Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

Commit

Permalink
Hybrid rendering bug fixes (#67)
Browse files Browse the repository at this point in the history
* bug fixes

* fix driver bug

* use intermediate var
  • Loading branch information
Lucas Crane authored Feb 3, 2020
1 parent eb775e5 commit 9e015c2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/renderer/GBufferPass.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ function uploadAttributes(gl, renderPass, geometry) {
}

function setAttribute(gl, location, bufferAttribute) {
if (location === undefined) {
return;
}

const { itemSize, array } = bufferAttribute;

gl.enableVertexAttribArray(location);
Expand Down
8 changes: 6 additions & 2 deletions src/renderer/glsl/chunks/surfaceInteractionDirect.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ export default `
uniform sampler2D gMatProps;

void surfaceInteractionDirect(vec2 coord, inout SurfaceInteraction si) {
si.position = texture(gPosition, coord).xyz;
vec4 positionAndMeshIndex = texture(gPosition, coord);

si.position = positionAndMeshIndex.xyz;

float meshIndex = positionAndMeshIndex.w;

vec4 normalMaterialType = texture(gNormal, coord);

Expand All @@ -22,6 +26,6 @@ export default `
si.roughness = matProps.x;
si.metalness = matProps.y;

si.hit = dot(si.normal, si.normal) > 0.0 ? true : false;
si.hit = meshIndex > 0.0 ? true : false;
}
`;
4 changes: 2 additions & 2 deletions src/renderer/glsl/gBuffer.frag
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ source: `
roughness = clamp(roughness, ROUGHNESS_MIN, 1.0);
metalness = clamp(metalness, 0.0, 1.0);

vec3 normal = vNormal;
vec3 faceNormal = faceNormals(vPosition);
vec3 normal = normalize(vNormal);
vec3 faceNormal = normalize(faceNormals(vPosition));
normal *= sign(dot(normal, faceNormal));

#ifdef NUM_NORMAL_MAPS
Expand Down
9 changes: 7 additions & 2 deletions src/renderer/glsl/toneMap.frag
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,13 @@ source: `
}

#ifdef EDGE_PRESERVING_UPSCALE

float getMeshId(sampler2D meshIdTex, vec2 vCoord) {
return floor(texture(meshIdTex, vCoord).w);
}

vec4 getUpscaledLight(vec2 coord) {
float meshId = texture(position, coord).w;
float meshId = getMeshId(position, coord);

vec2 sizef = lightScale * vec2(textureSize(position, 0));
vec2 texelf = coord * sizef - 0.5;
Expand All @@ -65,7 +70,7 @@ source: `
float sum;
for (int i = 0; i < 4; i++) {
vec2 pCoord = (vec2(texels[i]) + 0.5) / sizef;
float isValid = texture(position, pCoord).w == meshId ? 1.0 : 0.0;
float isValid = getMeshId(position, pCoord) == meshId ? 1.0 : 0.0;
float weight = isValid * weights[i];
upscaledLight += weight * texelFetch(light, texels[i], 0);
sum += weight;
Expand Down

0 comments on commit 9e015c2

Please sign in to comment.