added setAmbientLight(), setWorldColor()

This commit is contained in:
h4570
2020-12-07 21:02:06 +01:00
parent 18f3398687
commit 3284c5a598
8 changed files with 54 additions and 22 deletions
+8 -8
View File
@@ -12,7 +12,6 @@
#include "../include/utils/math.hpp"
#include "../include/utils/debug.hpp"
#include "../include/modules/light.hpp"
#include <packet2_chain.h>
#include <kernel.h>
#include <dma.h>
@@ -29,9 +28,10 @@
/** Initializes vars and creates data transfer packets
* @param packetSize Size of data packet, should be increased when more data will be rendered
*/
GifSender::GifSender(u32 t_packetSize, ScreenSettings *t_screen) : screen(t_screen)
GifSender::GifSender(u32 t_packetSize, ScreenSettings *t_screen, Light *t_light) : screen(t_screen)
{
PRINT_LOG("Initializing GifSender");
light = t_light;
packetSize = t_packetSize;
packets[0] = packet2_create(t_packetSize, P2_TYPE_NORMAL, P2_MODE_CHAIN, false);
packets[1] = packet2_create(t_packetSize, P2_TYPE_NORMAL, P2_MODE_CHAIN, false);
@@ -76,7 +76,7 @@ void GifSender::sendTexture(Texture &texture, texbuffer_t *t_texBuffer)
packet2_free(packet2);
}
void GifSender::sendClear(zbuffer_t *t_zBuffer)
void GifSender::sendClear(zbuffer_t *t_zBuffer, color_t *rgb)
{
packet2_t *packet2 = packet2_create(36, P2_TYPE_NORMAL, P2_MODE_CHAIN, false);
packet2_chain_open_end(packet2, 0, 0);
@@ -84,7 +84,7 @@ void GifSender::sendClear(zbuffer_t *t_zBuffer)
packet2_update(packet2, draw_clear(packet2->next, 0,
2048.0F - (screen->width / 2), 2048.0F - (screen->height / 2),
screen->width, screen->height,
0x10, 0x10, 0x10));
rgb->r, rgb->g, rgb->b));
packet2_update(packet2, draw_enable_tests(packet2->next, 0, t_zBuffer));
packet2_update(packet2, draw_finish(packet2->next));
packet2_chain_close_tag(packet2);
@@ -118,14 +118,14 @@ void GifSender::sendPacket()
}
/** Adds clear screen to current packet */
void GifSender::addClear(zbuffer_t *t_zBuffer)
void GifSender::addClear(zbuffer_t *t_zBuffer, color_t *rgb)
{
packet2_chain_open_cnt(currentPacket, 0, 0, 0);
packet2_update(currentPacket, draw_disable_tests(currentPacket->next, 0, t_zBuffer));
packet2_update(currentPacket, draw_clear(currentPacket->next, 0,
2048.0F - (screen->width / 2), 2048.0F - (screen->height / 2),
screen->width, screen->height,
0x10, 0x10, 0x10));
rgb->r, rgb->g, rgb->b));
packet2_update(currentPacket, draw_enable_tests(currentPacket->next, 0, t_zBuffer));
packet2_chain_close_tag(currentPacket);
}
@@ -180,7 +180,7 @@ void GifSender::calc3DObject(Matrix t_perspective, Mesh &t_mesh, u32 vertexCount
if (SHOULD_BE_LIGHTED)
{
const u16 lightsCount = Light::getLightsCount(t_bulbsCount);
const u16 lightsCount = light->getLightsCount(t_bulbsCount);
VECTOR *lightDirections = new VECTOR[lightsCount];
VECTOR *lightColors = new VECTOR[lightsCount];
int *lightTypes = new int[lightsCount];
@@ -188,7 +188,7 @@ void GifSender::calc3DObject(Matrix t_perspective, Mesh &t_mesh, u32 vertexCount
VECTOR *lights = new VECTOR[vertexCount];
calculate_normals(normals, vertexCount, normals, localLight);
Light::calculateLight(lightDirections, lightColors, lightTypes, t_bulbs, lightsCount, t_mesh.position);
light->calculateLight(lightDirections, lightColors, lightTypes, t_bulbs, lightsCount, t_mesh.position);
calculate_lights(lights, vertexCount, normals, lightDirections, lightColors, lightTypes, lightsCount);
+5 -3
View File
@@ -26,6 +26,8 @@ const u8 ADDITIONAL_LIGHTS = 1; // Ambient
const float LIGHT_MAX = 255.0F;
const float LIGHT_DIS_MOD = 4.0F;
void Light::setAmbientLight(const Vector3 &t_rgb) { ambientLight.set(t_rgb); }
u16 Light::getLightsCount(u32 t_bulbsCount) { return t_bulbsCount + ADDITIONAL_LIGHTS; }
/** Calculates lighting. Used in gifSender in object 3D calculations */
@@ -40,9 +42,9 @@ void Light::calculateLight(VECTOR *t_lightDirections, VECTOR *t_lightColors, int
t_lightDirections[0][2] = 0.0F;
t_lightDirections[0][3] = 1.0F;
t_lightColors[0][0] = 0.0F;
t_lightColors[0][1] = 0.0F;
t_lightColors[0][2] = 0.0F;
t_lightColors[0][0] = ambientLight.x;
t_lightColors[0][1] = ambientLight.y;
t_lightColors[0][2] = ambientLight.z;
t_lightColors[0][3] = 1.0F;
// ---
+13 -3
View File
@@ -44,9 +44,12 @@ Renderer::Renderer(u32 t_packetSize, ScreenSettings *t_screen)
allocateBuffers(t_screen->width, t_screen->height);
initDrawingEnv(t_screen->width, t_screen->height);
setPrim();
worldColor.r = 0x10;
worldColor.g = 0x10;
worldColor.b = 0x10;
screen = t_screen;
gifSender = new GifSender(t_packetSize, t_screen);
vifSender = new VifSender();
gifSender = new GifSender(t_packetSize, t_screen, &light);
vifSender = new VifSender(&light);
perspective.setPerspective(*t_screen);
renderData.perspective = &perspective;
PRINT_LOG("Renderer initialized!");
@@ -187,6 +190,13 @@ void Renderer::setPrim()
PRINT_LOG("Prim set!");
}
void Renderer::setWorldColor(const color_t &t_rgb)
{
worldColor.r = t_rgb.r;
worldColor.g = t_rgb.g;
worldColor.b = t_rgb.b;
}
/** Defines and allocates framebuffers and zbuffer */
void Renderer::allocateBuffers(float t_screenW, float t_screenH)
{
@@ -305,7 +315,7 @@ void Renderer::beginFrameIfNeeded()
if (isFrameEmpty)
{
isFrameEmpty = false;
gifSender->sendClear(&zBuffer);
gifSender->sendClear(&zBuffer, &worldColor);
}
}
+2 -1
View File
@@ -29,8 +29,9 @@ extern u32 VU1Draw3D_CodeStart __attribute__((section(".vudata")));
extern u32 VU1Draw3D_CodeEnd __attribute__((section(".vudata")));
//
VifSender::VifSender()
VifSender::VifSender(Light *t_light)
{
light = t_light;
PRINT_LOG("Initializing VifSender");
PRINT_LOG("VifSender initialized!");
dma_channel_initialize(DMA_CHANNEL_VIF1, NULL, 0);