by and large, Opengl branch compatibility alterations, though do again note the inclusion of
   sampler["lightBuffer"] = "#lightinfo";
   sampler["colorBuffer"] = "#color";
   sampler["matInfoBuffer"] = "#matinfo";

and
   samplerNames[5] = "$lightBuffer";
   samplerNames[6] = "$colorBuffer";
   samplerNames[7] = "$matInfoBuffer";
entries. This is where the engine knows to pass along a given rendertarget for input into a predefined shader, as opposed to the prior phase's output to targets within procedural ones.

Shader:
the XXXLight.hlsl/glsls account for alterations in inputs, check for emissive and translucency, apply Felix's Normal Mapped Ambient. and pass the results along to  AL_DeferredOutput for final computation before returning the result.
the lighting.hlsl/.glsl consissts of removal of the overridden engine-specific phong specular variant, and defines the  AL_DeferredOutput  method, which equates to the previously used pixspecular feature defined along the lines of
http://books.google.com/books?id=GY-AAwAAQBAJ&pg=PA112&lpg=PA112&dq=blinn+phong+specular+gloss+hlsl&source=bl&ots=q9SKJkmWHB&sig=uLIHX10Zul0X0LL2ehSMq7IFBIM&hl=en&sa=X&ei=DbcsVPeWEdW1yASDy4LYDw&ved=0CB4Q6AEwAA#v=onepage&q=gloss%20&f=false

also includes visualizers

Long term impact: This area, along with the \game\shaders\common\lighting\advanced\lightingUtils.hlsl/.glsl pair will be where we plug in properly attenuated Cook-Torrence later, presuming the impact is not to hefty.
This commit is contained in:
Azaezel 2016-02-16 02:29:54 -06:00
parent 196b214eae
commit 5ed06fff9d
13 changed files with 203 additions and 50 deletions

View file

@ -36,8 +36,11 @@ new GFXStateBlockData( AL_VectorLightState )
samplersDefined = true;
samplerStates[0] = SamplerClampPoint; // G-buffer
mSamplerNames[0] = "prePassBuffer";
samplerStates[1] = SamplerClampPoint; // Shadow Map (Do not change this to linear, as all cards can not filter equally.)
mSamplerNames[1] = "shadowMap";
samplerStates[2] = SamplerClampLinear; // SSAO Mask
mSamplerNames[2] = "ssaoMask";
samplerStates[3] = SamplerWrapPoint; // Random Direction Map
cullDefined = true;
@ -66,7 +69,9 @@ new ShaderData( AL_VectorLightShader )
samplerNames[2] = "$dynamicShadowMap";
samplerNames[3] = "$ssaoMask";
samplerNames[4] = "$gTapRotationTex";
samplerNames[5] = "$lightBuffer";
samplerNames[6] = "$colorBuffer";
samplerNames[7] = "$matInfoBuffer";
pixVersion = 3.0;
};
@ -78,7 +83,10 @@ new CustomMaterial( AL_VectorLightMaterial )
sampler["prePassBuffer"] = "#prepass";
sampler["shadowMap"] = "$dynamiclight";
sampler["dynamicShadowMap"] = "$dynamicShadowMap";
sampler["ssaoMask"] = "#ssaoMask";
sampler["ssaoMask"] = "#ssaoMask";
sampler["lightBuffer"] = "#lightinfo";
sampler["colorBuffer"] = "#color";
sampler["matInfoBuffer"] = "#matinfo";
target = "lightinfo";
@ -103,7 +111,9 @@ new GFXStateBlockData( AL_ConvexLightState )
samplersDefined = true;
samplerStates[0] = SamplerClampPoint; // G-buffer
mSamplerNames[0] = "prePassBuffer";
samplerStates[1] = SamplerClampPoint; // Shadow Map (Do not use linear, these are perspective projections)
mSamplerNames[1] = "shadowMap";
samplerStates[2] = SamplerClampLinear; // Cookie Map
samplerStates[3] = SamplerWrapPoint; // Random Direction Map
@ -133,6 +143,9 @@ new ShaderData( AL_PointLightShader )
samplerNames[2] = "$dynamicShadowMap";
samplerNames[3] = "$cookieMap";
samplerNames[4] = "$gTapRotationTex";
samplerNames[5] = "$lightBuffer";
samplerNames[6] = "$colorBuffer";
samplerNames[7] = "$matInfoBuffer";
pixVersion = 3.0;
};
@ -146,6 +159,9 @@ new CustomMaterial( AL_PointLightMaterial )
sampler["shadowMap"] = "$dynamiclight";
sampler["dynamicShadowMap"] = "$dynamicShadowMap";
sampler["cookieMap"] = "$dynamiclightmask";
sampler["lightBuffer"] = "#lightinfo";
sampler["colorBuffer"] = "#color";
sampler["matInfoBuffer"] = "#matinfo";
target = "lightinfo";
@ -166,6 +182,9 @@ new ShaderData( AL_SpotLightShader )
samplerNames[2] = "$dynamicShadowMap";
samplerNames[3] = "$cookieMap";
samplerNames[4] = "$gTapRotationTex";
samplerNames[5] = "$lightBuffer";
samplerNames[6] = "$colorBuffer";
samplerNames[7] = "$matInfoBuffer";
pixVersion = 3.0;
};
@ -179,6 +198,9 @@ new CustomMaterial( AL_SpotLightMaterial )
sampler["shadowMap"] = "$dynamiclight";
sampler["dynamicShadowMap"] = "$dynamicShadowMap";
sampler["cookieMap"] = "$dynamiclightmask";
sampler["lightBuffer"] = "#lightinfo";
sampler["colorBuffer"] = "#color";
sampler["matInfoBuffer"] = "#matinfo";
target = "lightinfo";

View file

@ -20,6 +20,7 @@
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "./torque.glsl"
#ifndef TORQUE_SHADERGEN
@ -207,14 +208,42 @@ void compute4Lights( vec3 wsView,
///
float AL_CalcSpecular( vec3 toLight, vec3 normal, vec3 toEye )
{
#ifdef PHONG_SPECULAR
// (R.V)^c
float specVal = dot( normalize( -reflect( toLight, normal ) ), toEye );
#else
// (N.H)^c [Blinn-Phong, TGEA style, default]
float specVal = dot( normal, normalize( toLight + toEye ) );
#endif
// (R.V)^c
float specVal = dot( normalize( -reflect( toLight, normal ) ), toEye );
// Return the specular factor.
return pow( max( specVal, 0.00001f ), AL_ConstantSpecularPower );
}
/// The output for Deferred Lighting
///
/// @param toLight Normalized vector representing direction from the pixel
/// being lit, to the light source, in world space.
///
/// @param normal Normalized surface normal.
///
/// @param toEye The normalized vector representing direction from the pixel
/// being lit to the camera.
///
vec4 AL_DeferredOutput(
vec3 lightColor,
vec3 diffuseColor,
vec4 matInfo,
vec4 ambient,
float specular,
float shadowAttenuation)
{
vec3 specularColor = vec3(specular);
bool metalness = getFlag(matInfo.r, 3);
if ( metalness )
{
specularColor = 0.04 * (1 - specular) + diffuseColor * specular;
}
//specular = color * map * spec^gloss
float specularOut = (specularColor * matInfo.b * min(pow(max(specular,1.0f), max((matInfo.a / AL_ConstantSpecularPower),1.0f)),matInfo.a)).r;
lightColor *= vec3(shadowAttenuation);
lightColor += ambient.rgb;
return vec4(lightColor.rgb, specularOut);
}

View file

@ -20,6 +20,7 @@
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "./torque.hlsl"
#ifndef TORQUE_SHADERGEN
@ -207,14 +208,42 @@ void compute4Lights( float3 wsView,
///
float AL_CalcSpecular( float3 toLight, float3 normal, float3 toEye )
{
#ifdef PHONG_SPECULAR
// (R.V)^c
float specVal = dot( normalize( -reflect( toLight, normal ) ), toEye );
#else
// (N.H)^c [Blinn-Phong, TGEA style, default]
float specVal = dot( normal, normalize( toLight + toEye ) );
#endif
// (R.V)^c
float specVal = dot( normalize( -reflect( toLight, normal ) ), toEye );
// Return the specular factor.
return pow( max( specVal, 0.00001f ), AL_ConstantSpecularPower );
}
/// The output for Deferred Lighting
///
/// @param toLight Normalized vector representing direction from the pixel
/// being lit, to the light source, in world space.
///
/// @param normal Normalized surface normal.
///
/// @param toEye The normalized vector representing direction from the pixel
/// being lit to the camera.
///
float4 AL_DeferredOutput(
float3 lightColor,
float3 diffuseColor,
float4 matInfo,
float4 ambient,
float specular,
float shadowAttenuation)
{
float3 specularColor = float3(specular, specular, specular);
bool metalness = getFlag(matInfo.r, 3);
if ( metalness )
{
specularColor = 0.04 * (1 - specular) + diffuseColor * specular;
}
//specular = color * map * spec^gloss
float specularOut = (specularColor * matInfo.b * min(pow(specular, max(( matInfo.a/ AL_ConstantSpecularPower),1.0f)),matInfo.a)).r;
lightColor *= shadowAttenuation;
lightColor += ambient.rgb;
return float4(lightColor.rgb, specularOut);
}

View file

@ -27,8 +27,6 @@
float4 main( PFXVertToPix IN,
uniform sampler2D lightPrePassTex : register(S0) ) : COLOR0
{
float3 lightcolor;
float nl_Att, specular;
lightinfoUncondition( tex2D( lightPrePassTex, IN.uv0 ), lightcolor, nl_Att, specular );
return float4( lightcolor, 1.0 );
float4 lightColor = tex2D( lightPrePassTex, IN.uv0 );
return float4( lightColor.rgb, 1.0 );
}

View file

@ -27,8 +27,6 @@
float4 main( PFXVertToPix IN,
uniform sampler2D lightPrePassTex : register(S0) ) : COLOR0
{
float3 lightcolor;
float nl_Att, specular;
lightinfoUncondition( tex2D( lightPrePassTex, IN.uv0 ), lightcolor, nl_Att, specular );
float specular = tex2D( lightPrePassTex, IN.uv0 ).a;
return float4( specular, specular, specular, 1.0 );
}

View file

@ -24,14 +24,12 @@
#include "shadergen:/autogenConditioners.h"
in vec2 uv0;
uniform sampler2D lightInfoBuffer;
uniform sampler2D lightPrePassTex;
out vec4 OUT_col;
void main()
{
vec3 lightcolor;
float nl_Att, specular;
lightinfoUncondition( texture( lightInfoBuffer, uv0 ), lightcolor, nl_Att, specular );
OUT_col = vec4( lightcolor, 1.0 );
vec4 lightColor = texture( lightPrePassTex, uv0 );
OUT_col = vec4( lightColor.rgb, 1.0 );
}

View file

@ -24,14 +24,12 @@
#include "shadergen:/autogenConditioners.h"
in vec2 uv0;
uniform sampler2D lightInfoBuffer;
uniform sampler2D lightPrePassTex;
out vec4 OUT_col;
void main()
{
vec3 lightcolor;
float nl_Att, specular;
lightinfoUncondition( texture( lightInfoBuffer, uv0 ), lightcolor, nl_Att, specular );
float specular = texture( lightPrePassTex, uv0 ).a;
OUT_col = vec4( specular, specular, specular, 1.0 );
}

View file

@ -33,6 +33,7 @@
in vec4 wsEyeDir;
in vec4 ssPos;
in vec4 vsEyeDir;
in vec4 color;
#ifdef USE_COOKIE_TEX
@ -111,6 +112,10 @@ uniform sampler2D prePassBuffer;
uniform sampler2D dynamicShadowMap;
#endif
uniform sampler2D lightBuffer;
uniform sampler2D colorBuffer;
uniform sampler2D matInfoBuffer;
uniform vec4 rtParams0;
uniform vec3 lightPosition;
@ -133,6 +138,15 @@ void main()
vec3 ssPos = ssPos.xyz / ssPos.w;
vec2 uvScene = getUVFromSSPos( ssPos, rtParams0 );
// Emissive.
vec4 matInfo = texture( matInfoBuffer, uvScene );
bool emissive = getFlag( matInfo.r, 0 );
if ( emissive )
{
OUT_col = vec4(0.0, 0.0, 0.0, 0.0);
return;
}
// Sample/unpack the normal/z data
vec4 prepassSample = prepassUncondition( prePassBuffer, uvScene );
vec3 normal = prepassSample.rgb;
@ -244,5 +258,6 @@ void main()
addToResult = ( 1.0 - shadowed ) * abs(lightMapParams);
}
OUT_col = lightinfoCondition( lightColorOut, Sat_NL_Att, specular, addToResult );
vec4 colorSample = texture( colorBuffer, uvScene );
OUT_col = AL_DeferredOutput(lightColorOut, colorSample.rgb, matInfo, addToResult, specular, Sat_NL_Att);
}

View file

@ -32,10 +32,12 @@
in vec4 wsEyeDir;
in vec4 ssPos;
in vec4 vsEyeDir;
in vec4 color;
#define IN_wsEyeDir wsEyeDir
#define IN_ssPos ssPos
#define IN_vsEyeDir vsEyeDir
#define IN_color color
#ifdef USE_COOKIE_TEX
@ -48,6 +50,10 @@ uniform sampler2D prePassBuffer;
uniform sampler2D shadowMap;
uniform sampler2D dynamicShadowMap;
uniform sampler2D lightBuffer;
uniform sampler2D colorBuffer;
uniform sampler2D matInfoBuffer;
uniform vec4 rtParams0;
uniform vec3 lightPosition;
@ -74,6 +80,15 @@ void main()
vec3 ssPos = IN_ssPos.xyz / IN_ssPos.w;
vec2 uvScene = getUVFromSSPos( ssPos, rtParams0 );
// Emissive.
vec4 matInfo = texture( matInfoBuffer, uvScene );
bool emissive = getFlag( matInfo.r, 0 );
if ( emissive )
{
OUT_col = vec4(0.0, 0.0, 0.0, 0.0);
return;
}
// Sample/unpack the normal/z data
vec4 prepassSample = prepassUncondition( prePassBuffer, uvScene );
vec3 normal = prepassSample.rgb;
@ -180,5 +195,6 @@ void main()
addToResult = ( 1.0 - shadowed ) * abs(lightMapParams);
}
OUT_col = lightinfoCondition( lightColorOut, Sat_NL_Att, specular, addToResult );
vec4 colorSample = texture( colorBuffer, uvScene );
OUT_col = AL_DeferredOutput(lightColorOut, colorSample.rgb, matInfo, addToResult, specular, Sat_NL_Att);
}

View file

@ -39,10 +39,13 @@ uniform sampler2D dynamicShadowMap;
#ifdef USE_SSAO_MASK
uniform sampler2D ssaoMask ;
uniform vec4 rtParams2;
uniform vec4 rtParams3;
#endif
uniform sampler2D prePassBuffer;
uniform sampler2D prePassBuffer;
uniform sampler2D lightBuffer;
uniform sampler2D colorBuffer;
uniform sampler2D matInfoBuffer;
uniform vec3 lightDirection;
uniform vec4 lightColor;
uniform float lightBrightness;
@ -189,7 +192,16 @@ vec4 AL_VectorLightShadowCast( sampler2D _sourceshadowMap,
out vec4 OUT_col;
void main()
{
{
// Emissive.
float4 matInfo = texture( matInfoBuffer, uv0 );
bool emissive = getFlag( matInfo.r, 0 );
if ( emissive )
{
OUT_col = vec4(1.0, 1.0, 1.0, 0.0);
return;
}
// Sample/unpack the normal/z data
vec4 prepassSample = prepassUncondition( prePassBuffer, uv0 );
vec3 normal = prepassSample.rgb;
@ -228,8 +240,6 @@ void main()
shadowSoftness,
dotNL,
overDarkPSSM);
vec4 dynamic_shadowed_colors = AL_VectorLightShadowCast( dynamicShadowMap,
uv0.xy,
dynamicWorldToLightProj,
@ -242,14 +252,13 @@ void main()
shadowSoftness,
dotNL,
overDarkPSSM);
float static_shadowed = static_shadowed_colors.a;
float dynamic_shadowed = dynamic_shadowed_colors.a;
#ifdef PSSM_DEBUG_RENDER
debugColor = static_shadowed_colors.rgb*0.5+dynamic_shadowed_colors.rgb*0.5;
#endif
// Fade out the shadow at the end of the range.
vec4 zDist = vec4(zNearFarInvNearFar.x + zNearFarInvNearFar.y * depth);
float fadeOutAmt = ( zDist.x - fadeStartLength.x ) * fadeStartLength.y;
@ -295,7 +304,7 @@ void main()
// Sample the AO texture.
#ifdef USE_SSAO_MASK
float ao = 1.0 - texture( ssaoMask, viewportCoordToRenderTarget( uv0.xy, rtParams2 ) ).r;
float ao = 1.0 - texture( ssaoMask, viewportCoordToRenderTarget( uv0.xy, rtParams3 ) ).r;
addToResult *= ao;
#endif
@ -303,6 +312,6 @@ void main()
lightColorOut = debugColor;
#endif
OUT_col = lightinfoCondition( lightColorOut, Sat_NL_Att, specular, addToResult );
vec4 colorSample = texture( colorBuffer, uv0 );
OUT_col = AL_DeferredOutput(lightColorOut, colorSample.rgb, matInfo, addToResult, specular, Sat_NL_Att);
}

View file

@ -34,6 +34,7 @@ struct ConvexConnectP
float4 wsEyeDir : TEXCOORD0;
float4 ssPos : TEXCOORD1;
float4 vsEyeDir : TEXCOORD2;
float4 color : COLOR0;
};
@ -117,6 +118,10 @@ float4 main( ConvexConnectP IN,
uniform sampler2D dynamicShadowMap : register(S2),
#endif
uniform sampler2D lightBuffer : register(S5),
uniform sampler2D colorBuffer : register(S6),
uniform sampler2D matInfoBuffer : register(S7),
uniform float4 rtParams0,
uniform float3 lightPosition,
@ -136,7 +141,15 @@ float4 main( ConvexConnectP IN,
// Compute scene UV
float3 ssPos = IN.ssPos.xyz / IN.ssPos.w;
float2 uvScene = getUVFromSSPos( ssPos, rtParams0 );
// Emissive.
float4 matInfo = tex2D( matInfoBuffer, uvScene );
bool emissive = getFlag( matInfo.r, 0 );
if ( emissive )
{
return float4(0.0, 0.0, 0.0, 0.0);
}
// Sample/unpack the normal/z data
float4 prepassSample = prepassUncondition( prePassBuffer, uvScene );
float3 normal = prepassSample.rgb;
@ -250,5 +263,6 @@ float4 main( ConvexConnectP IN,
addToResult = ( 1.0 - shadowed ) * abs(lightMapParams);
}
return lightinfoCondition( lightColorOut, Sat_NL_Att, specular, addToResult );
float4 colorSample = tex2D( colorBuffer, uvScene );
return AL_DeferredOutput(lightColorOut, colorSample.rgb, matInfo, addToResult, specular, Sat_NL_Att);
}

View file

@ -34,6 +34,7 @@ struct ConvexConnectP
float4 wsEyeDir : TEXCOORD0;
float4 ssPos : TEXCOORD1;
float4 vsEyeDir : TEXCOORD2;
float4 color : COLOR0;
};
#ifdef USE_COOKIE_TEX
@ -50,6 +51,10 @@ float4 main( ConvexConnectP IN,
uniform sampler2D shadowMap : register(S1),
uniform sampler2D dynamicShadowMap : register(S2),
uniform sampler2D lightBuffer : register(S5),
uniform sampler2D colorBuffer : register(S6),
uniform sampler2D matInfoBuffer : register(S7),
uniform float4 rtParams0,
uniform float3 lightPosition,
@ -72,6 +77,14 @@ float4 main( ConvexConnectP IN,
float3 ssPos = IN.ssPos.xyz / IN.ssPos.w;
float2 uvScene = getUVFromSSPos( ssPos, rtParams0 );
// Emissive.
float4 matInfo = tex2D( matInfoBuffer, uvScene );
bool emissive = getFlag( matInfo.r, 0 );
if ( emissive )
{
return float4(0.0, 0.0, 0.0, 0.0);
}
// Sample/unpack the normal/z data
float4 prepassSample = prepassUncondition( prePassBuffer, uvScene );
float3 normal = prepassSample.rgb;
@ -179,5 +192,6 @@ float4 main( ConvexConnectP IN,
addToResult = ( 1.0 - shadowed ) * abs(lightMapParams);
}
return lightinfoCondition( lightColorOut, Sat_NL_Att, specular, addToResult );
float4 colorSample = tex2D( colorBuffer, uvScene );
return AL_DeferredOutput(lightColorOut, colorSample.rgb, matInfo, addToResult, specular, Sat_NL_Att);
}

View file

@ -157,6 +157,10 @@ float4 main( FarFrustumQuadConnectP IN,
uniform sampler2D prePassBuffer : register(S0),
uniform sampler2D lightBuffer : register(S5),
uniform sampler2D colorBuffer : register(S6),
uniform sampler2D matInfoBuffer : register(S7),
uniform float3 lightDirection,
uniform float4 lightColor,
uniform float lightBrightness,
@ -190,7 +194,15 @@ float4 main( FarFrustumQuadConnectP IN,
uniform float4 dynamicFarPlaneScalePSSM
) : COLOR0
{
{
// Emissive.
float4 matInfo = tex2D( matInfoBuffer, IN.uv0 );
bool emissive = getFlag( matInfo.r, 0 );
if ( emissive )
{
return float4(1.0, 1.0, 1.0, 0.0);
}
// Sample/unpack the normal/z data
float4 prepassSample = prepassUncondition( prePassBuffer, IN.uv0 );
float3 normal = prepassSample.rgb;
@ -229,7 +241,6 @@ float4 main( FarFrustumQuadConnectP IN,
shadowSoftness,
dotNL,
overDarkPSSM);
float4 dynamic_shadowed_colors = AL_VectorLightShadowCast( dynamicShadowMap,
IN.uv0.xy,
dynamicWorldToLightProj,
@ -276,6 +287,7 @@ float4 main( FarFrustumQuadConnectP IN,
float Sat_NL_Att = saturate( dotNL * shadowed ) * lightBrightness;
float3 lightColorOut = lightMapParams.rgb * lightColor.rgb;
float4 addToResult = (lightAmbient * (1 - ambientCameraFactor)) + ( lightAmbient * ambientCameraFactor * saturate(dot(normalize(-IN.vsEyeRay), normal)) );
// TODO: This needs to be removed when lightmapping is disabled
@ -303,5 +315,6 @@ float4 main( FarFrustumQuadConnectP IN,
lightColorOut = debugColor;
#endif
return lightinfoCondition( lightColorOut, Sat_NL_Att, specular, addToResult );
float4 colorSample = tex2D( colorBuffer, IN.uv0 );
return AL_DeferredOutput(lightColorOut, colorSample.rgb, matInfo, addToResult, specular, Sat_NL_Att);
}