fixed path3 lighting on real ps2
This commit is contained in:
@@ -17,7 +17,7 @@
|
|||||||
struct LightBulb
|
struct LightBulb
|
||||||
{
|
{
|
||||||
Vector3 position;
|
Vector3 position;
|
||||||
u16 intensity;
|
u8 intensity;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ public:
|
|||||||
~Light();
|
~Light();
|
||||||
|
|
||||||
static u16 getLightsCount(u32 t_bulbsCount);
|
static u16 getLightsCount(u32 t_bulbsCount);
|
||||||
static void calculateLight(VECTOR *t_lightDirections, VECTOR *t_lightColors, int *t_lightTypes, LightBulb *t_bulbs, u32 t_bulbsCount, Vector3 t_objPosition);
|
static void calculateLight(VECTOR *t_lightDirections, VECTOR *t_lightColors, int *t_lightTypes, LightBulb *t_bulbs, u32 t_lightsCount, Vector3 t_objPosition);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -188,16 +188,16 @@ void GifSender::calc3DObject(Matrix t_perspective, Mesh &t_mesh, u32 vertexCount
|
|||||||
VECTOR *lights = new VECTOR[vertexCount];
|
VECTOR *lights = new VECTOR[vertexCount];
|
||||||
calculate_normals(normals, vertexCount, normals, localLight);
|
calculate_normals(normals, vertexCount, normals, localLight);
|
||||||
|
|
||||||
Light::calculateLight(lightDirections, lightColors, lightTypes, t_bulbs, t_bulbsCount, t_mesh.position);
|
Light::calculateLight(lightDirections, lightColors, lightTypes, t_bulbs, lightsCount, t_mesh.position);
|
||||||
|
|
||||||
calculate_lights(lights, vertexCount, normals, lightDirections, lightColors, lightTypes, lightsCount);
|
calculate_lights(lights, vertexCount, normals, lightDirections, lightColors, lightTypes, lightsCount);
|
||||||
|
|
||||||
for (u32 i = 0; i < vertexCount; i++)
|
for (u32 i = 0; i < vertexCount; i++)
|
||||||
{
|
{
|
||||||
// Apply the light value to the colour.
|
// Apply the light value to the colour.
|
||||||
colors[i][0] = (t_mesh.color.r * lights[i][0] / 128.0F);
|
colors[i][0] = (t_mesh.color.r * lights[i][0]);
|
||||||
colors[i][1] = (t_mesh.color.g * lights[i][1] / 128.0F);
|
colors[i][1] = (t_mesh.color.g * lights[i][1]);
|
||||||
colors[i][2] = (t_mesh.color.b * lights[i][2] / 128.0F);
|
colors[i][2] = (t_mesh.color.b * lights[i][2]);
|
||||||
vector_clamp(colors[i], colors[i], 0.00F, 1.99F);
|
vector_clamp(colors[i], colors[i], 0.00F, 1.99F);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,11 +23,13 @@ Light::~Light() {}
|
|||||||
// ----
|
// ----
|
||||||
|
|
||||||
const u8 ADDITIONAL_LIGHTS = 1; // Ambient
|
const u8 ADDITIONAL_LIGHTS = 1; // Ambient
|
||||||
|
const float LIGHT_MAX = 255.0F;
|
||||||
|
const float LIGHT_DIS_MOD = 4.0F;
|
||||||
|
|
||||||
u16 Light::getLightsCount(u32 t_bulbsCount) { return t_bulbsCount + ADDITIONAL_LIGHTS; }
|
u16 Light::getLightsCount(u32 t_bulbsCount) { return t_bulbsCount + ADDITIONAL_LIGHTS; }
|
||||||
|
|
||||||
/** Calculates lighting. Used in gifSender in object 3D calculations */
|
/** Calculates lighting. Used in gifSender in object 3D calculations */
|
||||||
void Light::calculateLight(VECTOR *t_lightDirections, VECTOR *t_lightColors, int *t_lightTypes, LightBulb *t_bulbs, u32 t_bulbsCount, Vector3 t_objPosition)
|
void Light::calculateLight(VECTOR *t_lightDirections, VECTOR *t_lightColors, int *t_lightTypes, LightBulb *t_bulbs, u32 t_lightsCount, Vector3 t_objPosition)
|
||||||
{
|
{
|
||||||
// --- Ambient light
|
// --- Ambient light
|
||||||
|
|
||||||
@@ -45,27 +47,30 @@ void Light::calculateLight(VECTOR *t_lightDirections, VECTOR *t_lightColors, int
|
|||||||
|
|
||||||
// ---
|
// ---
|
||||||
|
|
||||||
for (u8 i = 0; i < t_bulbsCount; i++)
|
for (u8 i = 1; i < t_lightsCount; i++)
|
||||||
{
|
{
|
||||||
t_lightTypes[i + 1] = LIGHT_DIRECTIONAL;
|
t_lightTypes[i] = LIGHT_DIRECTIONAL;
|
||||||
|
|
||||||
Vector3 newLight = Vector3(t_objPosition.x - t_bulbs[i].position.x,
|
|
||||||
t_objPosition.y - t_bulbs[i].position.y,
|
|
||||||
t_objPosition.z - t_bulbs[i].position.z);
|
|
||||||
|
|
||||||
|
Vector3 newLight = Vector3(t_objPosition.x - t_bulbs[i - 1].position.x,
|
||||||
|
t_objPosition.y - t_bulbs[i - 1].position.y,
|
||||||
|
t_objPosition.z - t_bulbs[i - 1].position.z);
|
||||||
newLight.normalize();
|
newLight.normalize();
|
||||||
newLight = newLight *
|
t_lightDirections[i][0] = newLight.x;
|
||||||
(.1F +
|
t_lightDirections[i][1] = newLight.y;
|
||||||
(t_bulbs[i].intensity / t_bulbs[i].position.distanceTo(t_objPosition)));
|
t_lightDirections[i][2] = newLight.z;
|
||||||
|
t_lightDirections[i][3] = 1.0F;
|
||||||
|
|
||||||
t_lightDirections[i + 1][0] = newLight.x;
|
// Intensity range 0.0F - 1.0F
|
||||||
t_lightDirections[i + 1][1] = newLight.y;
|
float intensity = t_bulbs[i - 1].intensity / LIGHT_MAX;
|
||||||
t_lightDirections[i + 1][2] = newLight.z;
|
// Distance range 0.0F - LIGHT_MAX * LIGHT_DIS_MOD (1020.0F at this time)
|
||||||
t_lightDirections[i + 1][3] = 1.0F;
|
float distance = t_bulbs[i - 1].position.distanceTo(t_objPosition);
|
||||||
|
// printf("Distance:%f\n", distance);
|
||||||
t_lightColors[i + 1][0] = 0.8F;
|
distance = distance > (LIGHT_MAX - LIGHT_DIS_MOD) * LIGHT_DIS_MOD ? LIGHT_MAX - LIGHT_DIS_MOD : distance;
|
||||||
t_lightColors[i + 1][1] = 0.8F;
|
intensity /= 1.0F + (distance / LIGHT_DIS_MOD); // intensity /= 1.0F - 251.0F
|
||||||
t_lightColors[i + 1][2] = 0.8F;
|
intensity /= 3.0F; // it looks better
|
||||||
t_lightColors[i + 1][3] = 1.0F;
|
t_lightColors[i][0] = intensity;
|
||||||
|
t_lightColors[i][1] = intensity;
|
||||||
|
t_lightColors[i][2] = intensity;
|
||||||
|
t_lightColors[i][3] = 1.0F;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user