Cleaning up the lighting with the simpler approach where emissive and lightmap is displayed on forward

This commit is contained in:
samcake 2016-07-08 18:14:05 -07:00
parent ed67fe4051
commit 2fbdb22493
29 changed files with 272 additions and 358 deletions

View file

@ -59,7 +59,7 @@ enum Slot {
static const std::string DEFAULT_ALBEDO_SHADER { static const std::string DEFAULT_ALBEDO_SHADER {
"vec4 getFragmentColor() {" "vec4 getFragmentColor() {"
" DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);" " DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);"
" return vec4(pow(frag.diffuse, vec3(1.0 / 2.2)), 1.0);" " return vec4(pow(frag.albedo, vec3(1.0 / 2.2)), 1.0);"
" }" " }"
}; };
@ -93,7 +93,7 @@ static const std::string DEFAULT_OCCLUSION_SHADER{
static const std::string DEFAULT_EMISSIVE_SHADER{ static const std::string DEFAULT_EMISSIVE_SHADER{
"vec4 getFragmentColor() {" "vec4 getFragmentColor() {"
" DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);" " DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);"
" return (frag.mode == FRAG_MODE_SHADED ? vec4(pow(frag.emissive, vec3(1.0 / 2.2)), 1.0) : vec4(vec3(0.0), 1.0));" " return (frag.mode == FRAG_MODE_SHADED ? vec4(pow(texture(specularMap, uv).rgb, vec3(1.0 / 2.2)), 1.0) : vec4(vec3(0.0), 1.0));"
" }" " }"
}; };
@ -107,7 +107,7 @@ static const std::string DEFAULT_UNLIT_SHADER{
static const std::string DEFAULT_LIGHTMAP_SHADER{ static const std::string DEFAULT_LIGHTMAP_SHADER{
"vec4 getFragmentColor() {" "vec4 getFragmentColor() {"
" DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);" " DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);"
" return (frag.mode == FRAG_MODE_LIGHTMAPPED ? vec4(pow(frag.emissive, vec3(1.0 / 2.2)), 1.0) : vec4(vec3(0.0), 1.0));" " return (frag.mode == FRAG_MODE_LIGHTMAPPED ? vec4(pow(texture(specularMap, uv).rgb, vec3(1.0 / 2.2)), 1.0) : vec4(vec3(0.0), 1.0));"
" }" " }"
}; };

View file

@ -36,11 +36,10 @@ struct DeferredFragment {
vec4 position; vec4 position;
vec3 normal; vec3 normal;
float metallic; float metallic;
vec3 diffuse; vec3 albedo;
float obscurance; float obscurance;
vec3 specular; vec3 fresnel;
float roughness; float roughness;
// vec3 emissive;
int mode; int mode;
float scattering; float scattering;
float depthVal; float depthVal;
@ -63,7 +62,7 @@ DeferredFragment unpackDeferredFragmentNoPosition(vec2 texcoord) {
frag.roughness = normalVal.a; frag.roughness = normalVal.a;
// Diffuse color and unpack the mode and the metallicness // Diffuse color and unpack the mode and the metallicness
frag.diffuse = diffuseVal.xyz; frag.albedo = diffuseVal.xyz;
frag.scattering = 0.0; frag.scattering = 0.0;
unpackModeMetallic(diffuseVal.w, frag.mode, frag.metallic); unpackModeMetallic(diffuseVal.w, frag.mode, frag.metallic);
@ -73,14 +72,13 @@ DeferredFragment unpackDeferredFragmentNoPosition(vec2 texcoord) {
if (frag.mode == FRAG_MODE_SCATTERING) { if (frag.mode == FRAG_MODE_SCATTERING) {
frag.scattering = specularVal.x; frag.scattering = specularVal.x;
//frag.emissive = vec3(0.0);
} }
if (frag.metallic <= 0.5) { if (frag.metallic <= 0.5) {
frag.metallic = 0.0; frag.metallic = 0.0;
frag.specular = vec3(0.03); // Default Di-electric fresnel value frag.fresnel = vec3(0.03); // Default Di-electric fresnel value
} else { } else {
frag.specular = vec3(diffuseVal.xyz); frag.fresnel = vec3(diffuseVal.xyz);
frag.metallic = 1.0; frag.metallic = 1.0;
} }

View file

@ -53,7 +53,6 @@ void packDeferredFragmentLightmap(vec3 normal, float alpha, vec3 albedo, float r
_fragColor0 = vec4(albedo, packLightmappedMetallic(metallic)); _fragColor0 = vec4(albedo, packLightmappedMetallic(metallic));
_fragColor1 = vec4(packNormal(normal), clamp(roughness, 0.0, 1.0)); _fragColor1 = vec4(packNormal(normal), clamp(roughness, 0.0, 1.0));
_fragColor2 = vec4(lightmap, 1.0); _fragColor2 = vec4(lightmap, 1.0);
_fragColor3 = vec4(albedo * lightmap, 1.0); _fragColor3 = vec4(albedo * lightmap, 1.0);
} }
@ -63,8 +62,7 @@ void packDeferredFragmentUnlit(vec3 normal, float alpha, vec3 color) {
} }
_fragColor0 = vec4(color, packUnlit()); _fragColor0 = vec4(color, packUnlit());
_fragColor1 = vec4(packNormal(normal), 1.0); _fragColor1 = vec4(packNormal(normal), 1.0);
//_fragColor2 = vec4(vec3(0.0), 1.0); // If unlit, do not worry about the emissive color target _fragColor2 = vec4(vec3(0.0), 1.0);
_fragColor3 = vec4(color, 1.0); _fragColor3 = vec4(color, 1.0);
} }

View file

@ -31,23 +31,12 @@
Light light = getLight(); Light light = getLight();
vec3 color = vec3(0.0); vec3 color = vec3(0.0);
<@if isScattering@>
<@else@>
// color += emissive * isEmissiveEnabled();
<@endif@>
//color += emissive * isEmissiveEnabled();
vec3 fresnel = vec3(0.03); // Default Di-electric fresnel value
if (metallic > 0.5) {
fresnel = albedo;
metallic = 1.0;
}
<@endfunc@> <@endfunc@>
<@func declareEvalAmbientGlobalColor()@> <@func declareEvalAmbientGlobalColor()@>
vec3 evalAmbientGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, float metallic, float roughness) { vec3 evalAmbientGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, vec3 fresnel, float metallic, float roughness) {
<$prepareGlobalLight()$> <$prepareGlobalLight()$>
color += albedo * getLightColor(light) * obscurance * getLightAmbientIntensity(light); color += albedo * getLightColor(light) * obscurance * getLightAmbientIntensity(light);
return color; return color;
@ -56,21 +45,20 @@ vec3 evalAmbientGlobalColor(mat4 invViewMat, float shadowAttenuation, float obsc
<@func declareEvalAmbientSphereGlobalColor(supportScattering)@> <@func declareEvalAmbientSphereGlobalColor(supportScattering)@>
<$declareLightingAmbient(1, 0, 0, supportScattering)$> <$declareLightingAmbient(1, _SCRIBE_NULL, _SCRIBE_NULL, $supportScattering$)$>
<$declareLightingDirectional(supportScattering)$> <$declareLightingDirectional($supportScattering$)$>
<@if supportScattering@> <@if supportScattering@>
<$declareDeferredCurvature()$> <$declareDeferredCurvature()$>
<@endif@> <@endif@>
vec3 evalAmbientSphereGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 evalAmbientSphereGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal,
vec3 albedo, float metallic, float roughness vec3 albedo, vec3 fresnel, float metallic, float roughness
<@if supportScattering@> <@if supportScattering@>
, float scattering, vec4 midNormalCurvature, vec4 lowNormalCurvature , float scattering, vec4 midNormalCurvature, vec4 lowNormalCurvature
<@endif@> <@endif@> ) {
) {
<$prepareGlobalLight(supportScattering)$> <$prepareGlobalLight($supportScattering$)$>
// Ambient // Ambient
vec3 ambientDiffuse; vec3 ambientDiffuse;
@ -78,10 +66,9 @@ vec3 evalAmbientSphereGlobalColor(mat4 invViewMat, float shadowAttenuation, floa
evalLightingAmbient(ambientDiffuse, ambientSpecular, light, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, obscurance evalLightingAmbient(ambientDiffuse, ambientSpecular, light, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, obscurance
<@if supportScattering@> <@if supportScattering@>
,scattering, midNormalCurvature, lowNormalCurvature ,scattering, midNormalCurvature, lowNormalCurvature
<@endif@> <@endif@> );
); color += ambientDiffuse;
color += ambientDiffuse * isDiffuseEnabled() * isAmbientEnabled(); color += ambientSpecular;
color += ambientSpecular * isSpecularEnabled() * isAmbientEnabled();
// Directional // Directional
@ -90,10 +77,9 @@ vec3 evalAmbientSphereGlobalColor(mat4 invViewMat, float shadowAttenuation, floa
evalLightingDirectional(directionalDiffuse, directionalSpecular, light, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, shadowAttenuation evalLightingDirectional(directionalDiffuse, directionalSpecular, light, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, shadowAttenuation
<@if supportScattering@> <@if supportScattering@>
,scattering, midNormalCurvature, lowNormalCurvature ,scattering, midNormalCurvature, lowNormalCurvature
<@endif@> <@endif@> );
); color += directionalDiffuse;
color += directionalDiffuse * isDiffuseEnabled() * isDirectionalEnabled(); color += directionalSpecular;
color += directionalSpecular * isSpecularEnabled() * isDirectionalEnabled();
return color; return color;
} }
@ -103,31 +89,31 @@ vec3 evalAmbientSphereGlobalColor(mat4 invViewMat, float shadowAttenuation, floa
<@func declareEvalSkyboxGlobalColor(supportScattering)@> <@func declareEvalSkyboxGlobalColor(supportScattering)@>
<$declareLightingAmbient(0, 1, 0, supportScattering)$> <$declareLightingAmbient(_SCRIBE_NULL, 1, _SCRIBE_NULL, $supportScattering$)$>
<$declareLightingDirectional(supportScattering)$> <$declareLightingDirectional($supportScattering$)$>
<@if supportScattering@> <@if supportScattering@>
<$declareDeferredCurvature()$> <$declareDeferredCurvature()$>
<@endif@> <@endif@>
vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal,
vec3 albedo, float metallic, float roughness vec3 albedo, vec3 fresnel, float metallic, float roughness
<@if supportScattering@> <@if supportScattering@>
, float scattering, vec4 midNormalCurvature, vec4 lowNormalCurvature , float scattering, vec4 midNormalCurvature, vec4 lowNormalCurvature
<@endif@> <@endif@>
) { ) {
<$prepareGlobalLight(supportScattering)$> <$prepareGlobalLight($supportScattering$)$>
// Ambient // Ambient
vec3 ambientDiffuse; vec3 ambientDiffuse;
vec3 ambientSpecular; vec3 ambientSpecular;
evalLightingAmbient(ambientDiffuse, ambientSpecular, light, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, obscurance evalLightingAmbient(ambientDiffuse, ambientSpecular, light, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, obscurance
<@if supportScattering@> <@if supportScattering@>
,scattering, midNormalCurvature, lowNormalCurvature ,scattering, midNormalCurvature, lowNormalCurvature
<@endif@> <@endif@>
); );
color += ambientDiffuse * isDiffuseEnabled() * isAmbientEnabled(); color += ambientDiffuse;
color += ambientSpecular * isSpecularEnabled() * isAmbientEnabled(); color += ambientSpecular;
// Directional // Directional
@ -138,8 +124,8 @@ vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscu
,scattering, midNormalCurvature, lowNormalCurvature ,scattering, midNormalCurvature, lowNormalCurvature
<@endif@> <@endif@>
); );
color += directionalDiffuse * isDiffuseEnabled() * isDirectionalEnabled(); color += directionalDiffuse;
color += directionalSpecular * isSpecularEnabled() * isDirectionalEnabled(); color += directionalSpecular;
return color; return color;
} }
@ -178,7 +164,7 @@ vec3 evalLightmappedColor(mat4 invViewMat, float shadowAttenuation, float obscur
<$declareLightingAmbient(1, 1, 1)$> <$declareLightingAmbient(1, 1, 1)$>
<$declareLightingDirectional()$> <$declareLightingDirectional()$>
vec3 evalGlobalLightingAlphaBlended(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, float metallic, vec3 emissive, float roughness, float opacity) { vec3 evalGlobalLightingAlphaBlended(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, vec3 fresnel, float metallic, vec3 emissive, float roughness, float opacity) {
<$prepareGlobalLight()$> <$prepareGlobalLight()$>
color += emissive * isEmissiveEnabled(); color += emissive * isEmissiveEnabled();
@ -187,16 +173,16 @@ vec3 evalGlobalLightingAlphaBlended(mat4 invViewMat, float shadowAttenuation, fl
vec3 ambientDiffuse; vec3 ambientDiffuse;
vec3 ambientSpecular; vec3 ambientSpecular;
evalLightingAmbient(ambientDiffuse, ambientSpecular, light, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, obscurance); evalLightingAmbient(ambientDiffuse, ambientSpecular, light, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, obscurance);
color += ambientDiffuse * isDiffuseEnabled() * isAmbientEnabled(); color += ambientDiffuse;
color += ambientSpecular * isSpecularEnabled() * isAmbientEnabled() / opacity; color += ambientSpecular / opacity;
// Directional // Directional
vec3 directionalDiffuse; vec3 directionalDiffuse;
vec3 directionalSpecular; vec3 directionalSpecular;
evalLightingDirectional(directionalDiffuse, directionalSpecular, light, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, shadowAttenuation); evalLightingDirectional(directionalDiffuse, directionalSpecular, light, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, shadowAttenuation);
color += directionalDiffuse * isDiffuseEnabled() * isDirectionalEnabled(); color += directionalDiffuse;
color += directionalSpecular * isSpecularEnabled() * isDirectionalEnabled() / opacity; color += directionalSpecular / opacity;
return color; return color;
} }

View file

@ -7,76 +7,4 @@
// //
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
!>
<!
<@if not DEFERRED_LIGHTING_SLH@>
<@def DEFERRED_LIGHTING_SLH@>
<@func declareEvalPBRShading()@>
vec3 fresnelSchlick(vec3 fresnelColor, vec3 lightDir, vec3 halfDir) {
return fresnelColor + (1.0 - fresnelColor) * pow(1.0 - clamp(dot(lightDir, halfDir), 0.0, 1.0), 5);
}
float specularDistribution(float roughness, vec3 normal, vec3 halfDir) {
float ndoth = clamp(dot(halfDir, normal), 0.0, 1.0);
float gloss2 = pow(0.001 + roughness, 4);
float denom = (ndoth * ndoth*(gloss2 - 1) + 1);
float power = gloss2 / (3.14159 * denom * denom);
return power;
}
/* //NOTE: ANother implementation for specularDistribution
float specularDistribution(float roughness, vec3 normal, vec3 halfDir) {
float gloss = exp2(10 * (1.0 - roughness) + 1);
float power = pow(clamp(dot(halfDir, normal), 0.0, 1.0), gloss);
power *= (gloss * 0.125 + 0.25);
return power;
}
*/
// Frag Shading returns the diffuse amount as W and the specular rgb as xyz
vec4 evalPBRShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, float metallic, vec3 fresnel, float roughness) {
// Diffuse Lighting
float diffuse = clamp(dot(fragNormal, fragLightDir), 0.0, 1.0);
// Specular Lighting
vec3 halfDir = normalize(fragEyeDir + fragLightDir);
vec3 fresnelColor = fresnelSchlick(fresnel, fragLightDir,halfDir);
float power = specularDistribution(roughness, fragNormal, halfDir);
vec3 specular = power * fresnelColor * diffuse;
return vec4(specular, (1.0 - metallic) * diffuse * (1 - fresnelColor.x));
}
<@endfunc@>
<@func declareEvalBlinnRShading()@>
vec4 evalBlinnShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, vec3 specular, float roughness) {
// Diffuse Lighting
float diffuseDot = dot(fragNormal, fragLightDir);
float facingLight = step(0.0, diffuseDot);
float diffuse = diffuseDot * facingLight;
// Specular Lighting depends on the half vector and the roughness
vec3 halfDir = normalize(fragEyeDir + fragLightDir);
float gloss = (1.0 - roughness) * 128.0;
glos *= gloss;
float specularPower = pow(facingLight * max(0.0, dot(halfDir, fragNormal)), gloss);
vec3 reflect = specularPower * specular * diffuse;
return vec4(reflect, diffuse);
}
<@endfunc@>
<$declareEvalPBRShading()$>
// Return xyz the specular/reflection component and w the diffuse component
vec4 evalFragShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, float metallic, vec3 specular, float roughness) {
return evalPBRShading(fragNormal, fragLightDir, fragEyeDir, metallic, specular, roughness);
}
<@endif@>
!> !>

View file

@ -57,9 +57,9 @@ vec3 evalAmbientSpecularIrradiance(Light light, vec3 fragEyeDir, vec3 fragNormal
} }
<@endfunc@> <@endfunc@>
<@func declareLightingAmbient(supportAmbientSphere1, supportAmbientMap1, supportIfAmbientMapElseAmbientSphere1, supportScattering)@> <@func declareLightingAmbient(supportAmbientSphere, supportAmbientMap, supportIfAmbientMapElseAmbientSphere, supportScattering)@>
<$declareEvalAmbientSpecularIrradiance(supportAmbientSphere1, supportAmbientMap1, supportIfAmbientMapElseAmbientSphere1)$> <$declareEvalAmbientSpecularIrradiance($supportAmbientSphere$, $supportAmbientMap$, $supportIfAmbientMapElseAmbientSphere$)$>
<@if supportScattering@> <@if supportScattering@>
float curvatureAO(in float k) { float curvatureAO(in float k) {
@ -74,38 +74,38 @@ void evalLightingAmbient(out vec3 diffuse, out vec3 specular, Light light, vec3
<@endif@> <@endif@>
) { ) {
<@if supportScattering@>
// Diffuse from ambient
diffuse = (1 - metallic) * evalSphericalLight(getLightAmbientSphere(light), normal).xyz;
// Specular highlight from ambient
specular = evalAmbientSpecularIrradiance(light, eyeDir, normal, roughness, fresnel) * obscurance * getLightAmbientIntensity(light);
<@if supportScattering@>
float ambientOcclusion = curvatureAO(lowNormalCurvature.w * 20.0f) * 0.5f; float ambientOcclusion = curvatureAO(lowNormalCurvature.w * 20.0f) * 0.5f;
float ambientOcclusionHF = curvatureAO(midNormalCurvature.w * 8.0f) * 0.5f; float ambientOcclusionHF = curvatureAO(midNormalCurvature.w * 8.0f) * 0.5f;
ambientOcclusion = min(ambientOcclusion, ambientOcclusionHF); ambientOcclusion = min(ambientOcclusion, ambientOcclusionHF);
/* if (showCurvature()) { obscurance = min(obscurance, ambientOcclusion);
diffuse = vec3(ambientOcclusion);
specular = vec3(0.0);
return;
}*/
if (scattering * isScatteringEnabled() > 0.0) {
// Diffuse from ambient // Diffuse from ambient
diffuse = ambientOcclusion * albedo * evalSphericalLight(getLightAmbientSphere(light), lowNormalCurvature.xyz).xyz *getLightAmbientIntensity(light); diffuse = evalSphericalLight(getLightAmbientSphere(light), lowNormalCurvature.xyz).xyz;
// Specular highlight from ambient specular = vec3(0.0);
// vec3 specularLighting = evalGlobalSpecularIrradiance(light, fragEyeDir, fragNormal, roughness, fresnel); }
// color += specularLighting;
// Specular highlight from ambient
// specular = evalAmbientSpecularIrradiance(light, eyeDir, normal, roughness, fresnel) * obscurance * getLightAmbientIntensity(light);
specular = vec3(0.0);
<@else@>
// Diffuse from ambient
diffuse = (1 - metallic) * albedo * evalSphericalLight(getLightAmbientSphere(light), normal).xyz * obscurance * getLightAmbientIntensity(light);
// Specular highlight from ambient
specular = evalAmbientSpecularIrradiance(light, eyeDir, normal, roughness, fresnel) * obscurance * getLightAmbientIntensity(light);
<@endif@> <@endif@>
float lightEnergy = obscurance * getLightAmbientIntensity(light);
if (isAlbedoEnabled() > 0.0) {
diffuse *= albedo;
}
diffuse *= lightEnergy * isDiffuseEnabled() * isAmbientEnabled();
specular *= lightEnergy * isSpecularEnabled() * isAmbientEnabled();
} }
<@endfunc@> <@endfunc@>

View file

@ -18,18 +18,18 @@ void evalLightingDirectional(out vec3 diffuse, out vec3 specular, Light light,
, float scattering, vec4 midNormalCurvature, vec4 lowNormalCurvature , float scattering, vec4 midNormalCurvature, vec4 lowNormalCurvature
<@endif@> <@endif@>
) { ) {
evalFragShading(diffuse, specular, normal, -getLightDirection(light), eyeDir, metallic, fresnel, roughness // Attenuation
vec3 lightEnergy = shadow * getLightColor(light) * getLightIntensity(light);
evalFragShading(diffuse, specular, normal, -getLightDirection(light), eyeDir, metallic, fresnel, roughness, albedo
<@if supportScattering@> <@if supportScattering@>
,scattering, midNormalCurvature, lowNormalCurvature ,scattering, midNormalCurvature, lowNormalCurvature
<@endif@> <@endif@>
); );
vec3 lightEnergy = shadow * getLightColor(light) * getLightIntensity(light); diffuse *= lightEnergy * isDiffuseEnabled() * isDirectionalEnabled();
specular *= lightEnergy * isSpecularEnabled() * isDirectionalEnabled();
diffuse *= albedo * lightEnergy;
specular *= lightEnergy;
} }
<@endfunc@> <@endfunc@>

View file

@ -23,21 +23,19 @@ void evalLightingPoint(out vec3 diffuse, out vec3 specular, Light light,
float fragLightDistance = length(fragLightVec); float fragLightDistance = length(fragLightVec);
vec3 fragLightDir = fragLightVec / fragLightDistance; vec3 fragLightDir = fragLightVec / fragLightDistance;
// Eval attenuation // Eval attenuation
float radialAttenuation = evalLightAttenuation(light, fragLightDistance); float radialAttenuation = evalLightAttenuation(light, fragLightDistance);
vec3 lightEnergy = radialAttenuation * shadow * getLightColor(light) * getLightIntensity(light); vec3 lightEnergy = radialAttenuation * shadow * getLightColor(light) * getLightIntensity(light);
// Eval shading // Eval shading
evalFragShading(diffuse, specular, normal, fragLightDir, fragEyeDir, metallic, fresnel, roughness evalFragShading(diffuse, specular, normal, fragLightDir, fragEyeDir, metallic, fresnel, roughness, albedo
<@if supportScattering@> <@if supportScattering@>
,scattering, midNormalCurvature, lowNormalCurvature ,scattering, midNormalCurvature, lowNormalCurvature
<@endif@> <@endif@>
); );
diffuse *= albedo * lightEnergy; diffuse *= lightEnergy * isDiffuseEnabled() * isPointEnabled();
specular *= lightEnergy * isSpecularEnabled() * isPointEnabled();
specular *= lightEnergy;
if (getLightShowContour(light) > 0.0) { if (getLightShowContour(light) > 0.0) {
// Show edge // Show edge

View file

@ -29,15 +29,14 @@ void evalLightingSpot(out vec3 diffuse, out vec3 specular, Light light,
vec3 lightEnergy = angularAttenuation * radialAttenuation * shadow * getLightColor(light) * getLightIntensity(light); vec3 lightEnergy = angularAttenuation * radialAttenuation * shadow * getLightColor(light) * getLightIntensity(light);
// Eval shading // Eval shading
evalFragShading(diffuse, specular, normal, fragLightDir, fragEyeDir, metallic, fresnel, roughness evalFragShading(diffuse, specular, normal, fragLightDir, fragEyeDir, metallic, fresnel, roughness, albedo
<@if supportScattering@> <@if supportScattering@>
,scattering, midNormalCurvature, lowNormalCurvature ,scattering, midNormalCurvature, lowNormalCurvature
<@endif@> <@endif@>
); );
diffuse *= albedo * lightEnergy; diffuse *= lightEnergy * isDiffuseEnabled() * isSpotEnabled();
specular *= lightEnergy * isSpecularEnabled() * isSpotEnabled();
specular *= lightEnergy;
if (getLightShowContour(light) > 0.0) { if (getLightShowContour(light) > 0.0) {
// Show edges // Show edges

View file

@ -75,6 +75,14 @@ void LightingModel::setSpecular(bool enable) {
bool LightingModel::isSpecularEnabled() const { bool LightingModel::isSpecularEnabled() const {
return (bool)_parametersBuffer.get<Parameters>().enableSpecular; return (bool)_parametersBuffer.get<Parameters>().enableSpecular;
} }
void LightingModel::setAlbedo(bool enable) {
if (enable != isAlbedoEnabled()) {
_parametersBuffer.edit<Parameters>().enableAlbedo = (float)enable;
}
}
bool LightingModel::isAlbedoEnabled() const {
return (bool)_parametersBuffer.get<Parameters>().enableAlbedo;
}
void LightingModel::setAmbientLight(bool enable) { void LightingModel::setAmbientLight(bool enable) {
if (enable != isAmbientLightEnabled()) { if (enable != isAmbientLightEnabled()) {
@ -129,6 +137,7 @@ void MakeLightingModel::configure(const Config& config) {
_lightingModel->setScattering(config.enableScattering); _lightingModel->setScattering(config.enableScattering);
_lightingModel->setDiffuse(config.enableDiffuse); _lightingModel->setDiffuse(config.enableDiffuse);
_lightingModel->setSpecular(config.enableSpecular); _lightingModel->setSpecular(config.enableSpecular);
_lightingModel->setAlbedo(config.enableAlbedo);
_lightingModel->setAmbientLight(config.enableAmbientLight); _lightingModel->setAmbientLight(config.enableAmbientLight);
_lightingModel->setDirectionalLight(config.enableDirectionalLight); _lightingModel->setDirectionalLight(config.enableDirectionalLight);
_lightingModel->setPointLight(config.enablePointLight); _lightingModel->setPointLight(config.enablePointLight);

View file

@ -37,12 +37,14 @@ public:
void setScattering(bool enable); void setScattering(bool enable);
bool isScatteringEnabled() const; bool isScatteringEnabled() const;
void setDiffuse(bool enable); void setDiffuse(bool enable);
bool isDiffuseEnabled() const; bool isDiffuseEnabled() const;
void setSpecular(bool enable); void setSpecular(bool enable);
bool isSpecularEnabled() const; bool isSpecularEnabled() const;
void setAlbedo(bool enable);
bool isAlbedoEnabled() const;
void setAmbientLight(bool enable); void setAmbientLight(bool enable);
bool isAmbientLightEnabled() const; bool isAmbientLightEnabled() const;
void setDirectionalLight(bool enable); void setDirectionalLight(bool enable);
@ -72,7 +74,7 @@ protected:
float enableScattering{ 1.0f }; float enableScattering{ 1.0f };
float enableDiffuse{ 1.0f }; float enableDiffuse{ 1.0f };
float enableSpecular{ 1.0f }; float enableSpecular{ 1.0f };
float spare; float enableAlbedo{ 1.0f };
float enableAmbientLight{ 1.0f }; float enableAmbientLight{ 1.0f };
float enableDirectionalLight{ 1.0f }; float enableDirectionalLight{ 1.0f };
@ -103,6 +105,7 @@ class MakeLightingModelConfig : public render::Job::Config {
Q_PROPERTY(bool enableScattering MEMBER enableScattering NOTIFY dirty) Q_PROPERTY(bool enableScattering MEMBER enableScattering NOTIFY dirty)
Q_PROPERTY(bool enableDiffuse MEMBER enableDiffuse NOTIFY dirty) Q_PROPERTY(bool enableDiffuse MEMBER enableDiffuse NOTIFY dirty)
Q_PROPERTY(bool enableSpecular MEMBER enableSpecular NOTIFY dirty) Q_PROPERTY(bool enableSpecular MEMBER enableSpecular NOTIFY dirty)
Q_PROPERTY(bool enableAlbedo MEMBER enableAlbedo NOTIFY dirty)
Q_PROPERTY(bool enableAmbientLight MEMBER enableAmbientLight NOTIFY dirty) Q_PROPERTY(bool enableAmbientLight MEMBER enableAmbientLight NOTIFY dirty)
Q_PROPERTY(bool enableDirectionalLight MEMBER enableDirectionalLight NOTIFY dirty) Q_PROPERTY(bool enableDirectionalLight MEMBER enableDirectionalLight NOTIFY dirty)
@ -122,6 +125,7 @@ public:
bool enableScattering{ true }; bool enableScattering{ true };
bool enableDiffuse{ true }; bool enableDiffuse{ true };
bool enableSpecular{ true }; bool enableSpecular{ true };
bool enableAlbedo{ true };
bool enableAmbientLight{ true }; bool enableAmbientLight{ true };
bool enableDirectionalLight{ true }; bool enableDirectionalLight{ true };

View file

@ -12,10 +12,13 @@
<@def LIGHTING_MODEL_SLH@> <@def LIGHTING_MODEL_SLH@>
<@func declareLightingModel()@> <@func declareLightingModel()@>
<@endfunc@>
<@func declareLightingModelMaster()@>
struct LightingModel { struct LightingModel {
vec4 _UnlitShadedEmissiveLightmap; vec4 _UnlitShadedEmissiveLightmap;
vec4 _ScatteringDiffuseSpecular; vec4 _ScatteringDiffuseSpecularAlbedo;
vec4 _AmbientDirectionalPointSpot; vec4 _AmbientDirectionalPointSpot;
vec4 _ShowContour; vec4 _ShowContour;
}; };
@ -38,13 +41,16 @@ float isLightmapEnabled() {
} }
float isScatteringEnabled() { float isScatteringEnabled() {
return lightingModel._ScatteringDiffuseSpecular.x; return lightingModel._ScatteringDiffuseSpecularAlbedo.x;
} }
float isDiffuseEnabled() { float isDiffuseEnabled() {
return lightingModel._ScatteringDiffuseSpecular.y; return lightingModel._ScatteringDiffuseSpecularAlbedo.y;
} }
float isSpecularEnabled() { float isSpecularEnabled() {
return lightingModel._ScatteringDiffuseSpecular.z; return lightingModel._ScatteringDiffuseSpecularAlbedo.z;
}
float isAlbedoEnabled() {
return lightingModel._ScatteringDiffuseSpecularAlbedo.w;
} }
float isAmbientEnabled() { float isAmbientEnabled() {
@ -65,6 +71,7 @@ float isShowContour() {
} }
<@endfunc@> <@endfunc@>
<$declareLightingModelMaster()$>
<@func declareBeckmannSpecular()@> <@func declareBeckmannSpecular()@>
@ -149,9 +156,12 @@ vec4 evalPBRShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, float m
void evalFragShading(out vec3 diffuse, out vec3 specular, void evalFragShading(out vec3 diffuse, out vec3 specular,
vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir,
float metallic, vec3 fresnel, float roughness) { float metallic, vec3 fresnel, float roughness, vec3 albedo) {
vec4 shading = evalPBRShading(fragNormal, fragLightDir, fragEyeDir, metallic, fresnel, roughness); vec4 shading = evalPBRShading(fragNormal, fragLightDir, fragEyeDir, metallic, fresnel, roughness);
diffuse = vec3(shading.w); diffuse = vec3(shading.w);
if (isAlbedoEnabled() > 0.0) {
diffuse *= albedo;
}
specular = shading.xyz; specular = shading.xyz;
} }
@ -159,11 +169,12 @@ void evalFragShading(out vec3 diffuse, out vec3 specular,
<@include SubsurfaceScattering.slh@> <@include SubsurfaceScattering.slh@>
<$declareSubsurfaceScatteringBRDF()$> <$declareSubsurfaceScatteringBRDF()$>
void evalFragShading(out vec3 diffuse, out vec3 specular, void evalFragShading(out vec3 diffuse, out vec3 specular,
vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir,
float metallic, vec3 fresnel, float roughness, float metallic, vec3 fresnel, float roughness, vec3 albedo,
float scattering, vec4 midNormalCurvature, vec4 lowNormalCurvature) { float scattering, vec4 midNormalCurvature, vec4 lowNormalCurvature) {
if (scattering > 0.0) { if (scattering * isScatteringEnabled() > 0.0) {
vec3 brdf = evalSkinBRDF(fragLightDir, fragNormal, midNormalCurvature.xyz, lowNormalCurvature.xyz, lowNormalCurvature.w); vec3 brdf = evalSkinBRDF(fragLightDir, fragNormal, midNormalCurvature.xyz, lowNormalCurvature.xyz, lowNormalCurvature.w);
float NdotL = clamp(dot(fragNormal, fragLightDir), 0.0, 1.0); float NdotL = clamp(dot(fragNormal, fragLightDir), 0.0, 1.0);
diffuse = mix(vec3(NdotL), brdf, scattering); diffuse = mix(vec3(NdotL), brdf, scattering);
@ -174,12 +185,14 @@ void evalFragShading(out vec3 diffuse, out vec3 specular,
diffuse *= specularBrdf.y; diffuse *= specularBrdf.y;
specular = vec3(specularBrdf.x); specular = vec3(specularBrdf.x);
} else { } else {
vec4 shading = evalPBRShading(fragNormal, fragLightDir, fragEyeDir, metallic, specular, roughness); vec4 shading = evalPBRShading(fragNormal, fragLightDir, fragEyeDir, metallic, fresnel, roughness);
diffuse = vec3(shading.w); diffuse = vec3(shading.w);
specular = shading.xyz; specular = shading.xyz;
} }
if (isAlbedoEnabled() > 0.0) {
diffuse *= albedo;
}
} }

View file

@ -102,12 +102,18 @@ void ToneMappingEffect::init() {
} }
void ToneMappingEffect::setExposure(float exposure) { void ToneMappingEffect::setExposure(float exposure) {
_parametersBuffer.edit<Parameters>()._exposure = exposure; auto& params = _parametersBuffer.get<Parameters>();
_parametersBuffer.edit<Parameters>()._twoPowExposure = pow(2.0, exposure); if (params._exposure != exposure) {
_parametersBuffer.edit<Parameters>()._exposure = exposure;
_parametersBuffer.edit<Parameters>()._twoPowExposure = pow(2.0, exposure);
}
} }
void ToneMappingEffect::setToneCurve(ToneCurve curve) { void ToneMappingEffect::setToneCurve(ToneCurve curve) {
_parametersBuffer.edit<Parameters>()._toneCurve = curve; auto& params = _parametersBuffer.get<Parameters>();
if (params._toneCurve != curve) {
_parametersBuffer.edit<Parameters>()._toneCurve = curve;
}
} }
void ToneMappingEffect::render(RenderArgs* args) { void ToneMappingEffect::render(RenderArgs* args) {
@ -149,13 +155,8 @@ void ToneMappingEffect::render(RenderArgs* args) {
void ToneMappingDeferred::configure(const Config& config) { void ToneMappingDeferred::configure(const Config& config) {
if (config.exposure >= 0.0f) { _toneMappingEffect.setExposure(config.exposure);
_toneMappingEffect.setExposure(config.exposure); _toneMappingEffect.setToneCurve((ToneMappingEffect::ToneCurve)config.curve);
}
if (config.curve >= 0) {
_toneMappingEffect.setToneCurve((ToneMappingEffect::ToneCurve)config.curve);
}
} }
void ToneMappingDeferred::run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext) { void ToneMappingDeferred::run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext) {

View file

@ -71,7 +71,7 @@ class ToneMappingConfig : public render::Job::Config {
public: public:
ToneMappingConfig() : render::Job::Config(true) {} ToneMappingConfig() : render::Job::Config(true) {}
void setExposure(float newExposure) { exposure = std::max(0.0f, newExposure); emit dirty(); } void setExposure(float newExposure) { exposure = newExposure; emit dirty(); }
void setCurve(int newCurve) { curve = std::max((int)ToneMappingEffect::None, std::min((int)ToneMappingEffect::Filmic, newCurve)); emit dirty(); } void setCurve(int newCurve) { curve = std::max((int)ToneMappingEffect::None, std::min((int)ToneMappingEffect::Filmic, newCurve)); emit dirty(); }

View file

@ -12,6 +12,8 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
<@include DeferredBufferRead.slh@> <@include DeferredBufferRead.slh@>
<@include DeferredGlobalLight.slh@> <@include DeferredGlobalLight.slh@>
@ -30,17 +32,8 @@ void main(void) {
float shadowAttenuation = 1.0; float shadowAttenuation = 1.0;
if (frag.mode == FRAG_MODE_UNLIT) { if (frag.mode == FRAG_MODE_UNLIT) {
// _fragColor = vec4(frag.diffuse, 1.0);
discard; discard;
} else if (frag.mode == FRAG_MODE_LIGHTMAPPED) { } else if (frag.mode == FRAG_MODE_LIGHTMAPPED) {
/* vec3 color = evalLightmappedColor(
getViewInverse(),
shadowAttenuation,
frag.obscurance,
frag.normal,
frag.diffuse,
frag.specularVal.xyz);
_fragColor = vec4(color, 1.0);*/
discard; discard;
} else { } else {
vec4 midNormalCurvature; vec4 midNormalCurvature;
@ -55,9 +48,9 @@ void main(void) {
frag.obscurance, frag.obscurance,
frag.position.xyz, frag.position.xyz,
frag.normal, frag.normal,
frag.diffuse, frag.albedo,
frag.fresnel,
frag.metallic, frag.metallic,
// frag.emissive,
frag.roughness, frag.roughness,
frag.scattering, frag.scattering,
midNormalCurvature, midNormalCurvature,

View file

@ -30,17 +30,8 @@ void main(void) {
float shadowAttenuation = evalShadowAttenuation(worldPos); float shadowAttenuation = evalShadowAttenuation(worldPos);
if (frag.mode == FRAG_MODE_UNLIT) { if (frag.mode == FRAG_MODE_UNLIT) {
// _fragColor = vec4(frag.diffuse, 1.0);
discard; discard;
} else if (frag.mode == FRAG_MODE_LIGHTMAPPED) { } else if (frag.mode == FRAG_MODE_LIGHTMAPPED) {
/* vec3 color = evalLightmappedColor(
getViewInverse(),
shadowAttenuation,
frag.obscurance,
frag.normal,
frag.diffuse,
frag.specularVal.xyz);
_fragColor = vec4(color, 1.0);*/
discard; discard;
} else { } else {
vec4 midNormalCurvature; vec4 midNormalCurvature;
@ -54,9 +45,9 @@ void main(void) {
frag.obscurance, frag.obscurance,
frag.position.xyz, frag.position.xyz,
frag.normal, frag.normal,
frag.diffuse, frag.albedo,
frag.fresnel,
frag.metallic, frag.metallic,
// frag.emissive,
frag.roughness, frag.roughness,
frag.scattering, frag.scattering,
midNormalCurvature, midNormalCurvature,

View file

@ -27,19 +27,9 @@ void main(void) {
float shadowAttenuation = 1.0; float shadowAttenuation = 1.0;
// Light mapped or not ?
if (frag.mode == FRAG_MODE_UNLIT) { if (frag.mode == FRAG_MODE_UNLIT) {
// _fragColor = vec4(frag.diffuse, 1.0); discard;
discard;
} else if (frag.mode == FRAG_MODE_LIGHTMAPPED) { } else if (frag.mode == FRAG_MODE_LIGHTMAPPED) {
/* vec3 color = evalLightmappedColor(
getViewInverse(),
shadowAttenuation,
frag.obscurance,
frag.normal,
frag.diffuse,
frag.specularVal.xyz);
_fragColor = vec4(color, 1.0);*/
discard; discard;
} else { } else {
vec3 color = evalAmbientGlobalColor( vec3 color = evalAmbientGlobalColor(
@ -48,9 +38,9 @@ void main(void) {
frag.obscurance, frag.obscurance,
frag.position.xyz, frag.position.xyz,
frag.normal, frag.normal,
frag.diffuse, frag.albedo,
frag.fresnel,
frag.metallic, frag.metallic,
// frag.emissive,
frag.roughness); frag.roughness);
_fragColor = vec4(color, 1.0); _fragColor = vec4(color, 1.0);
} }

View file

@ -29,19 +29,9 @@ void main(void) {
vec4 worldPos = getViewInverse() * vec4(frag.position.xyz, 1.0); vec4 worldPos = getViewInverse() * vec4(frag.position.xyz, 1.0);
float shadowAttenuation = evalShadowAttenuation(worldPos); float shadowAttenuation = evalShadowAttenuation(worldPos);
// Light mapped or not ?
if (frag.mode == FRAG_MODE_UNLIT) { if (frag.mode == FRAG_MODE_UNLIT) {
// _fragColor = vec4(frag.diffuse, 1.0);
discard; discard;
} else if (frag.mode == FRAG_MODE_LIGHTMAPPED) { } else if (frag.mode == FRAG_MODE_LIGHTMAPPED) {
/* vec3 color = evalLightmappedColor(
getViewInverse(),
shadowAttenuation,
frag.obscurance,
frag.normal,
frag.diffuse,
frag.specularVal.xyz);
_fragColor = vec4(color, 1.0);*/
discard; discard;
} else { } else {
vec3 color = evalAmbientGlobalColor( vec3 color = evalAmbientGlobalColor(
@ -50,9 +40,9 @@ void main(void) {
frag.obscurance, frag.obscurance,
frag.position.xyz, frag.position.xyz,
frag.normal, frag.normal,
frag.diffuse, frag.albedo,
frag.fresnel,
frag.metallic, frag.metallic,
// frag.emissive,
frag.roughness); frag.roughness);
_fragColor = vec4(color, 1.0); _fragColor = vec4(color, 1.0);
} }

View file

@ -29,17 +29,8 @@ void main(void) {
// Light mapped or not ? // Light mapped or not ?
if (frag.mode == FRAG_MODE_UNLIT) { if (frag.mode == FRAG_MODE_UNLIT) {
// _fragColor = vec4(frag.diffuse, 1.0);
discard; discard;
} else if (frag.mode == FRAG_MODE_LIGHTMAPPED) { } else if (frag.mode == FRAG_MODE_LIGHTMAPPED) {
/* vec3 color = evalLightmappedColor(
getViewInverse(),
shadowAttenuation,
frag.obscurance,
frag.normal,
frag.diffuse,
frag.specularVal.xyz);
_fragColor = vec4(color, 1.0);*/
discard; discard;
} else { } else {
vec4 midNormalCurvature; vec4 midNormalCurvature;
@ -53,13 +44,14 @@ void main(void) {
frag.obscurance, frag.obscurance,
frag.position.xyz, frag.position.xyz,
frag.normal, frag.normal,
frag.diffuse, frag.albedo,
frag.fresnel,
frag.metallic, frag.metallic,
// frag.emissive,
frag.roughness, frag.roughness,
frag.scattering, frag.scattering,
midNormalCurvature, midNormalCurvature,
lowNormalCurvature); lowNormalCurvature);
_fragColor = vec4(color, 1.0); _fragColor = vec4(color, 1.0);
} }
} }

View file

@ -31,17 +31,8 @@ void main(void) {
// Light mapped or not ? // Light mapped or not ?
if (frag.mode == FRAG_MODE_UNLIT) { if (frag.mode == FRAG_MODE_UNLIT) {
// _fragColor = vec4(frag.diffuse, 1.0);
discard; discard;
} else if (frag.mode == FRAG_MODE_LIGHTMAPPED) { } else if (frag.mode == FRAG_MODE_LIGHTMAPPED) {
/* vec3 color = evalLightmappedColor(
getViewInverse(),
shadowAttenuation,
frag.obscurance,
frag.normal,
frag.diffuse,
frag.specularVal.xyz);
_fragColor = vec4(color, 1.0);*/
discard; discard;
} else { } else {
vec4 midNormalCurvature; vec4 midNormalCurvature;
@ -55,9 +46,9 @@ void main(void) {
frag.obscurance, frag.obscurance,
frag.position.xyz, frag.position.xyz,
frag.normal, frag.normal,
frag.diffuse, frag.albedo,
frag.fresnel,
frag.metallic, frag.metallic,
//frag.emissive,
frag.roughness, frag.roughness,
frag.scattering, frag.scattering,
midNormalCurvature, midNormalCurvature,

View file

@ -50,11 +50,17 @@ void main(void) {
<$evalMaterialRoughness(roughnessTex, roughness, matKey, roughness)$>; <$evalMaterialRoughness(roughnessTex, roughness, matKey, roughness)$>;
float metallic = getMaterialMetallic(mat); float metallic = getMaterialMetallic(mat);
vec3 fresnel = vec3(0.03); // Default Di-electric fresnel value
if (metallic <= 0.5) {
metallic = 0.0;
} else {
fresnel = albedo;
metallic = 1.0;
}
vec3 emissive = getMaterialEmissive(mat); vec3 emissive = getMaterialEmissive(mat);
<$evalMaterialEmissive(emissiveTex, emissive, matKey, emissive)$>; <$evalMaterialEmissive(emissiveTex, emissive, matKey, emissive)$>;
vec3 fragPosition = _position.xyz; vec3 fragPosition = _position.xyz;
vec3 fragNormal = normalize(_normal); vec3 fragNormal = normalize(_normal);
@ -67,6 +73,7 @@ void main(void) {
fragPosition, fragPosition,
fragNormal, fragNormal,
albedo, albedo,
fresnel,
metallic, metallic,
emissive, emissive,
roughness, opacity), roughness, opacity),

View file

@ -75,9 +75,9 @@ void main(void) {
} }
evalLightingPoint(diffuse, specular, light, evalLightingPoint(diffuse, specular, light,
fragLightVecLen2.xyz, fragEyeDir, frag.normal, frag.roughness, fragLightVecLen2.xyz, fragEyeDir, frag.normal, frag.roughness,
frag.metallic, frag.specular, frag.diffuse, 1.0, frag.metallic, frag.fresnel, frag.albedo, 1.0,
frag.scattering * isScatteringEnabled(), midNormalCurvature, lowNormalCurvature); frag.scattering, midNormalCurvature, lowNormalCurvature);
_fragColor.rgb += diffuse * isDiffuseEnabled() * isPointEnabled(); _fragColor.rgb += diffuse;
_fragColor.rgb += specular * isSpecularEnabled() * isPointEnabled(); _fragColor.rgb += specular;
} }

View file

@ -77,10 +77,10 @@ void main(void) {
} }
evalLightingSpot(diffuse, specular, light, evalLightingSpot(diffuse, specular, light,
fragLightDirLen.xyzw, cosSpotAngle, fragEyeDir, frag.normal, frag.roughness, fragLightDirLen.xyzw, cosSpotAngle, fragEyeDir, frag.normal, frag.roughness,
frag.metallic, frag.specular, frag.diffuse, 1.0, frag.metallic, frag.fresnel, frag.albedo, 1.0,
frag.scattering * isScatteringEnabled(), midNormalCurvature, lowNormalCurvature); frag.scattering, midNormalCurvature, lowNormalCurvature);
_fragColor.rgb += diffuse * isDiffuseEnabled() * isSpotEnabled(); _fragColor.rgb += diffuse;
_fragColor.rgb += specular * isSpecularEnabled() * isSpotEnabled(); _fragColor.rgb += specular;
} }

View file

@ -11,10 +11,10 @@
// Set up the qml ui // Set up the qml ui
var qml = Script.resolvePath('deferredLighting.qml'); var qml = Script.resolvePath('deferredLighting.qml');
var window = new OverlayWindow({ var window = new OverlayWindow({
title: 'Deferred Lighting Pass', title: 'Lighting',
source: qml, source: qml,
width: 400, height: 100, width: 400, height: 150,
}); });
window.setPosition(250, 800); window.setPosition(250, 800);a
window.closed.connect(function() { Script.stop(); }); window.closed.connect(function() { Script.stop(); });

View file

@ -19,7 +19,7 @@ var qml = Script.resolvePath('framebuffer.qml');
var window = new OverlayWindow({ var window = new OverlayWindow({
title: 'Framebuffer Debug', title: 'Framebuffer Debug',
source: qml, source: qml,
width: 400, height: 400, width: 400, height: 50,
}); });
window.setPosition(25, 50); window.setPosition(25, 50);
window.closed.connect(function() { Script.stop(); }); window.closed.connect(function() { Script.stop(); });

View file

@ -11,59 +11,91 @@ import QtQuick 2.5
import QtQuick.Controls 1.4 import QtQuick.Controls 1.4
import "configSlider" import "configSlider"
Row { Column {
spacing: 8 spacing: 8
Column { Row {
spacing: 10 spacing: 8
Repeater { Column {
model: [ spacing: 10
"Unlit:LightingModel:enableUnlit", Repeater {
"Shaded:LightingModel:enableShaded", model: [
"Emissive:LightingModel:enableEmissive", "Unlit:LightingModel:enableUnlit",
"Lightmap:LightingModel:enableLightmap", "Shaded:LightingModel:enableShaded",
] "Emissive:LightingModel:enableEmissive",
CheckBox { "Lightmap:LightingModel:enableLightmap",
text: modelData.split(":")[0] ]
checked: Render.getConfig(modelData.split(":")[1]) CheckBox {
onCheckedChanged: { Render.getConfig(modelData.split(":")[1])[modelData.split(":")[2]] = checked } text: modelData.split(":")[0]
checked: Render.getConfig(modelData.split(":")[1])
onCheckedChanged: { Render.getConfig(modelData.split(":")[1])[modelData.split(":")[2]] = checked }
}
}
}
Column {
spacing: 10
Repeater {
model: [
"Scattering:LightingModel:enableScattering",
"Diffuse:LightingModel:enableDiffuse",
"Specular:LightingModel:enableSpecular",
"Albedo:LightingModel:enableAlbedo",
]
CheckBox {
text: modelData.split(":")[0]
checked: Render.getConfig(modelData.split(":")[1])
onCheckedChanged: { Render.getConfig(modelData.split(":")[1])[modelData.split(":")[2]] = checked }
}
}
}
Column {
spacing: 10
Repeater {
model: [
"Ambient:LightingModel:enableAmbientLight",
"Directional:LightingModel:enableDirectionalLight",
"Point:LightingModel:enablePointLight",
"Spot:LightingModel:enableSpotLight"
]
CheckBox {
text: modelData.split(":")[0]
checked: Render.getConfig(modelData.split(":")[1])
onCheckedChanged: { Render.getConfig(modelData.split(":")[1])[modelData.split(":")[2]] = checked }
}
} }
} }
} }
Column { Column {
spacing: 10 spacing: 10
Repeater { Repeater {
model: [ model: [ "Tone Mapping exposure:ToneMapping:exposure:5.0:-5.0"
"Scattering:LightingModel:enableScattering", ]
"Diffuse:LightingModel:enableDiffuse", ConfigSlider {
"Specular:LightingModel:enableSpecular", label: qsTr(modelData.split(":")[0])
] integral: false
CheckBox { config: Render.getConfig(modelData.split(":")[1])
text: modelData.split(":")[0] property: modelData.split(":")[2]
checked: Render.getConfig(modelData.split(":")[1]) max: modelData.split(":")[3]
onCheckedChanged: { Render.getConfig(modelData.split(":")[1])[modelData.split(":")[2]] = checked } min: modelData.split(":")[4]
} }
} }
}
Column { ComboBox {
spacing: 10 currentIndex: 1
Repeater { model: ListModel {
model: [ id: cbItems
"Ambient:LightingModel:enableAmbientLight", ListElement { text: "RGB"; color: "Yellow" }
"Directional:LightingModel:enableDirectionalLight", ListElement { text: "SRGB"; color: "Green" }
"Point:LightingModel:enablePointLight", ListElement { text: "Reinhard"; color: "Yellow" }
"Spot:LightingModel:enableSpotLight" ListElement { text: "Filmic"; color: "White" }
]
CheckBox {
text: modelData.split(":")[0]
checked: Render.getConfig(modelData.split(":")[1])
onCheckedChanged: { Render.getConfig(modelData.split(":")[1])[modelData.split(":")[2]] = checked }
} }
width: 200
onCurrentIndexChanged: { Render.getConfig("ToneMapping")["curve"] = currentIndex }
} }
} }
} }

View file

@ -23,51 +23,35 @@ Column {
debug.config.mode = mode; debug.config.mode = mode;
} }
function setX(x) { ComboBox {
print(x) currentIndex: 0
model: ListModel {
debug.config.size = Vec4({ x: x, y: -1, z: 1, w: 1 }); id: cbItems
} ListElement { text: "Off"; color: "Yellow" }
Slider { ListElement { text: "Depth"; color: "Green" }
minimumValue: -1.0 ListElement { text: "Albedo"; color: "Yellow" }
value: debug.config.size.x ListElement { text: "Normal"; color: "White" }
onValueChanged: { ListElement { text: "Roughness"; color: "White" }
debug.setX( value); ListElement { text: "Metallic"; color: "White" }
} ListElement { text: "Emissive"; color: "White" }
} ListElement { text: "Unlit"; color: "White" }
ListElement { text: "Occlusion"; color: "White" }
ExclusiveGroup { id: bufferGroup } ListElement { text: "Lightmap"; color: "White" }
Repeater { ListElement { text: "Scattering"; color: "White" }
model: [ ListElement { text: "Lighting"; color: "White" }
"Off", ListElement { text: "Shadow"; color: "White" }
"Depth", ListElement { text: "Linear Depth"; color: "White" }
"Albedo", ListElement { text: "Mid Curvature"; color: "White" }
"Normal", ListElement { text: "Mid Normal"; color: "White" }
"Roughness", ListElement { text: "Low Curvature"; color: "White" }
"Metallic", ListElement { text: "Low Normal"; color: "White" }
"Emissive", ListElement { text: "Debug Scattering"; color: "White" }
"Unlit", ListElement { text: "Ambient Occlusion"; color: "White" }
"Occlusion", ListElement { text: "Ambient Occlusion Blurred"; color: "White" }
"Lightmap", ListElement { text: "Custom"; color: "White" }
"Scattering",
"Lighting",
"Shadow",
"Pyramid Depth",
"Curvature",
"NormalCurvature",
"DiffusedCurvature",
"DiffusedNormalCurvature",
"Debug Scattering",
"Ambient Occlusion",
"Ambient Occlusion Blurred",
"Custom Shader"
]
RadioButton {
text: qsTr(modelData)
exclusiveGroup: bufferGroup
checked: index == 0
onCheckedChanged: if (checked) debug.setDebugMode(index - 1);
} }
width: 200
onCurrentIndexChanged: { debug.setDebugMode(currentIndex - 1) }
} }
} }
} }

View file

@ -741,6 +741,7 @@ int TextTemplate::evalBlockGeneration(std::ostream& dst, const BlockPointer& blo
std::vector< String > paramCache; std::vector< String > paramCache;
paramCache.push_back(""); paramCache.push_back("");
String val; String val;
bool valIsVar = false;
for (int i = 1; i < nbParams; i++) { for (int i = 1; i < nbParams; i++) {
val = block->command.arguments[i]; val = block->command.arguments[i];
if ((val[0] == Tag::VAR) && (val[val.length()-1] == Tag::VAR)) { if ((val[0] == Tag::VAR) && (val[val.length()-1] == Tag::VAR)) {
@ -748,7 +749,10 @@ int TextTemplate::evalBlockGeneration(std::ostream& dst, const BlockPointer& blo
Vars::iterator it = vars.find(val); Vars::iterator it = vars.find(val);
if (it != vars.end()) { if (it != vars.end()) {
val = (*it).second; val = (*it).second;
} else {
val = Tag::NULL_VAR;
} }
valIsVar = true;
} }
Vars::iterator it = vars.find(funcBlock->command.arguments[i]); Vars::iterator it = vars.find(funcBlock->command.arguments[i]);
@ -759,14 +763,19 @@ int TextTemplate::evalBlockGeneration(std::ostream& dst, const BlockPointer& blo
if (val != Tag::NULL_VAR) { if (val != Tag::NULL_VAR) {
vars.insert(Vars::value_type(funcBlock->command.arguments[i], val)); vars.insert(Vars::value_type(funcBlock->command.arguments[i], val));
} }
paramCache.push_back("");
paramCache.push_back(Tag::NULL_VAR);
} }
} }
generateTree(dst, funcBlock, vars); generateTree(dst, funcBlock, vars);
for (int i = 1; i < nbParams; i++) { for (int i = 1; i < nbParams; i++) {
vars[ funcBlock->command.arguments[i] ] = paramCache[i]; if (paramCache[i] == Tag::NULL_VAR) {
vars.erase(funcBlock->command.arguments[i]);
} else {
vars[funcBlock->command.arguments[i]] = paramCache[i];
}
} }
} }
} }

View file

@ -240,4 +240,5 @@ int main (int argc, char** argv) {
} }
return 0; return 0;
} }