Skip to content

Commit a02c295

Browse files
committed
improve looks
1 parent b7813fb commit a02c295

File tree

4 files changed

+26
-28
lines changed

4 files changed

+26
-28
lines changed

shaders/base.vert.hlsl

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
struct VSInput {
22
[[vk::location(0)]] float3 pos : TEXCOORD0;
3+
[[vk::location(1)]] float3 normal : TEXCOORD1;
34
};
45

56
// std140 alignment: vec4 is 16 bytes, which matches float4
@@ -37,22 +38,17 @@ VSOutput main(VSInput input, uint instanceID : SV_InstanceID) {
3738
// 1. Position (MVP is P * V * M)
3839
output.pos = mul(data.mvp, float4(input.pos, 1.0f));
3940

40-
// 2. Normal Calculation (for unit cube -0.5 to 0.5)
41-
float3 localNormal = float3(0, 0, 0);
42-
float3 absPos = abs(input.pos);
43-
if (absPos.x > absPos.y && absPos.x > absPos.z) localNormal.x = sign(input.pos.x);
44-
else if (absPos.y > absPos.z) localNormal.y = sign(input.pos.y);
45-
else localNormal.z = sign(input.pos.z);
46-
47-
// Transform normal to world space using the upper-left 3x3 of the model matrix
41+
// 2. Transform normal to world space using the upper-left 3x3 of the model matrix
4842
float3x3 normalMatrix = (float3x3)data.model;
49-
float3 N = normalize(mul(normalMatrix, localNormal));
43+
float3 N = normalize(mul(normalMatrix, input.normal));
5044
float3 L = normalize(lighting.lightDir.xyz);
5145

5246
// 3. Shading (Classic 2007)
47+
// Simple Lambertian diffuse
5348
float diffuse = max(0.0, dot(N, L));
5449

5550
// Mix top and bottom ambient based on normal Y in world space
51+
// Standard Roblox 2007 look uses a hemispherical ambient
5652
float ambientWeight = N.y * 0.5 + 0.5;
5753
float3 ambient = lerp(lighting.bottomAmbient.rgb, lighting.topAmbient.rgb, ambientWeight);
5854

shaders/base.vert.spv

-576 Bytes
Binary file not shown.

src/Engine/Rendering/Geometry.hpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,38 @@
77
namespace Nova {
88
struct Vertex {
99
Vector3 pos;
10-
// Future: Vector3 normal; Vector2 uv;
10+
Vector3 normal;
1111
};
1212

1313
struct Mesh {
1414
std::vector<Vertex> vertices;
15-
std::vector<uint32_t> indices; // Optional, but better for performance
15+
std::vector<uint32_t> indices;
1616
};
1717

1818
class Geometry {
1919
public:
2020
static Mesh CreateCube() {
2121
Mesh mesh;
22-
// Define the 8 corners of a 1x1x1 cube
23-
// We use 36 vertices for a "flat shaded" look (6 faces * 2 triangles * 3 verts)
22+
// 36 vertices for flat shading (6 faces * 2 triangles * 3 verts)
2423
mesh.vertices = {
2524
// Front face (Z+)
26-
{{-0.5f, -0.5f, 0.5f}}, {{ 0.5f, -0.5f, 0.5f}}, {{ 0.5f, 0.5f, 0.5f}},
27-
{{ 0.5f, 0.5f, 0.5f}}, {{-0.5f, 0.5f, 0.5f}}, {{-0.5f, -0.5f, 0.5f}},
25+
{{-0.5f, -0.5f, 0.5f}, {0, 0, 1}}, {{ 0.5f, -0.5f, 0.5f}, {0, 0, 1}}, {{ 0.5f, 0.5f, 0.5f}, {0, 0, 1}},
26+
{{ 0.5f, 0.5f, 0.5f}, {0, 0, 1}}, {{-0.5f, 0.5f, 0.5f}, {0, 0, 1}}, {{-0.5f, -0.5f, 0.5f}, {0, 0, 1}},
2827
// Back face (Z-)
29-
{{-0.5f, -0.5f, -0.5f}}, {{-0.5f, 0.5f, -0.5f}}, {{ 0.5f, 0.5f, -0.5f}},
30-
{{ 0.5f, 0.5f, -0.5f}}, {{ 0.5f, -0.5f, -0.5f}}, {{-0.5f, -0.5f, -0.5f}},
28+
{{-0.5f, -0.5f, -0.5f}, {0, 0, -1}}, {{-0.5f, 0.5f, -0.5f}, {0, 0, -1}}, {{ 0.5f, 0.5f, -0.5f}, {0, 0, -1}},
29+
{{ 0.5f, 0.5f, -0.5f}, {0, 0, -1}}, {{ 0.5f, -0.5f, -0.5f}, {0, 0, -1}}, {{-0.5f, -0.5f, -0.5f}, {0, 0, -1}},
3130
// Left face (X-)
32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{{-0.5f, 0.5f, -0.5f}, {0, 1, 0}},
4039
// Bottom face (Y-)
41-
{{-0.5f, -0.5f, -0.5f}}, {{ 0.5f, -0.5f, -0.5f}}, {{ 0.5f, -0.5f, 0.5f}},
42-
{{ 0.5f, -0.5f, 0.5f}}, {{-0.5f, -0.5f, 0.5f}}, {{-0.5f, -0.5f, -0.5f}}
40+
{{-0.5f, -0.5f, -0.5f}, {0, -1, 0}}, {{ 0.5f, -0.5f, -0.5f}, {0, -1, 0}}, {{ 0.5f, -0.5f, 0.5f}, {0, -1, 0}},
41+
{{ 0.5f, -0.5f, 0.5f}, {0, -1, 0}}, {{-0.5f, -0.5f, 0.5f}, {0, -1, 0}}, {{-0.5f, -0.5f, -0.5f}, {0, -1, 0}}
4342
};
4443
return mesh;
4544
}

src/Engine/Rendering/Renderer.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,13 @@ namespace Nova {
288288
pInfo.depth_stencil_state.enable_depth_write = true;
289289
pInfo.depth_stencil_state.compare_op = SDL_GPU_COMPAREOP_LESS;
290290

291-
SDL_GPUVertexAttribute attr = { 0, 0, SDL_GPU_VERTEXELEMENTFORMAT_FLOAT3, 0 };
291+
SDL_GPUVertexAttribute attrs[2];
292+
attrs[0] = { 0, 0, SDL_GPU_VERTEXELEMENTFORMAT_FLOAT3, 0 }; // Position
293+
attrs[1] = { 1, 0, SDL_GPU_VERTEXELEMENTFORMAT_FLOAT3, sizeof(Vector3) }; // Normal
294+
292295
SDL_GPUVertexBufferDescription desc = { 0, sizeof(Vertex), SDL_GPU_VERTEXINPUTRATE_VERTEX, 0 };
293-
pInfo.vertex_input_state.num_vertex_attributes = 1;
294-
pInfo.vertex_input_state.vertex_attributes = &attr;
296+
pInfo.vertex_input_state.num_vertex_attributes = 2;
297+
pInfo.vertex_input_state.vertex_attributes = attrs;
295298
pInfo.vertex_input_state.num_vertex_buffers = 1;
296299
pInfo.vertex_input_state.vertex_buffer_descriptions = &desc;
297300

0 commit comments

Comments
 (0)