Skip to content

Commit 4389f81

Browse files
committed
Incorrect sampler bindings in light pass
1 parent 2f71af4 commit 4389f81

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

demosys/deferred/renderer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def render_lights(self, camera_matrix, projection):
115115
s.uniform_mat4("m_proj", projection.matrix)
116116
s.uniform_mat4("m_light", m_light)
117117
s.uniform_sampler_2d(0, "g_normal", self.gbuffer.color_buffers[1])
118-
s.uniform_sampler_2d(0, "g_depth", self.gbuffer.depth_buffer)
118+
s.uniform_sampler_2d(1, "g_depth", self.gbuffer.depth_buffer)
119119
s.uniform_2f("screensize", self.width, self.height)
120120
s.uniform_2f("proj_const", *projection.projection_constants)
121121
s.uniform_1f("radius", light_size)

demosys/deferred/shaders/deferred/geometry.glsl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ void main() {
2424
layout(location=0) out vec4 out_color;
2525
layout(location=1) out vec3 out_normal;
2626

27+
uniform sampler2D texture0;
28+
2729
in vec3 normal;
2830
in vec2 uv;
2931

30-
uniform sampler2D texture0;
31-
3232
void main() {
33-
out_normal = normal;
33+
out_normal = normalize(normal);
3434
out_color = texture(texture0, uv);
3535
}
3636

demosys/deferred/shaders/deferred/light_point.glsl

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,29 @@ in vec3 vs_lightpos;
3434

3535
void main() {
3636
vec2 uv = vec2(gl_FragCoord.x / screensize.x, gl_FragCoord.y / screensize.y);
37-
vec3 normal = normalize(texture(g_normal, uv).xyz);
37+
vec3 N = normalize(texture(g_normal, uv).rgb);
3838

3939
// View position reconstruct from depth
4040
float depth = texture(g_depth, uv).r;
4141
vec3 ray = vec3(viewRay.xy / -viewRay.z, -1.0);
4242
float linear_depth = proj_const.y / (depth - proj_const.x);
4343
vec3 pos = ray * linear_depth;
4444

45-
float dist = length(pos - vs_lightpos);
45+
// Discard fragments outside the light radius
46+
float dist = length(vs_lightpos - pos);
4647
if (dist > radius) {
47-
// out_light = vec4(1.0, 0.0, 0.0, 1.0);
48-
// return;
4948
discard;
5049
}
5150

52-
// out_light = vec4(linear_depth);
53-
out_light = vec4(1.0 - (dist / radius));
51+
vec3 L = normalize(vs_lightpos - pos);
52+
vec3 R = reflect(L, N);
53+
float ndl = max(dot(N, L), 0.0);
54+
55+
// out_light = vec4(1.0 - (dist / radius));
56+
out_light = vec4(ndl);
57+
// out_light = vec4(R, 1.0);
58+
// out_light = vec4(N, 1.0);
59+
// out_light = vec4(depth);
5460
}
5561

5662
#endif

0 commit comments

Comments
 (0)