mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-12 15:14:35 +00:00
probe capture fixes
review of per and post bake protocols showed that the CAPTURING shader macro was not being properly recompiled in. as opengl was not playing nice with a simple batch shader recompilation for all effected shaders, a full lightmanager restart is at time of writing required. once we have a proper globally cached scene structure stored off GPU side, we'll want to change GFXShader::addGlobalMacro("CAPTURING", String("1")); on over to dirtying that value in the cached buffer via setting a shader global uniform
review of prefilter examples shows a fixed sample count of 1024 across multiple implementations, so we'll use the standard barring further research into where that number is comming from for a scalar approach
review of gl shaders shows a doubleup in compiled state testing, so slimmed that down and added additional debugging reports
This commit is contained in:
parent
97de2e6b60
commit
8c38448428
8 changed files with 104 additions and 30 deletions
|
|
@ -66,6 +66,10 @@ uniform vec4 albedo;
|
|||
#define DEBUGVIZ_CONTRIB 0
|
||||
#endif
|
||||
|
||||
#ifndef CAPTURE_LIGHT_FLOOR
|
||||
#define CAPTURE_LIGHT_FLOOR 0.04
|
||||
#endif
|
||||
|
||||
vec3 getDistanceVectorToPlane( vec3 origin, vec3 direction, vec4 plane )
|
||||
{
|
||||
float denum = dot( plane.xyz, direction.xyz );
|
||||
|
|
@ -234,7 +238,7 @@ vec3 evaluateStandardBRDF(Surface surface, SurfaceToLight surfaceToLight)
|
|||
vec3 Fr = D * F * Vis;
|
||||
|
||||
#if CAPTURING == 1
|
||||
return saturate(mix(Fd + Fr,surface.f0,surface.metalness));
|
||||
return mix(Fd + Fr, surface.baseColor.rgb, surface.metalness);
|
||||
#else
|
||||
return Fd + Fr;
|
||||
#endif
|
||||
|
|
@ -243,23 +247,38 @@ vec3 evaluateStandardBRDF(Surface surface, SurfaceToLight surfaceToLight)
|
|||
|
||||
vec3 getDirectionalLight(Surface surface, SurfaceToLight surfaceToLight, vec3 lightColor, float lightIntensity, float shadow)
|
||||
{
|
||||
vec3 factor = lightColor * max(surfaceToLight.NdotL * shadow * lightIntensity, 0.0f);
|
||||
#if CAPTURING == 1
|
||||
float lightfloor = CAPTURE_LIGHT_FLOOR;
|
||||
#else
|
||||
float lightfloor = 0.0;
|
||||
#endif
|
||||
vec3 factor = lightColor * max(surfaceToLight.NdotL * shadow * lightIntensity, lightfloor);
|
||||
return evaluateStandardBRDF(surface,surfaceToLight) * factor;
|
||||
}
|
||||
|
||||
vec3 getPunctualLight(Surface surface, SurfaceToLight surfaceToLight, vec3 lightColor, float lightIntensity, float radius, float shadow)
|
||||
{
|
||||
#if CAPTURING == 1
|
||||
float lightfloor = CAPTURE_LIGHT_FLOOR;
|
||||
#else
|
||||
float lightfloor = 0.0;
|
||||
#endif
|
||||
float attenuation = getDistanceAtt(surfaceToLight.Lu, radius);
|
||||
vec3 factor = lightColor * max(surfaceToLight.NdotL * shadow * lightIntensity * attenuation, 0.0f);
|
||||
vec3 factor = lightColor * max(surfaceToLight.NdotL * shadow * lightIntensity * attenuation, lightfloor);
|
||||
return evaluateStandardBRDF(surface,surfaceToLight) * factor;
|
||||
}
|
||||
|
||||
vec3 getSpotlight(Surface surface, SurfaceToLight surfaceToLight, vec3 lightColor, float lightIntensity, float radius, vec3 lightDir, vec2 lightSpotParams, float shadow)
|
||||
{
|
||||
#if CAPTURING == 1
|
||||
float lightfloor = CAPTURE_LIGHT_FLOOR;
|
||||
#else
|
||||
float lightfloor = 0.0;
|
||||
#endif
|
||||
float attenuation = 1.0f;
|
||||
attenuation *= getDistanceAtt(surfaceToLight.Lu, radius);
|
||||
attenuation *= getSpotAngleAtt(-surfaceToLight.L, lightDir, lightSpotParams.xy);
|
||||
vec3 factor = lightColor * max(surfaceToLight.NdotL* shadow * lightIntensity * attenuation, 0.0f) ;
|
||||
vec3 factor = lightColor * max(surfaceToLight.NdotL* shadow * lightIntensity * attenuation, lightfloor);
|
||||
return evaluateStandardBRDF(surface,surfaceToLight) * factor;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -68,6 +68,10 @@ uniform float4 albedo;
|
|||
#define DEBUGVIZ_CONTRIB 0
|
||||
#endif
|
||||
|
||||
#ifndef CAPTURE_LIGHT_FLOOR
|
||||
#define CAPTURE_LIGHT_FLOOR 0.04
|
||||
#endif
|
||||
|
||||
inline float3 getDistanceVectorToPlane( float3 origin, float3 direction, float4 plane )
|
||||
{
|
||||
float denum = dot( plane.xyz, direction.xyz );
|
||||
|
|
@ -235,7 +239,7 @@ float3 evaluateStandardBRDF(Surface surface, SurfaceToLight surfaceToLight)
|
|||
float3 Fr = D * F * Vis;
|
||||
|
||||
#if CAPTURING == 1
|
||||
return saturate(lerp(Fd + Fr,surface.f0,surface.metalness));
|
||||
return lerp(Fd + Fr,surface.baseColor.rgb,surface.metalness);
|
||||
#else
|
||||
return Fd + Fr;
|
||||
#endif
|
||||
|
|
@ -244,25 +248,41 @@ float3 evaluateStandardBRDF(Surface surface, SurfaceToLight surfaceToLight)
|
|||
|
||||
float3 getDirectionalLight(Surface surface, SurfaceToLight surfaceToLight, float3 lightColor, float lightIntensity, float shadow)
|
||||
{
|
||||
float3 factor = lightColor * max(surfaceToLight.NdotL* shadow * lightIntensity, 0.0f) ;
|
||||
#if CAPTURING == 1
|
||||
float lightfloor = CAPTURE_LIGHT_FLOOR;
|
||||
#else
|
||||
float lightfloor = 0.0;
|
||||
#endif
|
||||
float3 factor = lightColor * max(surfaceToLight.NdotL* shadow * lightIntensity, lightfloor) ;
|
||||
return evaluateStandardBRDF(surface,surfaceToLight) * factor;
|
||||
}
|
||||
|
||||
float3 getPunctualLight(Surface surface, SurfaceToLight surfaceToLight, float3 lightColor, float lightIntensity, float radius, float shadow)
|
||||
{
|
||||
#if CAPTURING == 1
|
||||
float lightfloor = CAPTURE_LIGHT_FLOOR;
|
||||
#else
|
||||
float lightfloor = 0.0;
|
||||
#endif
|
||||
float attenuation = getDistanceAtt(surfaceToLight.Lu, radius);
|
||||
float3 factor = lightColor * max(surfaceToLight.NdotL* shadow * lightIntensity * attenuation, 0.0f) ;
|
||||
float3 factor = lightColor * max(surfaceToLight.NdotL* shadow * lightIntensity * attenuation, lightfloor) ;
|
||||
return evaluateStandardBRDF(surface,surfaceToLight) * factor;
|
||||
}
|
||||
|
||||
float3 getSpotlight(Surface surface, SurfaceToLight surfaceToLight, float3 lightColor, float lightIntensity, float radius, float3 lightDir, float2 lightSpotParams, float shadow)
|
||||
{
|
||||
#if CAPTURING == 1
|
||||
float lightfloor = CAPTURE_LIGHT_FLOOR;
|
||||
#else
|
||||
float lightfloor = 0.0;
|
||||
#endif
|
||||
float attenuation = 1.0f;
|
||||
attenuation *= getDistanceAtt(surfaceToLight.Lu, radius);
|
||||
attenuation *= getSpotAngleAtt(-surfaceToLight.L, lightDir, lightSpotParams.xy);
|
||||
float3 factor = lightColor * max(surfaceToLight.NdotL* shadow * lightIntensity * attenuation, 0.0f) ;
|
||||
float3 factor = lightColor * max(surfaceToLight.NdotL* shadow * lightIntensity * attenuation, lightfloor) ;
|
||||
return evaluateStandardBRDF(surface,surfaceToLight) * factor;
|
||||
}
|
||||
|
||||
float computeSpecOcclusion( float NdotV , float AO , float roughness )
|
||||
{
|
||||
return saturate (pow( abs(NdotV + AO) , exp2 ( -16.0f * roughness - 1.0f )) - 1.0f + AO );
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ vec3 ImportanceSampleGGX(vec2 Xi, vec3 N)
|
|||
|
||||
vec3 prefilterEnvMap(vec3 R)
|
||||
{
|
||||
int sampleCount = resolution*2;
|
||||
int sampleCount = 1024;
|
||||
vec3 N = R;
|
||||
vec3 V = R;
|
||||
float totalWeight = 0.0;
|
||||
|
|
@ -107,7 +107,7 @@ vec3 prefilterEnvMap(vec3 R)
|
|||
float HdotV = max(dot(H, V), 0.0);
|
||||
float pdf = D * NdotH / (4.0 * HdotV) + 0.0001;
|
||||
|
||||
float saTexel = 4.0 * M_PI_F / float(6.0 * sampleCount * sampleCount);
|
||||
float saTexel = 4.0 * M_PI_F / float(6.0 * resolution * resolution);
|
||||
float saSample = 1.0 / (float(sampleCount) * pdf + 0.0001);
|
||||
|
||||
float mipLevel = roughness == 0.0 ? 0.0 : 0.5 * log2(saSample / saTexel);
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ float3 ImportanceSampleGGX(float2 Xi, float3 N)
|
|||
|
||||
float4 prefilterEnvMap(float3 R)
|
||||
{
|
||||
int sampleCount = resolution*2;
|
||||
int sampleCount = 1024;
|
||||
float3 N = R;
|
||||
float3 V = R;
|
||||
float totalWeight = 0.0;
|
||||
|
|
@ -109,7 +109,7 @@ float4 prefilterEnvMap(float3 R)
|
|||
float HdotV = max(dot(H, V), 0.0);
|
||||
float pdf = D * NdotH / (4.0 * HdotV) + 0.0001;
|
||||
|
||||
float saTexel = 4.0 * M_PI_F / (6.0 * sampleCount * sampleCount);
|
||||
float saTexel = 4.0 * M_PI_F / (6.0 * resolution * resolution);
|
||||
float saSample = 1.0 / (float(sampleCount) * pdf + 0.0001);
|
||||
|
||||
float mipLevel = roughness == 0.0 ? 0.0 : 0.5 * log2(saSample / saTexel);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue