@@ -17,7 +17,7 @@
|
|||||||
struct LightBulb
|
struct LightBulb
|
||||||
{
|
{
|
||||||
Vector3 position;
|
Vector3 position;
|
||||||
u16 intensity;
|
u8 intensity;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -39,7 +39,8 @@ public:
|
|||||||
Vector3 operator+(Vector3 v);
|
Vector3 operator+(Vector3 v);
|
||||||
Vector3 operator-(const Vector3 &v);
|
Vector3 operator-(const Vector3 &v);
|
||||||
Vector3 operator*(Vector3 &v);
|
Vector3 operator*(Vector3 &v);
|
||||||
Vector3 operator*(float t);
|
Vector3 operator*(const float &t);
|
||||||
|
void operator*=(const float &t);
|
||||||
Vector3 operator/(float t);
|
Vector3 operator/(float t);
|
||||||
Vector3 operator-(void);
|
Vector3 operator-(void);
|
||||||
|
|
||||||
@@ -54,7 +55,7 @@ public:
|
|||||||
void rotate(const Vector3 &v, u8 inversed = false);
|
void rotate(const Vector3 &v, u8 inversed = false);
|
||||||
void set(const float &t_x, const float &t_y, const float &t_z);
|
void set(const float &t_x, const float &t_y, const float &t_z);
|
||||||
void copy(Vector3 &v);
|
void copy(Vector3 &v);
|
||||||
float distanceTo(Vector3 &v);
|
float distanceTo(const Vector3 &v) const;
|
||||||
const void print() const;
|
const void print() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -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:
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -45,8 +45,7 @@ void Vector3::setByLerp(const Vector3 &v1, const Vector3 &v2, const float &t_int
|
|||||||
"vadd.xyz vf9, vf8, vf4 \n\t" // vf9 = vf8 + vf4
|
"vadd.xyz vf9, vf8, vf4 \n\t" // vf9 = vf8 + vf4
|
||||||
"sqc2 vf9, 0x0(%0) \n\t" // v0 = vf9
|
"sqc2 vf9, 0x0(%0) \n\t" // v0 = vf9
|
||||||
:
|
:
|
||||||
: "r"(&this->xyz), "r"(&v1.xyz), "r"(&v2.xyz), "f"(t_interp)
|
: "r"(&this->xyz), "r"(&v1.xyz), "r"(&v2.xyz), "f"(t_interp));
|
||||||
: "$8");
|
|
||||||
x *= t_scale;
|
x *= t_scale;
|
||||||
y *= t_scale;
|
y *= t_scale;
|
||||||
z *= t_scale;
|
z *= t_scale;
|
||||||
@@ -120,7 +119,7 @@ Vector3 Vector3::operator*(Vector3 &v)
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Vector3::operator*(float t)
|
Vector3 Vector3::operator*(const float &t)
|
||||||
{
|
{
|
||||||
Vector3 result;
|
Vector3 result;
|
||||||
asm volatile(
|
asm volatile(
|
||||||
@@ -130,11 +129,22 @@ Vector3 Vector3::operator*(float t)
|
|||||||
"vmulx.xyz vf6, vf4, vf5 \n\t"
|
"vmulx.xyz vf6, vf4, vf5 \n\t"
|
||||||
"sqc2 vf6, 0x0(%0) \n\t"
|
"sqc2 vf6, 0x0(%0) \n\t"
|
||||||
:
|
:
|
||||||
: "r"(result.xyz), "r"(this->xyz), "f"(t)
|
: "r"(result.xyz), "r"(this->xyz), "f"(t));
|
||||||
: "$8");
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Vector3::operator*=(const float &t)
|
||||||
|
{
|
||||||
|
asm volatile(
|
||||||
|
"lqc2 vf4, 0x0(%0) \n\t"
|
||||||
|
"mfc1 $8, %1 \n\t"
|
||||||
|
"qmtc2 $8, vf5 \n\t"
|
||||||
|
"vmulx.xyz vf4, vf4, vf5 \n\t"
|
||||||
|
"sqc2 vf4, 0x0(%0) \n\t"
|
||||||
|
:
|
||||||
|
: "r"(this->xyz), "f"(t));
|
||||||
|
}
|
||||||
|
|
||||||
Vector3 Vector3::operator/(float t)
|
Vector3 Vector3::operator/(float t)
|
||||||
{
|
{
|
||||||
Vector3 result;
|
Vector3 result;
|
||||||
@@ -164,8 +174,7 @@ u8 Vector3::shouldBeBackfaceCulled(const Vector3 *t_cameraPos, const Vector3 *v0
|
|||||||
"qmfc2 $2, vf5 \n\t" // store result on `dot` variable
|
"qmfc2 $2, vf5 \n\t" // store result on `dot` variable
|
||||||
"mtc1 $2, %0 \n\t"
|
"mtc1 $2, %0 \n\t"
|
||||||
: "=f"(dot)
|
: "=f"(dot)
|
||||||
: "r"(t_cameraPos->xyz), "r"(v0->xyz), "r"(v1->xyz), "r"(v2->xyz)
|
: "r"(t_cameraPos->xyz), "r"(v0->xyz), "r"(v1->xyz), "r"(v2->xyz));
|
||||||
: "$2");
|
|
||||||
return dot <= 0.0F;
|
return dot <= 0.0F;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,12 +199,12 @@ float Vector3::length()
|
|||||||
"vaddy.x vf5, vf5, vf5 \n\t"
|
"vaddy.x vf5, vf5, vf5 \n\t"
|
||||||
"vaddz.x vf5, vf5, vf5 \n\t"
|
"vaddz.x vf5, vf5, vf5 \n\t"
|
||||||
"vsqrt Q , vf5x \n\t"
|
"vsqrt Q , vf5x \n\t"
|
||||||
|
"vwaitq \n\t"
|
||||||
"vaddq.x vf8, vf0, Q \n\t"
|
"vaddq.x vf8, vf0, Q \n\t"
|
||||||
"qmfc2 $2, vf8 \n\t"
|
"qmfc2 $2, vf8 \n\t"
|
||||||
"mtc1 $2, %0 \n\t"
|
"mtc1 $2, %0 \n\t"
|
||||||
: "=f"(result)
|
: "=f"(result)
|
||||||
: "r"(this->xyz)
|
: "r"(this->xyz));
|
||||||
: "$2");
|
|
||||||
return result;
|
return result;
|
||||||
// return Math::sqrt(x * x + y * y + z * z);
|
// return Math::sqrt(x * x + y * y + z * z);
|
||||||
}
|
}
|
||||||
@@ -208,6 +217,7 @@ void Vector3::normalize()
|
|||||||
"vaddy.x vf5, vf5, vf5 \n\t"
|
"vaddy.x vf5, vf5, vf5 \n\t"
|
||||||
"vaddz.x vf5, vf5, vf5 \n\t"
|
"vaddz.x vf5, vf5, vf5 \n\t"
|
||||||
"vrsqrt Q, vf0w, vf5x \n\t"
|
"vrsqrt Q, vf0w, vf5x \n\t"
|
||||||
|
"vwaitq \n\t"
|
||||||
"vsub.xyz vf6, vf0, vf0 \n\t"
|
"vsub.xyz vf6, vf0, vf0 \n\t"
|
||||||
"vaddw.xyz vf6, vf6, vf4 \n\t"
|
"vaddw.xyz vf6, vf6, vf4 \n\t"
|
||||||
"vwaitq \n\t"
|
"vwaitq \n\t"
|
||||||
@@ -230,8 +240,7 @@ float Vector3::innerProduct(Vector3 &v)
|
|||||||
"qmfc2 $2, vf6 \n\t"
|
"qmfc2 $2, vf6 \n\t"
|
||||||
"mtc1 $2, %0 \n\t"
|
"mtc1 $2, %0 \n\t"
|
||||||
: "=f"(result)
|
: "=f"(result)
|
||||||
: "r"(this->xyz), "r"(v.xyz)
|
: "r"(this->xyz), "r"(v.xyz));
|
||||||
: "$2");
|
|
||||||
return result;
|
return result;
|
||||||
// return (x * v.x + y * v.y + z * v.z);
|
// return (x * v.x + y * v.y + z * v.z);
|
||||||
}
|
}
|
||||||
@@ -294,11 +303,10 @@ void Vector3::copy(Vector3 &v)
|
|||||||
"lq $6, 0x0(%1) \n\t"
|
"lq $6, 0x0(%1) \n\t"
|
||||||
"sq $6, 0x0(%0) \n\t"
|
"sq $6, 0x0(%0) \n\t"
|
||||||
:
|
:
|
||||||
: "r"(v.xyz), "r"(this->xyz)
|
: "r"(v.xyz), "r"(this->xyz));
|
||||||
: "$6");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float Vector3::distanceTo(Vector3 &v)
|
float Vector3::distanceTo(const Vector3 &v) const
|
||||||
{
|
{
|
||||||
register float result;
|
register float result;
|
||||||
asm volatile( // VU0 Macro program
|
asm volatile( // VU0 Macro program
|
||||||
@@ -309,16 +317,16 @@ float Vector3::distanceTo(Vector3 &v)
|
|||||||
"vaddy.x vf7, vf7, vf7 \n\t"
|
"vaddy.x vf7, vf7, vf7 \n\t"
|
||||||
"vaddz.x vf7, vf7, vf7 \n\t"
|
"vaddz.x vf7, vf7, vf7 \n\t"
|
||||||
"vsqrt Q , vf7x \n\t"
|
"vsqrt Q , vf7x \n\t"
|
||||||
|
"vwaitq \n\t"
|
||||||
"vaddq.x vf8, vf0, Q \n\t"
|
"vaddq.x vf8, vf0, Q \n\t"
|
||||||
"qmfc2 $2, vf8 \n\t"
|
"qmfc2 $2, vf8 \n\t"
|
||||||
"mtc1 $2, %0 \n\t"
|
"mtc1 $2, %0 \n\t"
|
||||||
: "=f"(result)
|
: "=f"(result)
|
||||||
: "r"(this->xyz), "r"(v.xyz)
|
: "r"(this->xyz), "r"(v.xyz));
|
||||||
: "$2");
|
|
||||||
return result;
|
return result;
|
||||||
// return Math::sqrt((this->x - another.x) * (this->x - another.x) +
|
// return Math::sqrt((this->x - v.x) * (this->x - v.x) +
|
||||||
// (this->y - another.y) * (this->y - another.y) +
|
// (this->y - v.y) * (this->y - v.y) +
|
||||||
// (this->z - another.z) * (this->z - another.z));
|
// (this->z - v.z) * (this->z - v.z));
|
||||||
}
|
}
|
||||||
|
|
||||||
const void Vector3::print() const
|
const void Vector3::print() const
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,10 +102,17 @@ void Renderer::changeTexture(Texture *t_tex)
|
|||||||
void Renderer::draw(Sprite &t_sprite)
|
void Renderer::draw(Sprite &t_sprite)
|
||||||
{
|
{
|
||||||
texrect_t rect;
|
texrect_t rect;
|
||||||
rect.t0.s = t_sprite.isFlippedHorizontally() ? 128.0F : 0.0F;
|
float texMax = t_sprite.size.x > t_sprite.size.y ? t_sprite.size.x : t_sprite.size.y;
|
||||||
rect.t0.t = t_sprite.isFlippedVertically() ? 128.0F : 0.0F;
|
float texS = texMax;
|
||||||
rect.t1.s = t_sprite.isFlippedHorizontally() ? 0.0F : 128.0F;
|
float texT = texMax;
|
||||||
rect.t1.t = t_sprite.isFlippedVertically() ? 0.0F : 128.0F;
|
if (t_sprite.size.x > t_sprite.size.y)
|
||||||
|
texT = texMax / (t_sprite.size.x / t_sprite.size.y);
|
||||||
|
else if (t_sprite.size.y > t_sprite.size.x)
|
||||||
|
texS = texMax / (t_sprite.size.y / t_sprite.size.x);
|
||||||
|
rect.t0.s = t_sprite.isFlippedHorizontally() ? texS : 0.0F;
|
||||||
|
rect.t0.t = t_sprite.isFlippedVertically() ? texT : 0.0F;
|
||||||
|
rect.t1.s = t_sprite.isFlippedHorizontally() ? 0.0F : texS;
|
||||||
|
rect.t1.t = t_sprite.isFlippedVertically() ? 0.0F : texT;
|
||||||
rect.color.r = t_sprite.color.r;
|
rect.color.r = t_sprite.color.r;
|
||||||
rect.color.g = t_sprite.color.g;
|
rect.color.g = t_sprite.color.g;
|
||||||
rect.color.b = t_sprite.color.b;
|
rect.color.b = t_sprite.color.b;
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
.vscode/
|
||||||
|
bin/**
|
||||||
|
fonts/**
|
||||||
Reference in New Issue
Block a user