Skip to content

Commit b6c8d69

Browse files
author
Hannah Bollar
committed
add - normal optimization to deffered to texture
1 parent f65b324 commit b6c8d69

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/shaders/deferred.frag.glsl.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ export default function(params) {
44
precision highp float;
55
66
uniform sampler2D u_gbuffers[${params.numGBuffers}];
7+
8+
// Redoing the impl from ForwardPlus to get texel index
79
810
varying vec2 v_uv;
911

src/shaders/deferredToTexture.frag.glsl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@ void main() {
2121
vec3 norm = applyNormalMap(v_normal, vec3(texture2D(u_normap, v_uv)));
2222
vec3 col = vec3(texture2D(u_colmap, v_uv));
2323

24-
// TODO: populate your g buffer
25-
// gl_FragData[0] = ??
26-
// gl_FragData[1] = ??
27-
// gl_FragData[2] = ??
28-
// gl_FragData[3] = ??
24+
// populate your g buffer
25+
26+
// optimization to compress the normal vector into x and y components (can just solve for z)
27+
// vec4(r, g, b, nor_x), vec4(x, y, z, nor_y)
28+
vec3 temp_normal = normalize(vec3(u_viewMatrix * vec4(norm,0.0)));
29+
gl_FragData[0] = vec4(col, temp_normal.x);
30+
gl_FragData[1] = vec4(v_position, temp_normal.y);
31+
32+
// if not optimizing the normal then:
33+
// gl_FragData[2] = vec4(v_normal, 0.0);
2934
}

0 commit comments

Comments
 (0)