REfactoring the shading functions interface to account for scattering

This commit is contained in:
samcake 2016-07-07 21:16:28 -07:00
parent fa62a0a73c
commit fff2a9a5a2
7 changed files with 41 additions and 62 deletions

View file

@ -135,7 +135,14 @@ vec4 fetchDiffusedCurvature(vec2 texcoord) {
return texture(diffusedCurvatureMap, texcoord);
}
void unpackMidLowNormalCurvature(vec2 texcoord, out vec4 midNormalCurvature, out vec4 vec4 lowNormalCurvature) {
midNormalCurvature = fetchCurvature(_texCoord0);
lowNormalCurvature = fetchDiffusedCurvature(_texCoord0);
midNormalCurvature.xyz = normalize((midNormalCurvature.xyz - 0.5f) * 2.0f);
lowNormalCurvature.xyz = normalize((lowNormalCurvature.xyz - 0.5f) * 2.0f);
midNormalCurvature.w = (midNormalCurvature.w * 2 - 1);
lowNormalCurvature.w = (lowNormalCurvature.w * 2 - 1);
}
<@endfunc@>
<@endif@>

View file

@ -60,7 +60,8 @@ vec3 evalAmbientGlobalColor(mat4 invViewMat, float shadowAttenuation, float obsc
<$declareLightingAmbient(1, 0, 0, supportScattering)$>
<$declareLightingDirectional(supportScattering)$>
vec3 evalAmbientSphereGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, float metallic, vec3 emissive, float roughness) {
vec3 evalAmbientSphereGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal,
vec3 albedo, float metallic, vec3 emissive, float roughness) {
<$prepareGlobalLight()$>
@ -86,22 +87,18 @@ vec3 evalAmbientSphereGlobalColor(mat4 invViewMat, float shadowAttenuation, floa
<$declareDeferredCurvature()$>
vec3 evalAmbientSphereGlobalColorScattering(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, float metallic, vec3 emissive, float roughness, float scattering, vec4 blurredCurvature, vec4 diffusedCurvature) {
vec3 evalAmbientSphereGlobalColorScattering(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal,
vec3 albedo, float metallic, vec3 emissive, float roughness, float scattering, vec4 midNormalCurvature, vec4 lowNormalCurvature) {
<$prepareGlobalLight(1)$>
vec3 midNormal = normalize((blurredCurvature.xyz - 0.5f) * 2.0f);
vec3 lowNormal = normalize((diffusedCurvature.xyz - 0.5f) * 2.0f);
float highCurvature = unpackCurvature(blurredCurvature.w);
float lowCurvature = unpackCurvature(diffusedCurvature.w);
// Ambient
vec3 ambientDiffuse;
vec3 ambientSpecular;
evalLightingAmbientScattering(ambientDiffuse, ambientSpecular, light,
fragEyeDir, fragNormal, roughness,
metallic, fresnel, albedo, obscurance,
isScatteringEnabled() * scattering, lowNormal, highCurvature, lowCurvature);
isScatteringEnabled() * scattering, midNormalCurvature, lowNormalCurvature);
color += ambientDiffuse * isDiffuseEnabled() * isAmbientEnabled();
color += ambientSpecular * isSpecularEnabled() * isAmbientEnabled();
@ -112,7 +109,7 @@ vec3 evalAmbientSphereGlobalColorScattering(mat4 invViewMat, float shadowAttenua
evalLightingDirectionalScattering(directionalDiffuse, directionalSpecular, light,
fragEyeDir, fragNormal, roughness,
metallic, fresnel, albedo, shadowAttenuation,
isScatteringEnabled() * scattering, midNormal, lowNormal, lowCurvature);
isScatteringEnabled() * scattering, midNormalCurvature, lowNormalCurvature);
color += directionalDiffuse * isDiffuseEnabled() * isDirectionalEnabled();
color += directionalSpecular * isSpecularEnabled() * isDirectionalEnabled();
@ -157,12 +154,7 @@ vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscu
vec3 evalSkyboxGlobalColorScattering(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, float metallic, vec3 emissive, float roughness, float scattering, vec4 blurredCurvature, vec4 diffusedCurvature) {
<$prepareGlobalLight(1)$>
vec3 midNormal = normalize((blurredCurvature.xyz - 0.5f) * 2.0f);
vec3 lowNormal = normalize((diffusedCurvature.xyz - 0.5f) * 2.0f);
float highCurvature = unpackCurvature(blurredCurvature.w);
float lowCurvature = unpackCurvature(diffusedCurvature.w);
// Ambient
// Ambient
vec3 ambientDiffuse;
vec3 ambientSpecular;
evalLightingAmbientScattering(ambientDiffuse, ambientSpecular, light,
@ -178,7 +170,7 @@ vec3 evalSkyboxGlobalColorScattering(mat4 invViewMat, float shadowAttenuation, f
evalLightingDirectionalScattering(directionalDiffuse, directionalSpecular, light,
fragEyeDir, fragNormal, roughness,
metallic, fresnel, albedo, shadowAttenuation,
isScatteringEnabled() * scattering, midNormal, lowNormal, lowCurvature);
isScatteringEnabled() * scattering, , midNormalCurvature, lowNormalCurvature);
color += directionalDiffuse * isDiffuseEnabled() * isDirectionalEnabled();
color += directionalSpecular * isSpecularEnabled() * isDirectionalEnabled();

View file

@ -18,9 +18,11 @@ void evalLightingDirectional(out vec3 diffuse, out vec3 specular, Light light,
vec4 shading = evalFragShading(normal, -getLightDirection(light), eyeDir, metallic, fresnel, roughness);
diffuse = albedo * shading.w * shadow * getLightColor(light) * getLightIntensity(light);
vec3 lightEnergy = shadow * getLightColor(light) * getLightIntensity(light);
specular = shading.rgb * shadow * getLightColor(light) * getLightIntensity(light);
diffuse = albedo * shading.w * lightEnergy;
specular = shading.rgb * lightEnergy;
}
<@if supportScattering@>
@ -28,14 +30,14 @@ void evalLightingDirectional(out vec3 diffuse, out vec3 specular, Light light,
void evalLightingDirectionalScattering(out vec3 diffuse, out vec3 specular, Light light,
vec3 eyeDir, vec3 normal, float roughness,
float metallic, vec3 fresnel, vec3 albedo, float shadow,
float scattering, vec3 midNormal, vec3 lowNormal, float curvature) {
float scattering, vec4 midNormalCurvature, vec4 lowNormalCurvature) {
vec3 fragLightDir = -normalize(getLightDirection(light));
evalFragShading(diffuse, specular,
normal, fragLightDir, eyeDir,
metallic, fresnel, roughness,
scattering, vec4(midNormal, curvature), vec4(lowNormal, curvature));
scattering, midNormalCurvature, lowNormalCurvature);
vec3 lightEnergy = shadow * getLightColor(light) * getLightIntensity(light);

View file

@ -64,7 +64,7 @@ void evalLightingPointScattering(out vec3 diffuse, out vec3 specular, Light ligh
evalFragShading(diffuse, specular,
normal, fragLightDir, fragEyeDir,
metallic, fresnel, roughness,
scattering, vec4(midNormal, curvature), vec4(lowNormal, curvature));
scattering, midNormalCurvature, lowNormalCurvature);
diffuse *= albedo * lightEnergy;

View file

@ -64,7 +64,7 @@ void evalLightingSpotScattering(out vec3 diffuse, out vec3 specular, Light light
evalFragShading(diffuse, specular,
normal, fragLightDir, fragEyeDir,
metallic, fresnel, roughness,
scattering, vec4(midNormal, curvature), vec4(lowNormal, curvature));
scattering, midNormalCurvature, lowNormalCurvature);
diffuse *= albedo * lightEnergy;

View file

@ -39,10 +39,12 @@ void main(void) {
frag.diffuse,
frag.specularVal.xyz);
_fragColor = vec4(color, 1.0);
} else { //if (frag.mode == FRAG_MODE_SCATTERING) {
vec4 blurredCurvature = fetchCurvature(_texCoord0);
vec4 diffusedCurvature = fetchDiffusedCurvature(_texCoord0);
} else {
vec4 midNormalCurvature;
vec4 lowNormalCurvature;
if (frag.mode == FRAG_MODE_SCATTERING) {
unpackMidLowNormalCurvature(_texcoord0, midNormalCurvature, lowNormalCurvature);
}
vec3 color = evalAmbientSphereGlobalColorScattering(
getViewInverse(),
@ -55,20 +57,9 @@ void main(void) {
frag.emissive,
frag.roughness,
frag.scattering,
blurredCurvature,
diffusedCurvature);
midNormalCurvature,
lowNormalCurvature);
_fragColor = vec4(color, 1.0);
/* } else {
vec3 color = evalAmbientSphereGlobalColor(
getViewInverse(),
shadowAttenuation,
frag.obscurance,
frag.position.xyz,
frag.normal,
frag.diffuse,
frag.metallic,
frag.emissive,
frag.roughness);
_fragColor = vec4(color, frag.normalVal.a);*/
}
}

View file

@ -39,11 +39,12 @@ void main(void) {
frag.diffuse,
frag.specularVal.xyz);
_fragColor = vec4(color, 1.0);
} else {// if (frag.mode == FRAG_MODE_SCATTERING) {
vec4 blurredCurvature = fetchCurvature(_texCoord0);
vec4 diffusedCurvature = fetchDiffusedCurvature(_texCoord0);
} else {
vec4 midNormalCurvature;
vec4 lowNormalCurvature;
if (frag.mode == FRAG_MODE_SCATTERING) {
unpackMidLowNormalCurvature(_texcoord0, midNormalCurvature, lowNormalCurvature);
}
vec3 color = evalSkyboxGlobalColorScattering(
getViewInverse(),
shadowAttenuation,
@ -55,22 +56,8 @@ void main(void) {
frag.emissive,
frag.roughness,
frag.scattering,
blurredCurvature,
diffusedCurvature);
midNormalCurvature,
lowNormalCurvature);
_fragColor = vec4(color, 1.0);
/* } else {
vec3 color = evalSkyboxGlobalColor(
getViewInverse(),
shadowAttenuation,
frag.obscurance,
frag.position.xyz,
frag.normal,
frag.diffuse,
frag.metallic,
frag.emissive,
frag.roughness);
_fragColor = vec4(color, frag.normalVal.a);
*/
}
}