mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-15 16:44:36 +00:00
Changes to GLSL files for OpenGL
This commit is contained in:
parent
2142d452d4
commit
6aea37b407
98 changed files with 3366 additions and 2686 deletions
|
|
@ -20,16 +20,33 @@
|
|||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
varying vec4 wsEyeDir;
|
||||
varying vec4 ssPos;
|
||||
#include "../../../gl/hlslCompat.glsl"
|
||||
|
||||
in vec4 vPosition;
|
||||
|
||||
#define IN_pos vPosition
|
||||
|
||||
out vec4 wsEyeDir;
|
||||
out vec4 ssPos;
|
||||
out vec4 vsEyeDir;
|
||||
|
||||
#define OUT_hpos gl_Position
|
||||
#define OUT_wsEyeDir wsEyeDir
|
||||
#define OUT_ssPos ssPos
|
||||
#define OUT_vsEyeDir vsEyeDir
|
||||
|
||||
uniform mat4 modelview;
|
||||
uniform mat4 objTrans;
|
||||
uniform mat4 worldViewOnly;
|
||||
uniform vec3 eyePosWorld;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = modelview * gl_Vertex;
|
||||
wsEyeDir = objTrans * gl_Vertex - vec4( eyePosWorld, 0.0 );
|
||||
ssPos = gl_Position;
|
||||
OUT_hpos = tMul( modelview, IN_pos );
|
||||
OUT_wsEyeDir = tMul( objTrans, IN_pos ) - vec4( eyePosWorld, 0.0 );
|
||||
OUT_vsEyeDir = tMul( worldViewOnly, IN_pos );
|
||||
OUT_ssPos = OUT_hpos;
|
||||
|
||||
correctSSP(gl_Position);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,14 +20,15 @@
|
|||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "../../../gl/hlslCompat.glsl"
|
||||
#include "shadergen:/autogenConditioners.h"
|
||||
|
||||
varying vec2 uv0;
|
||||
in vec2 uv0;
|
||||
uniform sampler2D prepassBuffer;
|
||||
uniform sampler1D depthViz;
|
||||
|
||||
void main()
|
||||
{
|
||||
float depth = prepassUncondition( prepassBuffer, uv0 ).w;
|
||||
gl_FragColor = vec4( texture1D( depthViz, depth ).rgb, 1 );
|
||||
OUT_FragColor0 = vec4( texture( depthViz, depth ).rgb, 1.0 );
|
||||
}
|
||||
|
|
@ -20,15 +20,16 @@
|
|||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "../../../gl/hlslCompat.glsl"
|
||||
#include "shadergen:/autogenConditioners.h"
|
||||
|
||||
varying vec2 uv0;
|
||||
in vec2 uv0;
|
||||
uniform sampler2D lightInfoBuffer;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 lightcolor;
|
||||
vec3 lightcolor;
|
||||
float nl_Att, specular;
|
||||
lightinfoUncondition( texture2DLod( lightInfoBuffer, uv0 ), lightcolor, nl_Att, specular );
|
||||
gl_FragColor = vec4( lightcolor, 1.0 );
|
||||
lightinfoUncondition( texture( lightInfoBuffer, uv0 ), lightcolor, nl_Att, specular );
|
||||
OUT_FragColor0 = vec4( lightcolor, 1.0 );
|
||||
}
|
||||
|
|
@ -20,15 +20,16 @@
|
|||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "../../../gl/hlslCompat.glsl"
|
||||
#include "shadergen:/autogenConditioners.h"
|
||||
|
||||
varying vec2 uv0;
|
||||
in vec2 uv0;
|
||||
uniform sampler2D lightInfoBuffer;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 lightcolor;
|
||||
vec3 lightcolor;
|
||||
float nl_Att, specular;
|
||||
lightinfoUncondition( texture2DLod( lightInfoBuffer, uv0 ), lightcolor, nl_Att, specular );
|
||||
gl_FragColor = vec4( specular, specular, specular, 1.0 );
|
||||
lightinfoUncondition( texture( lightInfoBuffer, uv0 ), lightcolor, nl_Att, specular );
|
||||
OUT_FragColor0 = vec4( specular, specular, specular, 1.0 );
|
||||
}
|
||||
|
|
@ -20,14 +20,14 @@
|
|||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "../../../gl/hlslCompat.glsl"
|
||||
#include "shadergen:/autogenConditioners.h"
|
||||
|
||||
|
||||
varying vec2 uv0;
|
||||
uniform sampler2D prepassTex;
|
||||
in vec2 uv0;
|
||||
uniform sampler2D prepassBuffer;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 normal = prepassUncondition( prepassTex, uv0 ).xyz;
|
||||
gl_FragColor = vec4( ( normal + 1.0 ) * 0.5, 1.0 );
|
||||
vec3 normal = prepassUncondition( prepassBuffer, uv0 ).xyz;
|
||||
OUT_FragColor0 = vec4( ( normal + 1.0 ) * 0.5, 1.0 );
|
||||
}
|
||||
|
|
@ -19,13 +19,14 @@
|
|||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
#include "../../../gl/hlslCompat.glsl"
|
||||
|
||||
varying vec2 uv0;
|
||||
in vec2 uv0;
|
||||
uniform sampler2D shadowMap;
|
||||
uniform sampler1D depthViz;
|
||||
|
||||
void main()
|
||||
{
|
||||
float depth = clamp( texture2DLod( shadowMap, uv0, 0 ).r, 0.0, 1.0 );
|
||||
gl_FragColor = vec4( texture1D( depthViz, depth ).rgb, 1.0 );
|
||||
float depth = saturate( texture( shadowMap, uv0 ).r );
|
||||
OUT_FragColor0 = vec4( texture( depthViz, depth ).rgb, 1 );
|
||||
}
|
||||
|
|
@ -24,7 +24,7 @@
|
|||
vec2 getUVFromSSPos( vec3 ssPos, vec4 rtParams )
|
||||
{
|
||||
vec2 outPos = ( ssPos.xy + 1.0 ) / 2.0;
|
||||
outPos.y = 1.0 - outPos.y;
|
||||
outPos = ( outPos * rtParams.zw ) + rtParams.xy;
|
||||
//outPos.y = 1.0 - outPos.y;
|
||||
return outPos;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,24 +20,32 @@
|
|||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "../../../gl/hlslCompat.glsl"
|
||||
#include "farFrustumQuad.glsl"
|
||||
|
||||
uniform vec4 renderTargetParams;
|
||||
|
||||
varying vec4 hpos;
|
||||
varying vec2 uv0;
|
||||
varying vec3 wsEyeRay;
|
||||
in vec4 vPosition;
|
||||
in vec3 vNormal;
|
||||
in vec3 vTangent;
|
||||
in vec2 vTexCoord0;
|
||||
|
||||
uniform vec4 rtParams0;
|
||||
out vec4 hpos;
|
||||
out vec2 uv0;
|
||||
out vec3 wsEyeRay;
|
||||
out vec3 vsEyeRay;
|
||||
|
||||
void main()
|
||||
{
|
||||
// Expand the SS coordinate (stored in uv0)
|
||||
hpos = vec4( gl_MultiTexCoord0.st * 2.0 - 1.0, 1.0, 1.0 );
|
||||
gl_Position = hpos;
|
||||
|
||||
{
|
||||
hpos = vec4( vTexCoord0, 0, 1 );
|
||||
|
||||
// Get a RT-corrected UV from the SS coord
|
||||
uv0 = getUVFromSSPos( hpos.xyz, renderTargetParams );
|
||||
uv0 = getUVFromSSPos( hpos.xyz, rtParams0 );
|
||||
gl_Position = hpos;
|
||||
|
||||
// Interpolators will generate eye ray from far-frustum corners
|
||||
wsEyeRay = gl_Vertex.xyz;
|
||||
// Interpolators will generate eye rays the
|
||||
// from far-frustum corners.
|
||||
wsEyeRay = vTangent;
|
||||
vsEyeRay = vNormal;
|
||||
|
||||
correctSSP(gl_Position);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,34 +21,26 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "../../../gl/hlslCompat.glsl"
|
||||
#include "farFrustumQuad.glsl"
|
||||
#include "lightingUtils.glsl"
|
||||
#include "../../shadowMap/shadowMapIO_GLSL.h"
|
||||
#include "shadergen:/autogenConditioners.h"
|
||||
|
||||
#include "farFrustumQuad.glsl"
|
||||
#include "lightingUtils.glsl"
|
||||
#include "../../../gl/lighting.glsl"
|
||||
#include "../../shadowMap/shadowMapIO_GLSL.h"
|
||||
#include "softShadow.glsl"
|
||||
|
||||
#if TORQUE_SM >= 30
|
||||
in vec4 wsEyeDir;
|
||||
in vec4 ssPos;
|
||||
in vec4 vsEyeDir;
|
||||
|
||||
// Enables high quality soft shadow
|
||||
// filtering for SM3.0 and above.
|
||||
#define SOFTSHADOW_SM3
|
||||
|
||||
#include "softShadow.glsl"
|
||||
|
||||
#else
|
||||
#ifdef USE_COOKIE_TEX
|
||||
|
||||
/// The texture for cookie rendering.
|
||||
uniform samplerCube cookieMap ;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
// I am not sure if we should do this in a better way
|
||||
//#define SHADOW_CUBE
|
||||
//#define SHADOW_PARABOLOID
|
||||
#define SHADOW_DUALPARABOLOID
|
||||
#define SHADOW_DUALPARABOLOID_SINGLE_PASS
|
||||
|
||||
|
||||
#ifdef SHADOW_CUBE
|
||||
|
||||
vec3 decodeShadowCoord( vec3 shadowCoord )
|
||||
|
|
@ -56,39 +48,47 @@
|
|||
return shadowCoord;
|
||||
}
|
||||
|
||||
vec4 shadowSample( samplerCUBE shadowMap, vec3 shadowCoord )
|
||||
vec4 shadowSample( samplerCube shadowMap, vec3 shadowCoord )
|
||||
{
|
||||
return textureCUBE( shadowMap, shadowCoord );
|
||||
return texture( shadowMap, shadowCoord );
|
||||
}
|
||||
|
||||
#elif defined( SHADOW_DUALPARABOLOID )
|
||||
|
||||
#else
|
||||
|
||||
vec3 decodeShadowCoord( vec3 paraVec )
|
||||
{
|
||||
// Swizzle z and y
|
||||
// Flip y and z
|
||||
paraVec = paraVec.xzy;
|
||||
|
||||
#ifdef SHADOW_DUALPARABOLOID_SINGLE_PASS
|
||||
#ifndef SHADOW_PARABOLOID
|
||||
|
||||
bool calcBack = (paraVec.z < 0.0);
|
||||
if(calcBack)
|
||||
if ( calcBack )
|
||||
{
|
||||
paraVec.z = paraVec.z * -1.0;
|
||||
|
||||
#ifdef SHADOW_DUALPARABOLOID
|
||||
paraVec.x = -paraVec.x;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
vec3 shadowCoord;
|
||||
shadowCoord.x = (paraVec.x / (2.0*(1.0 + paraVec.z))) + 0.5;
|
||||
shadowCoord.y = ((paraVec.y / (2.0*(1.0 + paraVec.z))) + 0.5);
|
||||
shadowCoord.x = (paraVec.x / (2*(1 + paraVec.z))) + 0.5;
|
||||
shadowCoord.y = 1-((paraVec.y / (2*(1 + paraVec.z))) + 0.5);
|
||||
shadowCoord.z = 0;
|
||||
|
||||
// adjust the co-ordinate slightly if it is near the extent of the paraboloid
|
||||
// this value was found via experementation
|
||||
shadowCoord.xy *= 0.997;
|
||||
// NOTE: this is wrong, it only biases in one direction, not towards the uv
|
||||
// center ( 0.5 0.5 ).
|
||||
//shadowCoord.xy *= 0.997;
|
||||
|
||||
#ifdef SHADOW_DUALPARABOLOID_SINGLE_PASS
|
||||
#ifndef SHADOW_PARABOLOID
|
||||
|
||||
// If this is the back, offset in the atlas
|
||||
if(calcBack)
|
||||
if ( calcBack )
|
||||
shadowCoord.x += 1.0;
|
||||
|
||||
// Atlasing front and back maps, so scale
|
||||
|
|
@ -99,51 +99,35 @@
|
|||
return shadowCoord;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#error Unknown shadow type!
|
||||
|
||||
#endif
|
||||
|
||||
varying vec4 wsEyeDir;
|
||||
varying vec4 ssPos;
|
||||
|
||||
|
||||
uniform sampler2D prePassBuffer;
|
||||
|
||||
#ifdef SHADOW_CUBE
|
||||
uniform samplerCube shadowMap;
|
||||
uniform samplerCube shadowMap;
|
||||
#else
|
||||
uniform sampler2D shadowMap;
|
||||
#endif
|
||||
#ifdef ACCUMULATE_LUV
|
||||
uniform sampler2D scratchTarget;
|
||||
uniform sampler2D shadowMap;
|
||||
#endif
|
||||
|
||||
uniform vec4 renderTargetParams;
|
||||
uniform vec4 rtParams0;
|
||||
|
||||
uniform vec3 lightPosition;
|
||||
uniform vec4 lightColor;
|
||||
uniform float lightBrightness;
|
||||
uniform float lightRange;
|
||||
uniform float lightBrightness;
|
||||
uniform float lightRange;
|
||||
uniform vec2 lightAttenuation;
|
||||
uniform vec4 lightMapParams;
|
||||
|
||||
uniform vec3 eyePosWorld;
|
||||
uniform vec4 farPlane;
|
||||
uniform float negFarPlaneDotEye;
|
||||
uniform mat3x3 worldToLightProj;
|
||||
|
||||
uniform vec4 vsFarPlane;
|
||||
uniform mat3 viewToLightProj;
|
||||
uniform vec4 lightParams;
|
||||
uniform float shadowSoftness;
|
||||
uniform float constantSpecularPower;
|
||||
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
void main()
|
||||
{
|
||||
// Compute scene UV
|
||||
vec3 ssPosP = ssPos.xyz / ssPos.w;
|
||||
vec2 uvScene = getUVFromSSPos( ssPosP, renderTargetParams );
|
||||
vec3 ssPos = ssPos.xyz / ssPos.w;
|
||||
vec2 uvScene = getUVFromSSPos( ssPos, rtParams0 );
|
||||
|
||||
// Sample/unpack the normal/z data
|
||||
vec4 prepassSample = prepassUncondition( prePassBuffer, uvScene );
|
||||
|
|
@ -151,21 +135,17 @@ void main()
|
|||
float depth = prepassSample.a;
|
||||
|
||||
// Eye ray - Eye -> Pixel
|
||||
vec3 eyeRay = getDistanceVectorToPlane( negFarPlaneDotEye, wsEyeDir.xyz / wsEyeDir.w , farPlane );
|
||||
|
||||
// Get world space pixel position
|
||||
vec3 worldPos = eyePosWorld + eyeRay * depth;
|
||||
vec3 eyeRay = getDistanceVectorToPlane( -vsFarPlane.w, vsEyeDir.xyz, vsFarPlane );
|
||||
vec3 viewSpacePos = eyeRay * depth;
|
||||
|
||||
// Build light vec, get length, clip pixel if needed
|
||||
vec3 lightVec = lightPosition - worldPos;
|
||||
vec3 lightVec = lightPosition - viewSpacePos;
|
||||
float lenLightV = length( lightVec );
|
||||
if ( lightRange - lenLightV < 0.0 )
|
||||
discard;
|
||||
|
||||
clip( lightRange - lenLightV );
|
||||
|
||||
// Get the attenuated falloff.
|
||||
float atten = attenuate( lightColor, lightAttenuation, lenLightV );
|
||||
if ( atten - 1e-6 < 0.0 )
|
||||
discard;
|
||||
clip( atten - 1e-6 );
|
||||
|
||||
// Normalize lightVec
|
||||
lightVec /= lenLightV;
|
||||
|
|
@ -181,61 +161,73 @@ void main()
|
|||
|
||||
#else
|
||||
|
||||
// Convert the light vector into a shadow map
|
||||
// here once instead of in the filtering loop.
|
||||
vec4 shadowCoord = vec4(0.0);
|
||||
#ifdef SHADOW_CUBE
|
||||
shadowCoord.xy = decodeShadowCoord( -lightVec );
|
||||
#else
|
||||
shadowCoord.xy = decodeShadowCoord( worldToLightProj * -lightVec ).xy;
|
||||
#endif
|
||||
|
||||
// Get a linear depth from the light source.
|
||||
float distToLight = lenLightV / lightRange;
|
||||
float distToLight = lenLightV / lightRange;
|
||||
|
||||
#ifdef SOFTSHADOW_SM3
|
||||
#ifdef SHADOW_CUBE
|
||||
|
||||
// TODO: We need to fix shadow cube to handle soft shadows!
|
||||
float occ = texture( shadowMap, tMul( viewToLightProj, -lightVec ) ).r;
|
||||
float shadowed = saturate( exp( lightParams.y * ( occ - distToLight ) ) );
|
||||
|
||||
#else
|
||||
|
||||
vec2 shadowCoord = decodeShadowCoord( tMul( viewToLightProj, -lightVec ) ).xy;
|
||||
|
||||
float shadowed = softShadow_filter( shadowMap,
|
||||
gTapRotationTex,
|
||||
ssPosP.xy,
|
||||
shadowCoord.xy,
|
||||
ssPos.xy,
|
||||
shadowCoord,
|
||||
shadowSoftness,
|
||||
distToLight,
|
||||
nDotL,
|
||||
lightParams.y );
|
||||
|
||||
#else // !SOFTSHADOW_SM3
|
||||
|
||||
// TODO: Implement the SM2 lower quality
|
||||
// shadow filtering method.
|
||||
|
||||
#endif
|
||||
|
||||
#endif // !NO_SHADOW
|
||||
|
||||
|
||||
#ifdef USE_COOKIE_TEX
|
||||
|
||||
// Lookup the cookie sample.
|
||||
vec4 cookie = texture( cookieMap, tMul( viewToLightProj, -lightVec ) );
|
||||
|
||||
// Multiply the light with the cookie tex.
|
||||
lightColor.rgb *= cookie.rgb;
|
||||
|
||||
// Use a maximum channel luminance to attenuate
|
||||
// the lighting else we get specular in the dark
|
||||
// regions of the cookie texture.
|
||||
atten *= max( cookie.r, max( cookie.g, cookie.b ) );
|
||||
|
||||
#endif
|
||||
|
||||
// NOTE: Do not clip on fully shadowed pixels as it would
|
||||
// cause the hardware occlusion query to disable the shadow.
|
||||
|
||||
// Specular term
|
||||
float specular = calcSpecular( lightVec,
|
||||
normal,
|
||||
normalize( -eyeRay ),
|
||||
constantSpecularPower,
|
||||
shadowed * atten * lightBrightness );
|
||||
|
||||
// N.L * Attenuation
|
||||
float Sat_NL_Att = clamp( nDotL * atten * shadowed, 0.0, 1.0 );
|
||||
|
||||
// In LUV color mode we need to blend in the
|
||||
// output from the previous target.
|
||||
vec4 previousPix = vec4(0.0);
|
||||
#ifdef ACCUMULATE_LUV
|
||||
previousPix = texture2DLod( scratchTarget, uvScene, 0 );
|
||||
#endif
|
||||
float specular = AL_CalcSpecular( lightVec,
|
||||
normal,
|
||||
normalize( -eyeRay ) ) * lightBrightness * atten * shadowed;
|
||||
|
||||
// Output
|
||||
gl_FragColor = lightinfoCondition( lightColor.rgb * lightBrightness,
|
||||
Sat_NL_Att,
|
||||
specular,
|
||||
previousPix ) * lightMapParams;
|
||||
float Sat_NL_Att = saturate( nDotL * atten * shadowed ) * lightBrightness;
|
||||
vec3 lightColorOut = lightMapParams.rgb * lightColor.rgb;
|
||||
vec4 addToResult = vec4(0.0);
|
||||
|
||||
// TODO: This needs to be removed when lightmapping is disabled
|
||||
// as its extra work per-pixel on dynamic lit scenes.
|
||||
//
|
||||
// Special lightmapping pass.
|
||||
if ( lightMapParams.a < 0.0 )
|
||||
{
|
||||
// This disables shadows on the backsides of objects.
|
||||
shadowed = nDotL < 0.0f ? 1.0f : shadowed;
|
||||
|
||||
Sat_NL_Att = 1.0f;
|
||||
shadowed = mix( 1.0f, shadowed, atten );
|
||||
lightColorOut = vec3(shadowed);
|
||||
specular *= lightBrightness;
|
||||
addToResult = ( 1.0 - shadowed ) * abs(lightMapParams);
|
||||
}
|
||||
|
||||
OUT_FragColor0 = lightinfoCondition( lightColorOut, Sat_NL_Att, specular, addToResult );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,113 +19,141 @@
|
|||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
#define NUM_TAPS 12
|
||||
|
||||
#define NUM_PRE_TAPS 4
|
||||
|
||||
/// The non-uniform poisson disk used in the
|
||||
/// high quality shadow filtering.
|
||||
vec2 sNonUniformTaps[NUM_TAPS];
|
||||
|
||||
void initNonUniformTaps()
|
||||
|
||||
#if defined( SOFTSHADOW ) && defined( SOFTSHADOW_HIGH_QUALITY )
|
||||
|
||||
#define NUM_PRE_TAPS 4
|
||||
#define NUM_TAPS 12
|
||||
|
||||
/// The non-uniform poisson disk used in the
|
||||
/// high quality shadow filtering.
|
||||
vec2 sNonUniformTaps[NUM_TAPS] = vec2[]
|
||||
(
|
||||
// These first 4 taps are located around the edges
|
||||
// of the disk and are used to predict fully shadowed
|
||||
// or unshadowed areas.
|
||||
vec2( 0.992833, 0.979309 ),
|
||||
vec2( -0.998585, 0.985853 ),
|
||||
vec2( 0.949299, -0.882562 ),
|
||||
vec2( -0.941358, -0.893924 ),
|
||||
|
||||
// The rest of the samples.
|
||||
vec2( 0.545055, -0.589072 ),
|
||||
vec2( 0.346526, 0.385821 ),
|
||||
vec2( -0.260183, 0.334412 ),
|
||||
vec2( 0.248676, -0.679605 ),
|
||||
vec2( -0.569502, -0.390637 ),
|
||||
vec2( -0.614096, 0.212577 ),
|
||||
vec2( -0.259178, 0.876272 ),
|
||||
vec2( 0.649526, 0.864333 )
|
||||
);
|
||||
|
||||
#else
|
||||
|
||||
#define NUM_PRE_TAPS 5
|
||||
|
||||
/// The non-uniform poisson disk used in the
|
||||
/// high quality shadow filtering.
|
||||
vec2 sNonUniformTaps[NUM_PRE_TAPS] = vec2[]
|
||||
(
|
||||
vec2( 0.892833, 0.959309 ),
|
||||
vec2( -0.941358, -0.873924 ),
|
||||
vec2( -0.260183, 0.334412 ),
|
||||
vec2( 0.348676, -0.679605 ),
|
||||
vec2( -0.569502, -0.390637 )
|
||||
);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/// The texture used to do per-pixel pseudorandom
|
||||
/// rotations of the filter taps.
|
||||
uniform sampler2D gTapRotationTex ;
|
||||
|
||||
|
||||
float softShadow_sampleTaps( sampler2D shadowMap,
|
||||
vec2 sinCos,
|
||||
vec2 shadowPos,
|
||||
float filterRadius,
|
||||
float distToLight,
|
||||
float esmFactor,
|
||||
int startTap,
|
||||
int endTap )
|
||||
{
|
||||
// These first 4 taps are located around the edges
|
||||
// of the disk and are used to predict fully shadowed
|
||||
// or unshadowed areas.
|
||||
sNonUniformTaps[0] = vec2( 0.992833, 0.979309 );
|
||||
sNonUniformTaps[1] = vec2( -0.998585, 0.985853 );
|
||||
sNonUniformTaps[2] = vec2( 0.949299, -0.882562 );
|
||||
sNonUniformTaps[3] = vec2( -0.941358, -0.893924 );
|
||||
|
||||
// The rest of the samples.
|
||||
sNonUniformTaps[4] = vec2( 0.545055, -0.589072 );
|
||||
sNonUniformTaps[5] = vec2( 0.346526, 0.385821 );
|
||||
sNonUniformTaps[6] = vec2( -0.260183, 0.334412 );
|
||||
sNonUniformTaps[7] = vec2( 0.248676, -0.679605 );
|
||||
sNonUniformTaps[8] = vec2( -0.569502, -0.390637 );
|
||||
sNonUniformTaps[9] = vec2( -0.014096, 0.012577 );
|
||||
sNonUniformTaps[10] = vec2( -0.259178, 0.876272 );
|
||||
sNonUniformTaps[11] = vec2( 0.649526, 0.664333 );
|
||||
float shadow = 0;
|
||||
|
||||
vec2 tap = vec2(0);
|
||||
for ( int t = startTap; t < endTap; t++ )
|
||||
{
|
||||
tap.x = ( sNonUniformTaps[t].x * sinCos.y - sNonUniformTaps[t].y * sinCos.x ) * filterRadius;
|
||||
tap.y = ( sNonUniformTaps[t].y * sinCos.y + sNonUniformTaps[t].x * sinCos.x ) * filterRadius;
|
||||
float occluder = tex2Dlod( shadowMap, vec4( shadowPos + tap, 0, 0 ) ).r;
|
||||
|
||||
float esm = saturate( exp( esmFactor * ( occluder - distToLight ) ) );
|
||||
shadow += esm / float( endTap - startTap );
|
||||
}
|
||||
|
||||
return shadow;
|
||||
}
|
||||
|
||||
/// The texture used to do per-pixel pseudorandom
|
||||
/// rotations of the filter taps.
|
||||
uniform sampler2D gTapRotationTex;
|
||||
|
||||
|
||||
float softShadow_sampleTaps( sampler2D shadowMap,
|
||||
vec2 sinCos,
|
||||
vec2 shadowPos,
|
||||
float filterRadius,
|
||||
float distToLight,
|
||||
float esmFactor,
|
||||
int startTap,
|
||||
int endTap )
|
||||
{
|
||||
initNonUniformTaps();
|
||||
float shadow = 0.0;
|
||||
|
||||
vec2 tap = vec2(0.0);
|
||||
for ( int t = startTap; t < endTap; t++ )
|
||||
{
|
||||
tap.x = ( sNonUniformTaps[t].x * sinCos.y - sNonUniformTaps[t].y * sinCos.x ) * filterRadius;
|
||||
tap.y = ( sNonUniformTaps[t].y * sinCos.y + sNonUniformTaps[t].x * sinCos.x ) * filterRadius;
|
||||
float occluder = texture2DLod( shadowMap, shadowPos + tap, 0.0 ).r;
|
||||
|
||||
float esm = clamp( exp( esmFactor * ( occluder - distToLight ) ), 0.0, 1.0 );
|
||||
shadow += esm / float( endTap - startTap );
|
||||
}
|
||||
|
||||
return shadow;
|
||||
}
|
||||
|
||||
|
||||
// HACK! HACK! HACK!
|
||||
// We take the noise texture directly as the second parameter to ensure that it
|
||||
// is the "last used" sampler, and thus doesn't collide with the prepass buffer
|
||||
// or shadow map. If we use gTapRotationTex directly here, then it is the first
|
||||
// used sampler and will collide with the prepass buffer.
|
||||
float softShadow_filter( sampler2D shadowMap,
|
||||
sampler2D noiseTexture,
|
||||
vec2 vpos,
|
||||
vec2 shadowPos,
|
||||
float filterRadius,
|
||||
float distToLight,
|
||||
float dotNL,
|
||||
float esmFactor )
|
||||
{
|
||||
// Lookup the random rotation for this screen pixel.
|
||||
vec2 sinCos = ( texture2DLod( noiseTexture, vpos * 16.0, 0.0 ).rg - 0.5 ) * 2.0;
|
||||
|
||||
// Do the prediction taps first.
|
||||
float shadow = softShadow_sampleTaps( shadowMap,
|
||||
sinCos,
|
||||
shadowPos,
|
||||
filterRadius,
|
||||
distToLight,
|
||||
esmFactor,
|
||||
0,
|
||||
NUM_PRE_TAPS );
|
||||
|
||||
// Only do the expensive filtering if we're really
|
||||
// in a partially shadowed area.
|
||||
if ( shadow * ( 1.0 - shadow ) * max( dotNL, 0.0 ) > 0.06 )
|
||||
{
|
||||
shadow += softShadow_sampleTaps( shadowMap,
|
||||
sinCos,
|
||||
shadowPos,
|
||||
filterRadius,
|
||||
distToLight,
|
||||
esmFactor,
|
||||
NUM_PRE_TAPS,
|
||||
NUM_TAPS );
|
||||
|
||||
// This averages the taps above with the results
|
||||
// of the prediction samples.
|
||||
shadow *= 0.5;
|
||||
}
|
||||
|
||||
return shadow;
|
||||
}
|
||||
|
||||
|
||||
float softShadow_filter( sampler2D shadowMap,
|
||||
vec2 vpos,
|
||||
vec2 shadowPos,
|
||||
float filterRadius,
|
||||
float distToLight,
|
||||
float dotNL,
|
||||
float esmFactor )
|
||||
{
|
||||
#ifndef SOFTSHADOW
|
||||
|
||||
// If softshadow is undefined then we skip any complex
|
||||
// filtering... just do a single sample ESM.
|
||||
|
||||
float occluder = tex2Dlod( shadowMap, vec4( shadowPos, 0, 0 ) ).r;
|
||||
float shadow = saturate( exp( esmFactor * ( occluder - distToLight ) ) );
|
||||
|
||||
#else
|
||||
|
||||
// Lookup the random rotation for this screen pixel.
|
||||
vec2 sinCos = ( tex2Dlod( gTapRotationTex, vec4( vpos * 16, 0, 0 ) ).rg - 0.5 ) * 2;
|
||||
|
||||
// Do the prediction taps first.
|
||||
float shadow = softShadow_sampleTaps( shadowMap,
|
||||
sinCos,
|
||||
shadowPos,
|
||||
filterRadius,
|
||||
distToLight,
|
||||
esmFactor,
|
||||
0,
|
||||
NUM_PRE_TAPS );
|
||||
|
||||
// We live with only the pretap results if we don't
|
||||
// have high quality shadow filtering enabled.
|
||||
#ifdef SOFTSHADOW_HIGH_QUALITY
|
||||
|
||||
// Only do the expensive filtering if we're really
|
||||
// in a partially shadowed area.
|
||||
if ( shadow * ( 1.0 - shadow ) * max( dotNL, 0 ) > 0.06 )
|
||||
{
|
||||
shadow += softShadow_sampleTaps( shadowMap,
|
||||
sinCos,
|
||||
shadowPos,
|
||||
filterRadius,
|
||||
distToLight,
|
||||
esmFactor,
|
||||
NUM_PRE_TAPS,
|
||||
NUM_TAPS );
|
||||
|
||||
// This averages the taps above with the results
|
||||
// of the prediction samples.
|
||||
shadow *= 0.5;
|
||||
}
|
||||
|
||||
#endif // SOFTSHADOW_HIGH_QUALITY
|
||||
|
||||
#endif // SOFTSHADOW
|
||||
|
||||
return shadow;
|
||||
}
|
||||
|
|
@ -25,58 +25,49 @@
|
|||
#include "lightingUtils.glsl"
|
||||
#include "../../shadowMap/shadowMapIO_GLSL.h"
|
||||
#include "shadergen:/autogenConditioners.h"
|
||||
#include "softShadow.glsl"
|
||||
#include "../../../gl/lighting.glsl"
|
||||
|
||||
in vec4 wsEyeDir;
|
||||
in vec4 ssPos;
|
||||
in vec4 vsEyeDir;
|
||||
|
||||
#if TORQUE_SM >= 30
|
||||
#define IN_wsEyeDir wsEyeDir
|
||||
#define IN_ssPos ssPos
|
||||
#define IN_vsEyeDir vsEyeDir
|
||||
|
||||
// Enables high quality soft shadow
|
||||
// filtering for SM3.0 and above.
|
||||
#define SOFTSHADOW_SM3
|
||||
|
||||
#include "softShadow.glsl"
|
||||
|
||||
#else
|
||||
#ifdef USE_COOKIE_TEX
|
||||
|
||||
/// The texture for cookie rendering.
|
||||
uniform sampler2D cookieMap;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
varying vec4 ssPos;
|
||||
varying vec4 wsEyeDir;
|
||||
|
||||
|
||||
uniform sampler2D prePassBuffer;
|
||||
uniform sampler2D shadowMap;
|
||||
#ifdef ACCUMULATE_LUV
|
||||
uniform sampler2D scratchTarget;
|
||||
#endif
|
||||
|
||||
uniform vec4 renderTargetParams;
|
||||
uniform vec4 rtParams0;
|
||||
|
||||
uniform vec3 lightPosition;
|
||||
uniform vec4 lightColor;
|
||||
uniform float lightBrightness;
|
||||
uniform float lightRange;
|
||||
uniform float lightBrightness;
|
||||
uniform float lightRange;
|
||||
uniform vec2 lightAttenuation;
|
||||
uniform vec3 lightDirection;
|
||||
uniform vec4 lightSpotParams;
|
||||
uniform vec4 lightMapParams;
|
||||
|
||||
uniform vec3 eyePosWorld;
|
||||
uniform vec4 farPlane;
|
||||
uniform float negFarPlaneDotEye;
|
||||
uniform mat4x4 worldToLightProj;
|
||||
uniform vec4 vsFarPlane;
|
||||
uniform mat4 viewToLightProj;
|
||||
|
||||
uniform vec4 lightParams;
|
||||
uniform float shadowSoftness;
|
||||
uniform float constantSpecularPower;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
{
|
||||
// Compute scene UV
|
||||
vec3 ssPosP = ssPos.xyz / ssPos.w;
|
||||
vec2 uvScene = getUVFromSSPos( ssPosP, renderTargetParams );
|
||||
vec3 ssPos = IN_ssPos.xyz / IN_ssPos.w;
|
||||
vec2 uvScene = getUVFromSSPos( ssPos, rtParams0 );
|
||||
|
||||
// Sample/unpack the normal/z data
|
||||
vec4 prepassSample = prepassUncondition( prePassBuffer, uvScene );
|
||||
|
|
@ -84,85 +75,92 @@ void main()
|
|||
float depth = prepassSample.a;
|
||||
|
||||
// Eye ray - Eye -> Pixel
|
||||
vec3 eyeRay = getDistanceVectorToPlane( negFarPlaneDotEye, wsEyeDir.xyz / wsEyeDir.w , farPlane );
|
||||
|
||||
// Get world space pixel position
|
||||
vec3 worldPos = eyePosWorld + eyeRay * depth;
|
||||
vec3 eyeRay = getDistanceVectorToPlane( -vsFarPlane.w, IN_vsEyeDir.xyz, vsFarPlane );
|
||||
vec3 viewSpacePos = eyeRay * depth;
|
||||
|
||||
// Build light vec, get length, clip pixel if needed
|
||||
vec3 lightToPxlVec = worldPos - lightPosition;
|
||||
vec3 lightToPxlVec = viewSpacePos - lightPosition;
|
||||
float lenLightV = length( lightToPxlVec );
|
||||
lightToPxlVec /= lenLightV;
|
||||
|
||||
//lightDirection = float3( -lightDirection.xy, lightDirection.z ); //float3( 0, 0, -1 );
|
||||
//lightDirection = vec3( -lightDirection.xy, lightDirection.z ); //vec3( 0, 0, -1 );
|
||||
float cosAlpha = dot( lightDirection, lightToPxlVec );
|
||||
if ( cosAlpha - lightSpotParams.x < 0.0 ) discard;
|
||||
if ( lightRange - lenLightV < 0.0 ) discard;
|
||||
clip( cosAlpha - lightSpotParams.x );
|
||||
clip( lightRange - lenLightV );
|
||||
|
||||
float atten = attenuate( lightColor, lightAttenuation, lenLightV );
|
||||
atten *= ( cosAlpha - lightSpotParams.x ) / lightSpotParams.y;
|
||||
if ( atten - 1e-6 < 0.0 ) discard;
|
||||
clip( atten - 1e-6 );
|
||||
atten = saturate( atten );
|
||||
|
||||
float nDotL = dot( normal, -lightToPxlVec );
|
||||
|
||||
// Get the shadow texture coordinate
|
||||
vec4 pxlPosLightProj = tMul( viewToLightProj, vec4( viewSpacePos, 1 ) );
|
||||
vec2 shadowCoord = ( ( pxlPosLightProj.xy / pxlPosLightProj.w ) * 0.5 ) + vec2( 0.5, 0.5 );
|
||||
shadowCoord.y = 1.0f - shadowCoord.y;
|
||||
|
||||
#ifdef NO_SHADOW
|
||||
|
||||
float shadowed = 1.0;
|
||||
|
||||
#else
|
||||
|
||||
// Find Shadow coordinate
|
||||
vec4 pxlPosLightProj = vec4( worldToLightProj * vec4( worldPos, 1.0 ) );
|
||||
vec2 shadowCoord = ( ( pxlPosLightProj.xy / pxlPosLightProj.w ) * 0.5 ) + vec2( 0.5, 0.5 );
|
||||
|
||||
// Get a linear depth from the light source.
|
||||
float distToLight = pxlPosLightProj.z / lightRange;
|
||||
|
||||
#ifdef SOFTSHADOW_SM3
|
||||
|
||||
float shadowed = softShadow_filter( shadowMap,
|
||||
gTapRotationTex,
|
||||
ssPosP.xy,
|
||||
shadowCoord,
|
||||
shadowSoftness,
|
||||
distToLight,
|
||||
nDotL,
|
||||
lightParams.y );
|
||||
|
||||
#else // !SOFTSHADOW_SM3
|
||||
|
||||
// Simple exponential shadow map.
|
||||
float occluder = decodeShadowMap( texture2DLod( shadowMap, shadowCoord, 0.0 ) );
|
||||
float esmFactor = lightParams.y;
|
||||
float shadowed = clamp( exp( esmFactor * ( occluder - distToLight ) ), 0.0, 1.0 );
|
||||
|
||||
#endif
|
||||
float shadowed = softShadow_filter( shadowMap,
|
||||
ssPos.xy,
|
||||
shadowCoord,
|
||||
shadowSoftness,
|
||||
distToLight,
|
||||
nDotL,
|
||||
lightParams.y );
|
||||
|
||||
#endif // !NO_SHADOW
|
||||
|
||||
|
||||
#ifdef USE_COOKIE_TEX
|
||||
|
||||
// Lookup the cookie sample.
|
||||
vec4 cookie = texture( cookieMap, shadowCoord );
|
||||
|
||||
// Multiply the light with the cookie tex.
|
||||
lightColor.rgb *= cookie.rgb;
|
||||
|
||||
// Use a maximum channel luminance to attenuate
|
||||
// the lighting else we get specular in the dark
|
||||
// regions of the cookie texture.
|
||||
atten *= max( cookie.r, max( cookie.g, cookie.b ) );
|
||||
|
||||
#endif
|
||||
|
||||
// NOTE: Do not clip on fully shadowed pixels as it would
|
||||
// cause the hardware occlusion query to disable the shadow.
|
||||
|
||||
// Specular term
|
||||
float specular = calcSpecular( -lightToPxlVec,
|
||||
normal,
|
||||
normalize( -eyeRay ),
|
||||
constantSpecularPower,
|
||||
shadowed * atten * lightBrightness );
|
||||
|
||||
// N.L * Attenuation
|
||||
float Sat_NL_Att = clamp( nDotL * atten * shadowed, 0.0, 1.0 );
|
||||
|
||||
// In LUV color mode we need to blend in the
|
||||
// output from the previous target.
|
||||
vec4 previousPix = vec4(0.0);
|
||||
#ifdef ACCUMULATE_LUV
|
||||
previousPix = texture2DLod( scratchTarget, uvScene, 0.0 );
|
||||
#endif
|
||||
float specular = AL_CalcSpecular( -lightToPxlVec,
|
||||
normal,
|
||||
normalize( -eyeRay ) ) * lightBrightness * atten * shadowed;
|
||||
|
||||
// Output
|
||||
gl_FragColor = lightinfoCondition( lightColor.rgb * lightBrightness,
|
||||
Sat_NL_Att,
|
||||
specular,
|
||||
previousPix ) * lightMapParams;
|
||||
float Sat_NL_Att = saturate( nDotL * atten * shadowed ) * lightBrightness;
|
||||
vec3 lightColorOut = lightMapParams.rgb * lightColor.rgb;
|
||||
vec4 addToResult = vec4(0.0);
|
||||
|
||||
// TODO: This needs to be removed when lightmapping is disabled
|
||||
// as its extra work per-pixel on dynamic lit scenes.
|
||||
//
|
||||
// Special lightmapping pass.
|
||||
if ( lightMapParams.a < 0.0 )
|
||||
{
|
||||
// This disables shadows on the backsides of objects.
|
||||
shadowed = nDotL < 0.0f ? 1.0f : shadowed;
|
||||
|
||||
Sat_NL_Att = 1.0f;
|
||||
shadowed = mix( 1.0f, shadowed, atten );
|
||||
lightColorOut = vec3(shadowed);
|
||||
specular *= lightBrightness;
|
||||
addToResult = ( 1.0 - shadowed ) * abs(lightMapParams);
|
||||
}
|
||||
|
||||
OUT_FragColor0 = lightinfoCondition( lightColorOut, Sat_NL_Att, specular, addToResult );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,40 +22,32 @@
|
|||
|
||||
#include "../../../gl/hlslCompat.glsl"
|
||||
#include "shadergen:/autogenConditioners.h"
|
||||
#include "farFrustumQuad.glsl"
|
||||
#include "../../../gl/torque.glsl"
|
||||
#include "../../../gl/lighting.glsl"
|
||||
#include "lightingUtils.glsl"
|
||||
#include "../../shadowMap/shadowMapIO_GLSL.h"
|
||||
#include "softShadow.glsl"
|
||||
|
||||
varying vec2 uv0;
|
||||
varying vec3 wsEyeRay;
|
||||
in vec4 hpos;
|
||||
in vec2 uv0;
|
||||
in vec3 wsEyeRay;
|
||||
in vec3 vsEyeRay;
|
||||
|
||||
uniform sampler2D prePassBuffer;
|
||||
uniform sampler2D ShadowMap;
|
||||
uniform sampler2D ShadowMap ;
|
||||
|
||||
#if TORQUE_SM >= 30
|
||||
|
||||
// Enables high quality soft shadow
|
||||
// filtering for SM3.0 and above.
|
||||
#define SOFTSHADOW_SM3
|
||||
|
||||
#include "softShadow.glsl"
|
||||
|
||||
#else
|
||||
|
||||
|
||||
|
||||
#ifdef USE_SSAO_MASK
|
||||
uniform sampler2D ssaoMask ;
|
||||
uniform vec4 rtParams2;
|
||||
#endif
|
||||
|
||||
|
||||
uniform sampler2D prePassBuffer;
|
||||
uniform vec3 lightDirection;
|
||||
uniform vec4 lightColor;
|
||||
uniform float lightBrightness;
|
||||
uniform vec4 lightAmbient;
|
||||
uniform vec4 lightTrilight;
|
||||
|
||||
uniform vec3 eyePosWorld;
|
||||
|
||||
uniform mat4 worldToLightProj;
|
||||
uniform vec4 splitDistStart;
|
||||
uniform vec4 splitDistEnd;
|
||||
uniform float lightBrightness;
|
||||
uniform vec4 lightAmbient;
|
||||
uniform vec3 eyePosWorld;
|
||||
uniform mat4x4 worldToLightProj;
|
||||
uniform vec4 scaleX;
|
||||
uniform vec4 scaleY;
|
||||
uniform vec4 offsetX;
|
||||
|
|
@ -65,16 +57,12 @@ uniform vec4 atlasYOffset;
|
|||
uniform vec2 atlasScale;
|
||||
uniform vec4 zNearFarInvNearFar;
|
||||
uniform vec4 lightMapParams;
|
||||
|
||||
uniform float constantSpecularPower;
|
||||
uniform vec2 fadeStartLength;
|
||||
uniform vec4 farPlaneScalePSSM;
|
||||
uniform vec4 splitFade;
|
||||
uniform vec4 overDarkPSSM;
|
||||
uniform float shadowSoftness;
|
||||
|
||||
|
||||
void main()
|
||||
void main()
|
||||
{
|
||||
// Sample/unpack the normal/z data
|
||||
vec4 prepassSample = prepassUncondition( prePassBuffer, uv0 );
|
||||
|
|
@ -83,148 +71,162 @@ void main()
|
|||
|
||||
// Use eye ray to get ws pos
|
||||
vec4 worldPos = vec4(eyePosWorld + wsEyeRay * depth, 1.0f);
|
||||
|
||||
|
||||
// Get the light attenuation.
|
||||
float dotNL = dot(-lightDirection, normal);
|
||||
|
||||
#ifdef PSSM_DEBUG_RENDER
|
||||
vec3 debugColor = vec3(0);
|
||||
#endif
|
||||
|
||||
#ifdef NO_SHADOW
|
||||
|
||||
// Fully unshadowed.
|
||||
float shadowed = 1.0;
|
||||
|
||||
#ifdef PSSM_DEBUG_RENDER
|
||||
debugColor = vec3(1.0);
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
|
||||
// Compute shadow map coordinate
|
||||
vec4 pxlPosLightProj = worldToLightProj * worldPos;
|
||||
vec4 pxlPosLightProj = tMul(worldToLightProj, worldPos);
|
||||
vec2 baseShadowCoord = pxlPosLightProj.xy / pxlPosLightProj.w;
|
||||
|
||||
float distOffset = 0.0;
|
||||
float shadowed = 0.0;
|
||||
float fadeAmt = 0.0;
|
||||
vec4 zDist = vec4(zNearFarInvNearFar.x + zNearFarInvNearFar.y * depth);
|
||||
|
||||
// Calculate things dependant on the shadowmap split
|
||||
for ( int i = 0; i < 2; i++ )
|
||||
{
|
||||
float zDistSplit = zDist.x + distOffset;
|
||||
vec4 mask0;
|
||||
mask0.x = float(zDistSplit >= splitDistStart.x);
|
||||
mask0.y = float(zDistSplit >= splitDistStart.y);
|
||||
mask0.z = float(zDistSplit >= splitDistStart.z);
|
||||
mask0.w = float(zDistSplit >= splitDistStart.w);
|
||||
|
||||
// Distance to light, in shadowmap space
|
||||
float distToLight = pxlPosLightProj.z / pxlPosLightProj.w;
|
||||
|
||||
vec4 mask1;
|
||||
mask1.x = float(zDistSplit < splitDistEnd.x);
|
||||
mask1.y = float(zDistSplit < splitDistEnd.y);
|
||||
mask1.z = float(zDistSplit < splitDistEnd.z);
|
||||
mask1.w = float(zDistSplit < splitDistEnd.w);
|
||||
// Figure out which split to sample from. Basically, we compute the shadowmap sample coord
|
||||
// for all of the splits and then check if its valid.
|
||||
vec4 shadowCoordX = vec4( baseShadowCoord.x );
|
||||
vec4 shadowCoordY = vec4( baseShadowCoord.y );
|
||||
vec4 farPlaneDists = vec4( distToLight );
|
||||
shadowCoordX *= scaleX;
|
||||
shadowCoordY *= scaleY;
|
||||
shadowCoordX += offsetX;
|
||||
shadowCoordY += offsetY;
|
||||
farPlaneDists *= farPlaneScalePSSM;
|
||||
|
||||
// If the shadow sample is within -1..1 and the distance
|
||||
// to the light for this pixel is less than the far plane
|
||||
// of the split, use it.
|
||||
vec4 finalMask;
|
||||
if ( shadowCoordX.x > -0.99 && shadowCoordX.x < 0.99 &&
|
||||
shadowCoordY.x > -0.99 && shadowCoordY.x < 0.99 &&
|
||||
farPlaneDists.x < 1.0 )
|
||||
finalMask = vec4(1, 0, 0, 0);
|
||||
|
||||
else if ( shadowCoordX.y > -0.99 && shadowCoordX.y < 0.99 &&
|
||||
shadowCoordY.y > -0.99 && shadowCoordY.y < 0.99 &&
|
||||
farPlaneDists.y < 1.0 )
|
||||
finalMask = vec4(0, 1, 0, 0);
|
||||
|
||||
else if ( shadowCoordX.z > -0.99 && shadowCoordX.z < 0.99 &&
|
||||
shadowCoordY.z > -0.99 && shadowCoordY.z < 0.99 &&
|
||||
farPlaneDists.z < 1.0 )
|
||||
finalMask = vec4(0, 0, 1, 0);
|
||||
|
||||
vec4 finalMask = mask0 * mask1;
|
||||
else
|
||||
finalMask = vec4(0, 0, 0, 1);
|
||||
|
||||
float splitFadeDist = dot( finalMask, splitFade );
|
||||
|
||||
vec2 finalScale;
|
||||
finalScale.x = dot(finalMask, scaleX);
|
||||
finalScale.y = dot(finalMask, scaleY);
|
||||
#ifdef PSSM_DEBUG_RENDER
|
||||
if ( finalMask.x > 0 )
|
||||
debugColor += vec3( 1, 0, 0 );
|
||||
else if ( finalMask.y > 0 )
|
||||
debugColor += vec3( 0, 1, 0 );
|
||||
else if ( finalMask.z > 0 )
|
||||
debugColor += vec3( 0, 0, 1 );
|
||||
else if ( finalMask.w > 0 )
|
||||
debugColor += vec3( 1, 1, 0 );
|
||||
#endif
|
||||
|
||||
vec2 finalOffset;
|
||||
finalOffset.x = dot(finalMask, offsetX);
|
||||
finalOffset.y = dot(finalMask, offsetY);
|
||||
|
||||
vec2 shadowCoord;
|
||||
shadowCoord = baseShadowCoord * finalScale;
|
||||
shadowCoord += finalOffset;
|
||||
// Here we know what split we're sampling from, so recompute the texcoord location
|
||||
// Yes, we could just use the result from above, but doing it this way actually saves
|
||||
// shader instructions.
|
||||
vec2 finalScale;
|
||||
finalScale.x = dot(finalMask, scaleX);
|
||||
finalScale.y = dot(finalMask, scaleY);
|
||||
|
||||
// Convert to texcoord space
|
||||
shadowCoord = 0.5 * shadowCoord + vec2(0.5, 0.5);
|
||||
//shadowCoord.y = 1.0f - shadowCoord.y;
|
||||
vec2 finalOffset;
|
||||
finalOffset.x = dot(finalMask, offsetX);
|
||||
finalOffset.y = dot(finalMask, offsetY);
|
||||
|
||||
// Move around inside of atlas
|
||||
vec2 aOffset;
|
||||
aOffset.x = dot(finalMask, atlasXOffset);
|
||||
aOffset.y = dot(finalMask, atlasYOffset);
|
||||
vec2 shadowCoord;
|
||||
shadowCoord = baseShadowCoord * finalScale;
|
||||
shadowCoord += finalOffset;
|
||||
|
||||
shadowCoord *= atlasScale;
|
||||
shadowCoord += aOffset;
|
||||
|
||||
// Distance to light, in shadowmap space
|
||||
float distToLight = pxlPosLightProj.z / pxlPosLightProj.w;
|
||||
|
||||
// Each split has a different far plane, take this into account.
|
||||
float farPlaneScale = dot( farPlaneScalePSSM, finalMask );
|
||||
distToLight *= farPlaneScale;
|
||||
|
||||
#ifdef SOFTSHADOW_SM3
|
||||
// Convert to texcoord space
|
||||
shadowCoord = 0.5 * shadowCoord + vec2(0.5, 0.5);
|
||||
shadowCoord.y = 1.0f - shadowCoord.y;
|
||||
|
||||
float esmShadow = softShadow_filter( ShadowMap,
|
||||
gTapRotationTex,
|
||||
uv0.xy,
|
||||
shadowCoord,
|
||||
farPlaneScale * shadowSoftness,
|
||||
distToLight,
|
||||
dotNL,
|
||||
dot( finalMask, overDarkPSSM ) );
|
||||
|
||||
#else // !SOFTSHADOW_SM3
|
||||
// Move around inside of atlas
|
||||
vec2 aOffset;
|
||||
aOffset.x = dot(finalMask, atlasXOffset);
|
||||
aOffset.y = dot(finalMask, atlasYOffset);
|
||||
|
||||
float occluder = decodeShadowMap( texture2DLod( ShadowMap, shadowCoord, 0.0 ) );
|
||||
float overDark = dot( finalMask, overDarkPSSM );
|
||||
float esmShadow = saturate( exp( esmFactor * ( occluder - distToLight ) ) );
|
||||
|
||||
#endif
|
||||
|
||||
if ( i == 0 )
|
||||
{
|
||||
float endDist = dot(splitDistEnd, finalMask);
|
||||
fadeAmt = smoothstep(endDist - splitFadeDist, endDist, zDist).x;
|
||||
shadowed = esmShadow * ( 1.0 - fadeAmt );
|
||||
}
|
||||
else
|
||||
shadowed += esmShadow * fadeAmt;
|
||||
|
||||
distOffset += splitFadeDist;
|
||||
}
|
||||
shadowCoord *= atlasScale;
|
||||
shadowCoord += aOffset;
|
||||
|
||||
// Each split has a different far plane, take this into account.
|
||||
float farPlaneScale = dot( farPlaneScalePSSM, finalMask );
|
||||
distToLight *= farPlaneScale;
|
||||
|
||||
float shadowed = softShadow_filter( ShadowMap,
|
||||
uv0.xy,
|
||||
shadowCoord,
|
||||
farPlaneScale * shadowSoftness,
|
||||
distToLight,
|
||||
dotNL,
|
||||
dot( finalMask, overDarkPSSM ) );
|
||||
|
||||
// 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;
|
||||
shadowed = mix( shadowed, 1.0, clamp( fadeOutAmt, 0.0, 1.0 ) );
|
||||
shadowed = mix( shadowed, 1.0, saturate( fadeOutAmt ) );
|
||||
|
||||
#ifdef PSSM_DEBUG_RENDER
|
||||
if ( fadeOutAmt > 1.0 )
|
||||
debugColor = vec3(1.0);
|
||||
#endif
|
||||
|
||||
#endif // !NO_SHADOW
|
||||
|
||||
// Calc lighting coefficents
|
||||
float specular = calcSpecular( -lightDirection,
|
||||
normal,
|
||||
normalize(-wsEyeRay),
|
||||
constantSpecularPower,
|
||||
shadowed * lightBrightness );
|
||||
|
||||
float Sat_NL_Att = clamp(dotNL, 0.0, 1.0) * shadowed;
|
||||
|
||||
// Trilight, described by Tom Forsyth
|
||||
// http://home.comcast.net/~tom_forsyth/papers/trilight/trilight.html
|
||||
#ifdef ACCUMULATE_LUV
|
||||
|
||||
// In LUV multiply in the brightness of the light color (normaly done in the attenuate function)
|
||||
Sat_NL_Att *= lightColor.a;
|
||||
// Specular term
|
||||
float specular = AL_CalcSpecular( -lightDirection,
|
||||
normal,
|
||||
normalize(-vsEyeRay) ) * lightBrightness * shadowed;
|
||||
|
||||
vec4 ambientBlend = lightAmbient;
|
||||
ambientBlend.b *= clamp(-dotNL, 0.0, 1.0);
|
||||
|
||||
vec3 trilight = lightTrilight.rgb;
|
||||
trilight.b *= clamp(1.0 - abs(dotNL), 0.0, 1.0);
|
||||
|
||||
ambientBlend.rg = mix(ambientBlend.rg, trilight.rg, clamp(0.5 * trilight.b / lightAmbient.b, 0.0, 1.0));
|
||||
ambientBlend.b += trilight.b;
|
||||
float Sat_NL_Att = saturate( dotNL * shadowed ) * lightBrightness;
|
||||
vec3 lightColorOut = lightMapParams.rgb * lightColor.rgb;
|
||||
vec4 addToResult = lightAmbient;
|
||||
|
||||
#else
|
||||
// TODO: This needs to be removed when lightmapping is disabled
|
||||
// as its extra work per-pixel on dynamic lit scenes.
|
||||
//
|
||||
// Special lightmapping pass.
|
||||
if ( lightMapParams.a < 0.0 )
|
||||
{
|
||||
// This disables shadows on the backsides of objects.
|
||||
shadowed = dotNL < 0.0f ? 1.0f : shadowed;
|
||||
|
||||
// RGB
|
||||
// TODO: Trilight seems broken... it does lighting in shadows!
|
||||
//vec4 ambientBlend = vec4(lightTrilight.rgb * clamp(1.0 - abs(dotNL), 0.0, 1.0) + lightAmbient.rgb * clamp(-dotNL, 0.0, 1.0), 0.0);
|
||||
vec4 ambientBlend = vec4(lightAmbient.rgb, 0.0);
|
||||
Sat_NL_Att = 1.0f;
|
||||
lightColorOut = vec3(shadowed);
|
||||
specular *= lightBrightness;
|
||||
addToResult = ( 1.0 - shadowed ) * abs(lightMapParams);
|
||||
}
|
||||
|
||||
#endif
|
||||
// Sample the AO texture.
|
||||
#ifdef USE_SSAO_MASK
|
||||
float ao = 1.0 - texture( ssaoMask, viewportCoordToRenderTarget( uv0.xy, rtParams2 ) ).r;
|
||||
addToResult *= ao;
|
||||
#endif
|
||||
|
||||
#ifdef PSSM_DEBUG_RENDER
|
||||
lightColorOut = debugColor;
|
||||
#endif
|
||||
|
||||
OUT_FragColor0 = lightinfoCondition( lightColorOut, Sat_NL_Att, specular, addToResult );
|
||||
|
||||
// Output
|
||||
gl_FragColor = lightinfoCondition( lightColor.rgb * lightBrightness, Sat_NL_Att, specular, ambientBlend) * lightMapParams;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,35 +20,27 @@
|
|||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "../../../gl/hlslCompat.glsl"
|
||||
|
||||
uniform sampler2D diffuseMap;
|
||||
|
||||
varying vec2 uv;
|
||||
in vec2 uv;
|
||||
|
||||
uniform vec2 oneOverTargetSize;
|
||||
|
||||
const float offset[3] = float[]( 0.0, 1.3846153846, 3.2307692308 );
|
||||
const float weight[3] = float[]( 0.2270270270, 0.3162162162, 0.0702702703 );
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 sNonUniformTaps[8];
|
||||
|
||||
sNonUniformTaps[0] = vec2(0.992833, 0.979309);
|
||||
sNonUniformTaps[1] = vec2(-0.998585, 0.985853);
|
||||
sNonUniformTaps[2] = vec2(0.949299, -0.882562);
|
||||
sNonUniformTaps[3] = vec2(-0.941358, -0.893924);
|
||||
sNonUniformTaps[4] = vec2(0.545055, -0.589072);
|
||||
sNonUniformTaps[5] = vec2(0.346526, 0.385821);
|
||||
sNonUniformTaps[6] = vec2(-0.260183, 0.334412);
|
||||
sNonUniformTaps[7] = vec2(0.248676, -0.679605);
|
||||
vec4 OUT = texture( diffuseMap, uv ) * weight[0];
|
||||
|
||||
gl_FragColor = vec4(0.0);
|
||||
|
||||
vec2 texScale = vec2(1.0);
|
||||
|
||||
for ( int i=0; i < 4; i++ )
|
||||
for ( int i=1; i < 3; i++ )
|
||||
{
|
||||
vec2 offset = (oneOverTargetSize * texScale) * sNonUniformTaps[i];
|
||||
gl_FragColor += texture2D( diffuseMap, uv + offset );
|
||||
vec2 _sample = (BLUR_DIR * offset[i]) * oneOverTargetSize;
|
||||
OUT += texture( diffuseMap, uv + _sample ) * weight[i];
|
||||
OUT += texture( diffuseMap, uv - _sample ) * weight[i];
|
||||
}
|
||||
|
||||
gl_FragColor /= vec4(4.0);
|
||||
gl_FragColor.rgb = vec3(0.0);
|
||||
|
||||
OUT_FragColor0 = OUT;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,13 +22,16 @@
|
|||
|
||||
#include "../../../../../../shaders/common/gl/torque.glsl"
|
||||
|
||||
uniform vec2 oneOverTargetSize;
|
||||
in vec4 vPosition;
|
||||
in vec2 vTexCoord0;
|
||||
|
||||
uniform vec4 rtParams0;
|
||||
|
||||
varying vec2 uv;
|
||||
out vec2 uv;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = gl_Vertex;
|
||||
uv = viewportCoordToRenderTarget( gl_MultiTexCoord0.st, rtParams0 );
|
||||
gl_Position = vPosition;
|
||||
uv = viewportCoordToRenderTarget( vTexCoord0.st, rtParams0 );
|
||||
gl_Position.y *= -1; //correct ssp
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ uniform sampler2D diffuseMap0;
|
|||
uniform float texSize;
|
||||
uniform vec2 blurDimension;
|
||||
|
||||
varying vec2 tex0;
|
||||
in vec2 tex0;
|
||||
|
||||
void main()
|
||||
{
|
||||
|
|
@ -40,8 +40,8 @@ void main()
|
|||
vec4 accum = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
for(int i = 0; i < int(blurSamples); i++)
|
||||
{
|
||||
accum += texture2D(diffuseMap0, BaseTexCoord + float(i) * SampleOffset);
|
||||
accum += texture(diffuseMap0, BaseTexCoord + float(i) * SampleOffset);
|
||||
}
|
||||
accum /= blurSamples;
|
||||
gl_FragColor = accum;
|
||||
OUT_FragColor0 = accum;
|
||||
}
|
||||
|
|
@ -20,12 +20,15 @@
|
|||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
in vec4 vPosition;
|
||||
in vec2 vTexCoord0;
|
||||
|
||||
uniform mat4 modelview;
|
||||
|
||||
varying vec2 tex0;
|
||||
out vec2 tex0;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = modelview * gl_Vertex;
|
||||
tex0 = gl_MultiTexCoord0.st;
|
||||
gl_Position = modelview * vPosition;
|
||||
tex0 = vTexCoord0.st;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue