Skip to content
Snippets Groups Projects
Commit 628e0d7b authored by Rye Mutt's avatar Rye Mutt :bread:
Browse files

Fix rendering

parent 39785f27
No related branches found
No related tags found
No related merge requests found
Showing
with 38 additions and 57 deletions
...@@ -40,12 +40,12 @@ uniform float kern_scale; ...@@ -40,12 +40,12 @@ uniform float kern_scale;
in vec2 vary_fragcoord; in vec2 vary_fragcoord;
vec4 getPosition(vec2 pos_screen); vec4 getPosition(vec2 pos_screen);
vec3 getNorm(vec2 pos_screen); vec4 getNorm(vec2 pos_screen);
void main() void main()
{ {
vec2 tc = vary_fragcoord.xy; vec2 tc = vary_fragcoord.xy;
vec3 norm = getNorm(tc); vec4 norm = getNorm(tc);
vec3 pos = getPosition(tc).xyz; vec3 pos = getPosition(tc).xyz;
vec4 ccol = texture(lightMap, tc).rgba; vec4 ccol = texture(lightMap, tc).rgba;
......
...@@ -143,31 +143,20 @@ vec2 getScreenCoordinate(vec2 screenpos) ...@@ -143,31 +143,20 @@ vec2 getScreenCoordinate(vec2 screenpos)
return sc - vec2(1.0, 1.0); return sc - vec2(1.0, 1.0);
} }
vec3 getNorm(vec2 screenpos) vec4 getNorm(vec2 screenpos)
{ {
return texture(normalMap, screenpos.xy).rgb; return texture(normalMap, screenpos.xy);
}
vec3 getNormalFromPacked(vec4 packedNormalEnvIntensityFlags)
{
vec2 enc = packedNormalEnvIntensityFlags.xy;
vec2 fenc = enc*4-2;
float f = dot(fenc,fenc);
float g = sqrt(1-f/4);
vec3 n;
n.xy = fenc*g;
n.z = 1-f/2;
return normalize(n); // TODO: Is this normalize redundant?
} }
// return packedNormalEnvIntensityFlags since GBUFFER_FLAG_HAS_PBR needs .w // return packedNormalEnvIntensityFlags since GBUFFER_FLAG_HAS_PBR needs .w
// See: C++: addDeferredAttachments(), GLSL: softenLightF // See: C++: addDeferredAttachments(), GLSL: softenLightF
vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity) vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity)
{ {
n = texture(normalMap, screenpos.xy).rgb; vec4 norm = texture(normalMap, screenpos.xy);
n = norm.xyz;
envIntensity = texture(emissiveRect, screenpos.xy).r; envIntensity = texture(emissiveRect, screenpos.xy).r;
return vec4(n, envIntensity); return norm;
} }
// get linear depth value given a depth buffer sample d and znear and zfar values // get linear depth value given a depth buffer sample d and znear and zfar values
......
...@@ -35,7 +35,7 @@ in vec2 vary_fragcoord; ...@@ -35,7 +35,7 @@ in vec2 vary_fragcoord;
uniform vec3 sun_dir; uniform vec3 sun_dir;
uniform float shadow_bias; uniform float shadow_bias;
vec3 getNorm(vec2 pos_screen); vec4 getNorm(vec2 pos_screen);
vec4 getPosition(vec2 pos_screen); vec4 getPosition(vec2 pos_screen);
float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen);
...@@ -45,13 +45,13 @@ void main() ...@@ -45,13 +45,13 @@ void main()
{ {
vec2 pos_screen = vary_fragcoord.xy; vec2 pos_screen = vary_fragcoord.xy;
vec4 pos = getPosition(pos_screen); vec4 pos = getPosition(pos_screen);
vec3 norm = getNorm(pos_screen); vec4 norm = getNorm(pos_screen);
vec4 col; vec4 col;
col.r = sampleDirectionalShadow(pos.xyz, norm, pos_screen); col.r = sampleDirectionalShadow(pos.xyz, norm.xyz, pos_screen);
col.g = 1.0f; col.g = 1.0f;
col.b = sampleSpotShadow(pos.xyz, norm, 0, pos_screen); col.b = sampleSpotShadow(pos.xyz, norm.xyz, 0, pos_screen);
col.a = sampleSpotShadow(pos.xyz, norm, 1, pos_screen); col.a = sampleSpotShadow(pos.xyz, norm.xyz, 1, pos_screen);
frag_color = clamp(col, vec4(0), vec4(1)); frag_color = clamp(col, vec4(0), vec4(1));
} }
...@@ -32,7 +32,7 @@ out vec4 frag_color; ...@@ -32,7 +32,7 @@ out vec4 frag_color;
in vec2 vary_fragcoord; in vec2 vary_fragcoord;
vec4 getPosition(vec2 pos_screen); vec4 getPosition(vec2 pos_screen);
vec3 getNorm(vec2 pos_screen); vec4 getNorm(vec2 pos_screen);
float sampleDirectionalShadow(vec3 shadow_pos, vec3 norm, vec2 pos_screen); float sampleDirectionalShadow(vec3 shadow_pos, vec3 norm, vec2 pos_screen);
float sampleSpotShadow(vec3 shadow_pos, vec3 norm, int index, vec2 pos_screen); float sampleSpotShadow(vec3 shadow_pos, vec3 norm, int index, vec2 pos_screen);
...@@ -42,13 +42,13 @@ void main() ...@@ -42,13 +42,13 @@ void main()
{ {
vec2 pos_screen = vary_fragcoord.xy; vec2 pos_screen = vary_fragcoord.xy;
vec4 pos = getPosition(pos_screen); vec4 pos = getPosition(pos_screen);
vec3 norm = getNorm(pos_screen); vec4 norm = getNorm(pos_screen);
vec4 col; vec4 col;
col.r = sampleDirectionalShadow(pos.xyz, norm, pos_screen); col.r = sampleDirectionalShadow(pos.xyz, norm.xyz, pos_screen);
col.g = calcAmbientOcclusion(pos, norm, pos_screen); col.g = calcAmbientOcclusion(pos, norm.xyz, pos_screen);
col.b = sampleSpotShadow(pos.xyz, norm, 0, pos_screen); col.b = sampleSpotShadow(pos.xyz, norm.xyz, 0, pos_screen);
col.a = sampleSpotShadow(pos.xyz, norm, 1, pos_screen); col.a = sampleSpotShadow(pos.xyz, norm.xyz, 1, pos_screen);
frag_color = clamp(col, vec4(0), vec4(1)); frag_color = clamp(col, vec4(0), vec4(1));
} }
...@@ -33,7 +33,7 @@ uniform vec3 moon_dir; ...@@ -33,7 +33,7 @@ uniform vec3 moon_dir;
uniform int sun_up_factor; uniform int sun_up_factor;
in vec2 vary_fragcoord; in vec2 vary_fragcoord;
vec3 getNorm(vec2 pos_screen); vec4 getNorm(vec2 pos_screen);
vec4 getPositionWithDepth(vec2 pos_screen, float depth); vec4 getPositionWithDepth(vec2 pos_screen, float depth);
void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive); void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive);
...@@ -53,8 +53,7 @@ void main() ...@@ -53,8 +53,7 @@ void main()
vec2 tc = vary_fragcoord.xy; vec2 tc = vary_fragcoord.xy;
float depth = getDepth(tc.xy); float depth = getDepth(tc.xy);
vec4 pos = getPositionWithDepth(tc, depth); vec4 pos = getPositionWithDepth(tc, depth);
vec4 norm = texture(normalMap, tc); vec4 norm = getNorm(tc);
norm.xyz = getNorm(tc);
vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir;
vec3 color = vec3(0); vec3 color = vec3(0);
......
...@@ -48,7 +48,7 @@ in vec4 vary_fragcoord; ...@@ -48,7 +48,7 @@ in vec4 vary_fragcoord;
void calcHalfVectors(vec3 lv, vec3 n, vec3 v, out vec3 h, out vec3 l, out float nh, out float nl, out float nv, out float vh, out float lightDist); void calcHalfVectors(vec3 lv, vec3 n, vec3 v, out vec3 h, out vec3 l, out float nh, out float nl, out float nv, out float vh, out float lightDist);
float calcLegacyDistanceAttenuation(float distance, float falloff); float calcLegacyDistanceAttenuation(float distance, float falloff);
vec4 getPosition(vec2 pos_screen); vec4 getPosition(vec2 pos_screen);
vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity); vec4 getNorm(vec2 screenpos);
vec2 getScreenXY(vec4 clip); vec2 getScreenXY(vec4 clip);
vec2 getScreenCoord(vec4 clip); vec2 getScreenCoord(vec4 clip);
vec3 srgb_to_linear(vec3 c); vec3 srgb_to_linear(vec3 c);
...@@ -74,9 +74,8 @@ void main() ...@@ -74,9 +74,8 @@ void main()
discard; discard;
} }
float envIntensity; // not used for this shader vec4 norm = getNorm(tc); // need `norm.w` for GET_GBUFFER_FLAG()
vec3 n; vec3 n = norm.xyz;
vec4 norm = getNormalEnvIntensityFlags(tc, n, envIntensity); // need `norm.w` for GET_GBUFFER_FLAG()
vec4 spec = texture(specularRect, tc); vec4 spec = texture(specularRect, tc);
vec3 diffuse = texture(diffuseRect, tc).rgb; vec3 diffuse = texture(diffuseRect, tc).rgb;
......
...@@ -52,7 +52,7 @@ uniform vec4 viewport; ...@@ -52,7 +52,7 @@ uniform vec4 viewport;
void calcHalfVectors(vec3 lv, vec3 n, vec3 v, out vec3 h, out vec3 l, out float nh, out float nl, out float nv, out float vh, out float lightDist); void calcHalfVectors(vec3 lv, vec3 n, vec3 v, out vec3 h, out vec3 l, out float nh, out float nl, out float nv, out float vh, out float lightDist);
float calcLegacyDistanceAttenuation(float distance, float falloff); float calcLegacyDistanceAttenuation(float distance, float falloff);
vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity); vec4 getNorm(vec2 screenpos);
vec4 getPosition(vec2 pos_screen); vec4 getPosition(vec2 pos_screen);
vec2 getScreenXY(vec4 clip); vec2 getScreenXY(vec4 clip);
vec2 getScreenCoord(vec4 clip); vec2 getScreenCoord(vec4 clip);
...@@ -72,9 +72,8 @@ void main() ...@@ -72,9 +72,8 @@ void main()
vec2 tc = getScreenCoord(vary_fragcoord); vec2 tc = getScreenCoord(vary_fragcoord);
vec3 pos = getPosition(tc).xyz; vec3 pos = getPosition(tc).xyz;
float envIntensity; vec4 norm = getNorm(tc); // need `norm.w` for GET_GBUFFER_FLAG()
vec3 n; vec3 n = norm.xyz;
vec4 norm = getNormalEnvIntensityFlags(tc, n, envIntensity); // need `norm.w` for GET_GBUFFER_FLAG()
vec3 diffuse = texture(diffuseRect, tc).rgb; vec3 diffuse = texture(diffuseRect, tc).rgb;
vec4 spec = texture(specularRect, tc); vec4 spec = texture(specularRect, tc);
......
...@@ -40,14 +40,13 @@ uniform sampler2D specularRect; ...@@ -40,14 +40,13 @@ uniform sampler2D specularRect;
uniform sampler2D diffuseRect; uniform sampler2D diffuseRect;
uniform sampler2D diffuseMap; uniform sampler2D diffuseMap;
vec3 getNorm(vec2 screenpos); vec4 getNorm(vec2 screenpos);
float getDepth(vec2 pos_screen); float getDepth(vec2 pos_screen);
float linearDepth(float d, float znear, float zfar); float linearDepth(float d, float znear, float zfar);
float linearDepth01(float d, float znear, float zfar); float linearDepth01(float d, float znear, float zfar);
vec4 getPositionWithDepth(vec2 pos_screen, float depth); vec4 getPositionWithDepth(vec2 pos_screen, float depth);
vec4 getPosition(vec2 pos_screen); vec4 getPosition(vec2 pos_screen);
vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity);
float random (vec2 uv); float random (vec2 uv);
...@@ -57,9 +56,7 @@ void main() ...@@ -57,9 +56,7 @@ void main()
{ {
vec2 tc = vary_fragcoord.xy; vec2 tc = vary_fragcoord.xy;
float depth = linearDepth01(getDepth(tc), zNear, zFar); float depth = linearDepth01(getDepth(tc), zNear, zFar);
float envIntensity; vec4 norm = getNorm(tc); // need `norm.w` for GET_GBUFFER_FLAG()
vec3 n;
vec4 norm = getNormalEnvIntensityFlags(tc, n, envIntensity); // need `norm.w` for GET_GBUFFER_FLAG()
vec3 pos = getPositionWithDepth(tc, getDepth(tc)).xyz; vec3 pos = getPositionWithDepth(tc, getDepth(tc)).xyz;
vec4 spec = texture(specularRect, tc); vec4 spec = texture(specularRect, tc);
vec2 hitpixel; vec2 hitpixel;
...@@ -84,7 +81,7 @@ void main() ...@@ -84,7 +81,7 @@ void main()
vec4 collectedColor = vec4(0); vec4 collectedColor = vec4(0);
float w = tapScreenSpaceReflection(4, tc, pos, n, collectedColor, diffuseMap, 0); float w = tapScreenSpaceReflection(4, tc, pos, norm.xyz, collectedColor, diffuseMap, 0);
collectedColor.rgb *= specCol.rgb; collectedColor.rgb *= specCol.rgb;
......
...@@ -61,7 +61,7 @@ in vec2 vary_fragcoord; ...@@ -61,7 +61,7 @@ in vec2 vary_fragcoord;
uniform mat4 inv_proj; uniform mat4 inv_proj;
uniform vec2 screen_res; uniform vec2 screen_res;
vec3 getNorm(vec2 pos_screen); vec4 getNorm(vec2 pos_screen);
vec4 getPositionWithDepth(vec2 pos_screen, float depth); vec4 getPositionWithDepth(vec2 pos_screen, float depth);
void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive); void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive);
...@@ -128,10 +128,9 @@ void main() ...@@ -128,10 +128,9 @@ void main()
vec2 tc = vary_fragcoord.xy; vec2 tc = vary_fragcoord.xy;
float depth = getDepth(tc.xy); float depth = getDepth(tc.xy);
vec4 pos = getPositionWithDepth(tc, depth); vec4 pos = getPositionWithDepth(tc, depth);
vec4 norm = texture(normalMap, tc); vec4 norm = getNorm(tc);
vec3 colorEmissive = texture(emissiveRect, tc).rgb; vec3 colorEmissive = texture(emissiveRect, tc).rgb;
float envIntensity = colorEmissive.r; float envIntensity = colorEmissive.r;
norm.xyz = getNorm(tc);
vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir;
vec4 baseColor = texture(diffuseRect, tc); vec4 baseColor = texture(diffuseRect, tc);
...@@ -193,12 +192,12 @@ void main() ...@@ -193,12 +192,12 @@ void main()
else if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_HDRI)) else if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_HDRI))
{ {
// actual HDRI sky, just copy color value // actual HDRI sky, just copy color value
color = texture(emissiveRect, tc).rgb; color = colorEmissive.rgb;
} }
else if (GET_GBUFFER_FLAG(GBUFFER_FLAG_SKIP_ATMOS)) else if (GET_GBUFFER_FLAG(GBUFFER_FLAG_SKIP_ATMOS))
{ {
//should only be true of WL sky, port over base color value and scale for fake HDR //should only be true of WL sky, port over base color value and scale for fake HDR
color = texture(emissiveRect, tc).rgb; color = colorEmissive.rgb;
color = srgb_to_linear(color); color = srgb_to_linear(color);
color *= sky_hdr_scale; color *= sky_hdr_scale;
} }
......
...@@ -72,7 +72,7 @@ uniform mat4 inv_proj; ...@@ -72,7 +72,7 @@ uniform mat4 inv_proj;
void calcHalfVectors(vec3 lv, vec3 n, vec3 v, out vec3 h, out vec3 l, out float nh, out float nl, out float nv, out float vh, out float lightDist); void calcHalfVectors(vec3 lv, vec3 n, vec3 v, out vec3 h, out vec3 l, out float nh, out float nl, out float nv, out float vh, out float lightDist);
float calcLegacyDistanceAttenuation(float distance, float falloff); float calcLegacyDistanceAttenuation(float distance, float falloff);
bool clipProjectedLightVars(vec3 center, vec3 pos, out float dist, out float l_dist, out vec3 lv, out vec4 proj_tc ); bool clipProjectedLightVars(vec3 center, vec3 pos, out float dist, out float l_dist, out vec3 lv, out vec4 proj_tc );
vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity); vec4 getNorm(vec2 screenpos);
vec3 getProjectedLightAmbiance(float amb_da, float attenuation, float lit, float nl, float noise, vec2 projected_uv); vec3 getProjectedLightAmbiance(float amb_da, float attenuation, float lit, float nl, float noise, vec2 projected_uv);
vec3 getProjectedLightDiffuseColor(float light_distance, vec2 projected_uv ); vec3 getProjectedLightDiffuseColor(float light_distance, vec2 projected_uv );
vec2 getScreenCoord(vec4 clip); vec2 getScreenCoord(vec4 clip);
...@@ -121,9 +121,8 @@ void main() ...@@ -121,9 +121,8 @@ void main()
shadow = clamp(shadow, 0.0, 1.0); shadow = clamp(shadow, 0.0, 1.0);
} }
float envIntensity; vec4 norm = getNorm(tc);
vec3 n; vec3 n = norm.xyz;
vec4 norm = getNormalEnvIntensityFlags(tc, n, envIntensity);
float dist_atten = calcLegacyDistanceAttenuation(dist, falloff); float dist_atten = calcLegacyDistanceAttenuation(dist, falloff);
if (dist_atten <= 0.0) if (dist_atten <= 0.0)
...@@ -145,7 +144,6 @@ void main() ...@@ -145,7 +144,6 @@ void main()
if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR))
{ {
vec3 colorEmissive = texture(emissiveRect, tc).rgb;
vec3 orm = spec.rgb; vec3 orm = spec.rgb;
float perceptualRoughness = orm.g; float perceptualRoughness = orm.g;
float metallic = orm.b; float metallic = orm.b;
...@@ -182,6 +180,8 @@ void main() ...@@ -182,6 +180,8 @@ void main()
} }
else else
{ {
float envIntensity = texture(emissiveRect, tc).r;
diffuse = srgb_to_linear(diffuse); diffuse = srgb_to_linear(diffuse);
spec.rgb = srgb_to_linear(spec.rgb); spec.rgb = srgb_to_linear(spec.rgb);
......
...@@ -56,7 +56,6 @@ void main() ...@@ -56,7 +56,6 @@ void main()
} }
vec4 pos = getPositionWithDepth(tc, depth); vec4 pos = getPositionWithDepth(tc, depth);
vec4 norm = texture(normalMap, tc);
vec4 fogged = getWaterFogView(pos.xyz); vec4 fogged = getWaterFogView(pos.xyz);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment