Skip to content

Commit

Permalink
gpu: implement normal ST source
Browse files Browse the repository at this point in the history
  • Loading branch information
fleroviux committed Jan 6, 2024
1 parent 2ec3ea3 commit 40cbb3b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ namespace dual::nds::gpu {
}

void SetVertexUV(Vector2<Fixed12x4> uv, const Matrix4<Fixed20x12>& texture_matrix);
void SetNormal(Vector3<Fixed20x12> normal);
void SetNormal(Vector3<Fixed20x12> normal, const Matrix4<Fixed20x12>& texture_matrix);

void SetMaterialDiffuseColor(const Color4& color) {
m_material.diffuse_color = color;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace dual::nds::gpu {
(i32)(xyz & (0x3FFu << 10)) << 12 >> 19,
(i32)(xyz & (0x3FFu << 20)) << 2 >> 19,
0
}).XYZ());
}).XYZ(), m_texture_mtx);
}

void CommandProcessor::cmdSetUV() {
Expand Down
14 changes: 12 additions & 2 deletions src/dual/src/nds/video_unit/gpu/geometry_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,9 +444,19 @@ namespace dual::nds::gpu {
}
}

void GeometryEngine::SetNormal(Vector3<Fixed20x12> normal) {
void GeometryEngine::SetNormal(Vector3<Fixed20x12> normal, const Matrix4<Fixed20x12>& texture_matrix) {
if(m_texture_parameters.st_transform == TextureParams::Transform::Normal) {
ATOM_PANIC("normal ST transform");
const i64 normal_x = (i64)normal.X().Raw();
const i64 normal_y = (i64)normal.Y().Raw();
const i64 normal_z = (i64)normal.Z().Raw();

for(const int i : {0, 1}) {
const i64 x = normal_x * texture_matrix[0][i].Raw();
const i64 y = normal_y * texture_matrix[1][i].Raw();
const i64 z = normal_z * texture_matrix[2][i].Raw();

m_vertex_uv[i] = (i16)(((x + y + z) >> 24) + m_vertex_uv_src[i].Raw());
}
}

i32 r = m_material.emissive_color.R().Raw() << 14;
Expand Down

0 comments on commit 40cbb3b

Please sign in to comment.