Full Template for ticket #1

This commit is contained in:
DavidWyand-GG 2012-09-19 11:54:25 -04:00
parent 74f265b3b3
commit f439dc8dcd
2150 changed files with 286240 additions and 0 deletions

View file

@ -0,0 +1,47 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "../../hlslStructs.h"
struct ConvexConnectV
{
float4 hpos : POSITION;
float4 wsEyeDir : TEXCOORD0;
float4 ssPos : TEXCOORD1;
float4 vsEyeDir : TEXCOORD2;
};
ConvexConnectV main( VertexIn_P IN,
uniform float4x4 modelview,
uniform float4x4 objTrans,
uniform float4x4 worldViewOnly,
uniform float3 eyePosWorld )
{
ConvexConnectV OUT;
OUT.hpos = mul( modelview, IN.pos );
OUT.wsEyeDir = mul( objTrans, IN.pos ) - float4( eyePosWorld, 0.0 );
OUT.vsEyeDir = mul( worldViewOnly, IN.pos );
OUT.ssPos = OUT.hpos;
return OUT;
}

View file

@ -0,0 +1,33 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "shadergen:/autogenConditioners.h"
#include "../../postfx/postFx.hlsl"
float4 main( PFXVertToPix IN,
uniform sampler2D prepassTex : register(S0),
uniform sampler1D depthViz : register(S1) ) : COLOR0
{
float depth = prepassUncondition( prepassTex, IN.uv0 ).w;
return float4( tex1D( depthViz, depth ).rgb, 1.0 );
}

View file

@ -0,0 +1,34 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "shadergen:/autogenConditioners.h"
#include "../../postfx/postFx.hlsl"
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 );
}

View file

@ -0,0 +1,34 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "shadergen:/autogenConditioners.h"
#include "../../postfx/postFx.hlsl"
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( specular, specular, specular, 1.0 );
}

View file

@ -0,0 +1,32 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "shadergen:/autogenConditioners.h"
#include "../../postfx/postFx.hlsl"
float4 main( PFXVertToPix IN,
uniform sampler2D prepassTex : register(S0) ) : COLOR0
{
float3 normal = prepassUncondition( prepassTex, IN.uv0 ).xyz;
return float4( ( normal + 1.0 ) * 0.5, 1.0 );
}

View file

@ -0,0 +1,34 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
struct MaterialDecoratorConnectV
{
float2 uv0 : TEXCOORD0;
};
float4 main( MaterialDecoratorConnectV IN,
uniform sampler2D shadowMap : register(S0),
uniform sampler1D depthViz : register(S1) ) : COLOR0
{
float depth = saturate( tex2D( shadowMap, IN.uv0 ).r );
return float4( tex1D( depthViz, depth ).rgb, 1 );
}

View file

@ -0,0 +1,45 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
struct FarFrustumQuadConnectV
{
float4 hpos : POSITION;
float2 uv0 : TEXCOORD0;
float3 wsEyeRay : TEXCOORD1;
float3 vsEyeRay : TEXCOORD2;
};
struct FarFrustumQuadConnectP
{
float2 uv0 : TEXCOORD0;
float3 wsEyeRay : TEXCOORD1;
float3 vsEyeRay : TEXCOORD2;
};
float2 getUVFromSSPos( float3 ssPos, float4 rtParams )
{
float2 outPos = ( ssPos.xy + 1.0 ) / 2.0;
outPos.y = 1.0 - outPos.y;
outPos = ( outPos * rtParams.zw ) + rtParams.xy;
return outPos;
}

View file

@ -0,0 +1,43 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "../../hlslStructs.h"
#include "farFrustumQuad.hlsl"
FarFrustumQuadConnectV main( VertexIn_PNT IN,
uniform float4 rtParams0 )
{
FarFrustumQuadConnectV OUT;
OUT.hpos = float4( IN.uv0, 0, 1 );
// Get a RT-corrected UV from the SS coord
OUT.uv0 = getUVFromSSPos( OUT.hpos.xyz, rtParams0 );
// Interpolators will generate eye rays the
// from far-frustum corners.
OUT.wsEyeRay = IN.pos.xyz;
OUT.vsEyeRay = IN.normal.xyz;
return OUT;
}

View file

@ -0,0 +1,35 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
varying vec4 wsEyeDir;
varying vec4 ssPos;
uniform mat4 modelview;
uniform mat4 objTrans;
uniform vec3 eyePosWorld;
void main()
{
gl_Position = modelview * gl_Vertex;
wsEyeDir = objTrans * gl_Vertex - vec4( eyePosWorld, 0.0 );
ssPos = gl_Position;
}

View file

@ -0,0 +1,33 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "shadergen:/autogenConditioners.h"
varying vec2 uv0;
uniform sampler2D prepassBuffer;
uniform sampler1D depthViz;
void main()
{
float depth = prepassUncondition( prepassBuffer, uv0 ).w;
gl_FragColor = vec4( texture1D( depthViz, depth ).rgb, 1 );
}

View file

@ -0,0 +1,34 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "shadergen:/autogenConditioners.h"
varying vec2 uv0;
uniform sampler2D lightInfoBuffer;
void main()
{
vec3 lightcolor;
float nl_Att, specular;
lightinfoUncondition( texture2DLod( lightInfoBuffer, uv0 ), lightcolor, nl_Att, specular );
gl_FragColor = vec4( lightcolor, 1.0 );
}

View file

@ -0,0 +1,34 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "shadergen:/autogenConditioners.h"
varying vec2 uv0;
uniform sampler2D lightInfoBuffer;
void main()
{
vec3 lightcolor;
float nl_Att, specular;
lightinfoUncondition( texture2DLod( lightInfoBuffer, uv0 ), lightcolor, nl_Att, specular );
gl_FragColor = vec4( specular, specular, specular, 1.0 );
}

View file

@ -0,0 +1,33 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "shadergen:/autogenConditioners.h"
varying vec2 uv0;
uniform sampler2D prepassTex;
void main()
{
vec3 normal = prepassUncondition( prepassTex, uv0 ).xyz;
gl_FragColor = vec4( ( normal + 1.0 ) * 0.5, 1.0 );
}

View file

@ -0,0 +1,31 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
varying 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 );
}

View file

@ -0,0 +1,30 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
vec2 getUVFromSSPos( vec3 ssPos, vec4 rtParams )
{
vec2 outPos = ( ssPos.xy + 1.0 ) / 2.0;
outPos = ( outPos * rtParams.zw ) + rtParams.xy;
//outPos.y = 1.0 - outPos.y;
return outPos;
}

View file

@ -0,0 +1,43 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "farFrustumQuad.glsl"
uniform vec4 renderTargetParams;
varying vec4 hpos;
varying vec2 uv0;
varying vec3 wsEyeRay;
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;
// Get a RT-corrected UV from the SS coord
uv0 = getUVFromSSPos( hpos.xyz, renderTargetParams );
// Interpolators will generate eye ray from far-frustum corners
wsEyeRay = gl_Vertex.xyz;
}

View file

@ -0,0 +1,79 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
float attenuate( vec4 lightColor, vec2 attParams, float dist )
{
// We're summing the results of a scaled constant,
// linear, and quadratic attenuation.
#ifdef ACCUMULATE_LUV
return lightColor.w * ( 1.0 - dot( attParams, vec2( dist, dist * dist ) ) );
#else
return 1.0 - dot( attParams, vec2( dist, dist * dist ) );
#endif
}
// Calculate the specular coefficent
//
// pxlToLight - Normalized vector representing direction from the pixel being lit, to the light source, in world space
// normal - Normalized surface normal
// pxlToEye - Normalized vector representing direction from pixel being lit, to the camera, in world space
// specPwr - Specular exponent
// specularScale - A scalar on the specular output used in RGB accumulation.
//
float calcSpecular( vec3 pxlToLight, vec3 normal, vec3 pxlToEye, float specPwr, float specularScale )
{
#ifdef PHONG_SPECULAR
// (R.V)^c
float specVal = dot( normalize( -reflect( pxlToLight, normal ) ), pxlToEye );
#else
// (N.H)^c [Blinn-Phong, TGEA style, default]
float specVal = dot( normal, normalize( pxlToLight + pxlToEye ) );
#endif
#ifdef ACCUMULATE_LUV
return pow( max( specVal, 0.00001f ), specPwr );
#else
// If this is RGB accumulation, than there is no facility for the luminance
// of the light to play in to the specular intensity. In LUV, the luminance
// of the light color gets rolled into N.L * Attenuation
return specularScale * pow( max( specVal, 0.00001f ), specPwr );
#endif
}
vec3 getDistanceVectorToPlane( vec3 origin, vec3 direction, vec4 plane )
{
float denum = dot( plane.xyz, direction.xyz );
float num = dot( plane, vec4( origin, 1.0 ) );
float t = -num / denum;
return direction.xyz * t;
}
vec3 getDistanceVectorToPlane( float negFarPlaneDotEye, vec3 direction, vec4 plane )
{
float denum = dot( plane.xyz, direction.xyz );
float t = negFarPlaneDotEye / denum;
return direction.xyz * t;
}

View file

@ -0,0 +1,241 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "../../../gl/hlslCompat.glsl"
#include "farFrustumQuad.glsl"
#include "lightingUtils.glsl"
#include "../../shadowMap/shadowMapIO_GLSL.h"
#include "shadergen:/autogenConditioners.h"
#if TORQUE_SM >= 30
// Enables high quality soft shadow
// filtering for SM3.0 and above.
#define SOFTSHADOW_SM3
#include "softShadow.glsl"
#else
#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 )
{
return shadowCoord;
}
vec4 shadowSample( samplerCUBE shadowMap, vec3 shadowCoord )
{
return textureCUBE( shadowMap, shadowCoord );
}
#elif defined( SHADOW_DUALPARABOLOID )
vec3 decodeShadowCoord( vec3 paraVec )
{
// Swizzle z and y
paraVec = paraVec.xzy;
#ifdef SHADOW_DUALPARABOLOID_SINGLE_PASS
bool calcBack = (paraVec.z < 0.0);
if(calcBack)
paraVec.z = paraVec.z * -1.0;
#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.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;
#ifdef SHADOW_DUALPARABOLOID_SINGLE_PASS
// If this is the back, offset in the atlas
if(calcBack)
shadowCoord.x += 1.0;
// Atlasing front and back maps, so scale
shadowCoord.x *= 0.5;
#endif
return shadowCoord;
}
#else
#error Unknown shadow type!
#endif
varying vec4 wsEyeDir;
varying vec4 ssPos;
uniform sampler2D prePassBuffer;
#ifdef SHADOW_CUBE
uniform samplerCube shadowMap;
#else
uniform sampler2D shadowMap;
#endif
#ifdef ACCUMULATE_LUV
uniform sampler2D scratchTarget;
#endif
uniform vec4 renderTargetParams;
uniform vec3 lightPosition;
uniform vec4 lightColor;
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 lightParams;
uniform float shadowSoftness;
uniform float constantSpecularPower;
void main()
{
// Compute scene UV
vec3 ssPosP = ssPos.xyz / ssPos.w;
vec2 uvScene = getUVFromSSPos( ssPosP, renderTargetParams );
// Sample/unpack the normal/z data
vec4 prepassSample = prepassUncondition( prePassBuffer, uvScene );
vec3 normal = prepassSample.rgb;
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;
// Build light vec, get length, clip pixel if needed
vec3 lightVec = lightPosition - worldPos;
float lenLightV = length( lightVec );
if ( lightRange - lenLightV < 0.0 )
discard;
// Get the attenuated falloff.
float atten = attenuate( lightColor, lightAttenuation, lenLightV );
if ( atten - 1e-6 < 0.0 )
discard;
// Normalize lightVec
lightVec /= lenLightV;
// If we can do dynamic branching then avoid wasting
// fillrate on pixels that are backfacing to the light.
float nDotL = dot( lightVec, normal );
//DB_CLIP( nDotL < 0 );
#ifdef NO_SHADOW
float shadowed = 1.0;
#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;
#ifdef SOFTSHADOW_SM3
float shadowed = softShadow_filter( shadowMap,
gTapRotationTex,
ssPosP.xy,
shadowCoord.xy,
shadowSoftness,
distToLight,
nDotL,
lightParams.y );
#else // !SOFTSHADOW_SM3
// TODO: Implement the SM2 lower quality
// shadow filtering method.
#endif
#endif // !NO_SHADOW
// 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,
lightColor.a * 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
// Output
gl_FragColor = lightinfoCondition( lightColor.rgb * lightBrightness,
Sat_NL_Att,
specular,
previousPix ) * lightMapParams;
}

View file

@ -0,0 +1,131 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// 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()
{
// 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 );
}
/// 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;
}

View file

@ -0,0 +1,168 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "../../../gl/hlslCompat.glsl"
#include "farFrustumQuad.glsl"
#include "lightingUtils.glsl"
#include "../../shadowMap/shadowMapIO_GLSL.h"
#include "shadergen:/autogenConditioners.h"
#if TORQUE_SM >= 30
// Enables high quality soft shadow
// filtering for SM3.0 and above.
#define SOFTSHADOW_SM3
#include "softShadow.glsl"
#else
#endif
varying vec4 ssPos;
varying vec4 wsEyeDir;
uniform sampler2D prePassBuffer;
uniform sampler2D shadowMap;
#ifdef ACCUMULATE_LUV
uniform sampler2D scratchTarget;
#endif
uniform vec4 renderTargetParams;
uniform vec3 lightPosition;
uniform vec4 lightColor;
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 lightParams;
uniform float shadowSoftness;
uniform float constantSpecularPower;
void main()
{
// Compute scene UV
vec3 ssPosP = ssPos.xyz / ssPos.w;
vec2 uvScene = getUVFromSSPos( ssPosP, renderTargetParams );
// Sample/unpack the normal/z data
vec4 prepassSample = prepassUncondition( prePassBuffer, uvScene );
vec3 normal = prepassSample.rgb;
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;
// Build light vec, get length, clip pixel if needed
vec3 lightToPxlVec = worldPos - lightPosition;
float lenLightV = length( lightToPxlVec );
lightToPxlVec /= lenLightV;
//lightDirection = float3( -lightDirection.xy, lightDirection.z ); //float3( 0, 0, -1 );
float cosAlpha = dot( lightDirection, lightToPxlVec );
if ( cosAlpha - lightSpotParams.x < 0.0 ) discard;
if ( lightRange - lenLightV < 0.0 ) discard;
float atten = attenuate( lightColor, lightAttenuation, lenLightV );
atten *= ( cosAlpha - lightSpotParams.x ) / lightSpotParams.y;
if ( atten - 1e-6 < 0.0 ) discard;
float nDotL = dot( normal, -lightToPxlVec );
#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
#endif // !NO_SHADOW
// 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,
lightColor.a * 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
// Output
gl_FragColor = lightinfoCondition( lightColor.rgb * lightBrightness,
Sat_NL_Att,
specular,
previousPix ) * lightMapParams;
}

View file

@ -0,0 +1,230 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "../../../gl/hlslCompat.glsl"
#include "shadergen:/autogenConditioners.h"
#include "lightingUtils.glsl"
#include "../../shadowMap/shadowMapIO_GLSL.h"
varying vec2 uv0;
varying vec3 wsEyeRay;
uniform sampler2D prePassBuffer;
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
#endif
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 vec4 scaleX;
uniform vec4 scaleY;
uniform vec4 offsetX;
uniform vec4 offsetY;
uniform vec4 atlasXOffset;
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()
{
// Sample/unpack the normal/z data
vec4 prepassSample = prepassUncondition( prePassBuffer, uv0 );
vec3 normal = prepassSample.rgb;
float depth = prepassSample.a;
// 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 NO_SHADOW
// Fully unshadowed.
float shadowed = 1.0;
#else
// Compute shadow map coordinate
vec4 pxlPosLightProj = 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);
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);
vec4 finalMask = mask0 * mask1;
float splitFadeDist = dot( finalMask, splitFade );
vec2 finalScale;
finalScale.x = dot(finalMask, scaleX);
finalScale.y = dot(finalMask, scaleY);
vec2 finalOffset;
finalOffset.x = dot(finalMask, offsetX);
finalOffset.y = dot(finalMask, offsetY);
vec2 shadowCoord;
shadowCoord = baseShadowCoord * finalScale;
shadowCoord += finalOffset;
// Convert to texcoord space
shadowCoord = 0.5 * shadowCoord + vec2(0.5, 0.5);
//shadowCoord.y = 1.0f - shadowCoord.y;
// Move around inside of atlas
vec2 aOffset;
aOffset.x = dot(finalMask, atlasXOffset);
aOffset.y = dot(finalMask, atlasYOffset);
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
float esmShadow = softShadow_filter( ShadowMap,
gTapRotationTex,
uv0.xy,
shadowCoord,
farPlaneScale * shadowSoftness,
distToLight,
dotNL,
dot( finalMask, overDarkPSSM ) );
#else // !SOFTSHADOW_SM3
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;
}
// Fade out the shadow at the end of the range.
float fadeOutAmt = ( zDist.x - fadeStartLength.x ) * fadeStartLength.y;
shadowed = mix( shadowed, 1.0, clamp( fadeOutAmt, 0.0, 1.0 ) );
#endif // !NO_SHADOW
// Calc lighting coefficents
float specular = calcSpecular( -lightDirection,
normal,
normalize(-wsEyeRay),
constantSpecularPower,
lightColor.a * 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;
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;
#else
// 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);
#endif
// Output
gl_FragColor = lightinfoCondition( lightColor.rgb * lightBrightness, Sat_NL_Att, specular, ambientBlend) * lightMapParams;
}

View file

@ -0,0 +1,51 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
float attenuate( float4 lightColor, float2 attParams, float dist )
{
// We're summing the results of a scaled constant,
// linear, and quadratic attenuation.
#ifdef ACCUMULATE_LUV
return lightColor.w * ( 1.0 - dot( attParams, float2( dist, dist * dist ) ) );
#else
return 1.0 - dot( attParams, float2( dist, dist * dist ) );
#endif
}
float3 getDistanceVectorToPlane( float3 origin, float3 direction, float4 plane )
{
float denum = dot( plane.xyz, direction.xyz );
float num = dot( plane, float4( origin, 1.0 ) );
float t = -num / denum;
return direction.xyz * t;
}
float3 getDistanceVectorToPlane( float negFarPlaneDotEye, float3 direction, float4 plane )
{
float denum = dot( plane.xyz, direction.xyz );
float t = negFarPlaneDotEye / denum;
return direction.xyz * t;
}

View file

@ -0,0 +1,75 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "shadergen:/autogenConditioners.h"
#include "farFrustumQuad.hlsl"
#include "lightingUtils.hlsl"
#include "../../lighting.hlsl"
struct ConvexConnectP
{
float4 ssPos : TEXCOORD0;
float3 vsEyeDir : TEXCOORD1;
};
float4 main( ConvexConnectP IN,
uniform sampler2D prePassBuffer : register(S0),
uniform float4 lightPosition,
uniform float4 lightColor,
uniform float lightRange,
uniform float4 vsFarPlane,
uniform float4 rtParams0 ) : COLOR0
{
// Compute scene UV
float3 ssPos = IN.ssPos.xyz / IN.ssPos.w;
float2 uvScene = getUVFromSSPos(ssPos, rtParams0);
// Sample/unpack the normal/z data
float4 prepassSample = prepassUncondition(prePassBuffer, uvScene);
float3 normal = prepassSample.rgb;
float depth = prepassSample.a;
// Eye ray - Eye -> Pixel
float3 eyeRay = getDistanceVectorToPlane(-vsFarPlane.w, IN.vsEyeDir, vsFarPlane);
float3 viewSpacePos = eyeRay * depth;
// Build light vec, get length, clip pixel if needed
float3 lightVec = lightPosition.xyz - viewSpacePos;
float lenLightV = length(lightVec);
clip(lightRange - lenLightV);
// Do a very simple falloff instead of real attenuation
float atten = 1.0 - saturate(lenLightV / lightRange);
// Normalize lightVec
lightVec /= lenLightV;
// N.L * Attenuation
float Sat_NL_Att = saturate(dot(lightVec, normal)) * atten;
// Output, no specular
return lightinfoCondition(lightColor.rgb, Sat_NL_Att, 0.0, 0.0);
}

View file

@ -0,0 +1,46 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "../../hlslStructs.h"
struct ConvexConnectV
{
float4 hpos : POSITION;
float4 ssPos : TEXCOORD0;
float3 vsEyeDir : TEXCOORD1;
};
ConvexConnectV main( VertexIn_P IN,
uniform float4x4 viewProj,
uniform float4x4 view,
uniform float3 particlePosWorld,
uniform float lightRange )
{
ConvexConnectV OUT;
float4 vPosWorld = IN.pos + float4(particlePosWorld, 0.0) + float4(IN.pos.xyz, 0.0) * lightRange;
OUT.hpos = mul(viewProj, vPosWorld);
OUT.vsEyeDir = mul(view, vPosWorld);
OUT.ssPos = OUT.hpos;
return OUT;
}

View file

@ -0,0 +1,239 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "shadergen:/autogenConditioners.h"
#include "farFrustumQuad.hlsl"
#include "lightingUtils.hlsl"
#include "../../lighting.hlsl"
#include "../shadowMap/shadowMapIO_HLSL.h"
#include "softShadow.hlsl"
struct ConvexConnectP
{
float4 wsEyeDir : TEXCOORD0;
float4 ssPos : TEXCOORD1;
float4 vsEyeDir : TEXCOORD2;
};
#ifdef USE_COOKIE_TEX
/// The texture for cookie rendering.
uniform samplerCUBE cookieMap : register(S2);
#endif
#ifdef SHADOW_CUBE
float3 decodeShadowCoord( float3 shadowCoord )
{
return shadowCoord;
}
float4 shadowSample( samplerCUBE shadowMap, float3 shadowCoord )
{
return texCUBE( shadowMap, shadowCoord );
}
#else
float3 decodeShadowCoord( float3 paraVec )
{
// Flip y and z
paraVec = paraVec.xzy;
#ifndef SHADOW_PARABOLOID
bool calcBack = (paraVec.z < 0.0);
if ( calcBack )
{
paraVec.z = paraVec.z * -1.0;
#ifdef SHADOW_DUALPARABOLOID
paraVec.x = -paraVec.x;
#endif
}
#endif
float3 shadowCoord;
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
// NOTE: this is wrong, it only biases in one direction, not towards the uv
// center ( 0.5 0.5 ).
//shadowCoord.xy *= 0.997;
#ifndef SHADOW_PARABOLOID
// If this is the back, offset in the atlas
if ( calcBack )
shadowCoord.x += 1.0;
// Atlasing front and back maps, so scale
shadowCoord.x *= 0.5;
#endif
return shadowCoord;
}
#endif
float4 main( ConvexConnectP IN,
uniform sampler2D prePassBuffer : register(S0),
#ifdef SHADOW_CUBE
uniform samplerCUBE shadowMap : register(S1),
#else
uniform sampler2D shadowMap : register(S1),
#endif
uniform float4 rtParams0,
uniform float3 lightPosition,
uniform float4 lightColor,
uniform float lightBrightness,
uniform float lightRange,
uniform float2 lightAttenuation,
uniform float4 lightMapParams,
uniform float4 vsFarPlane,
uniform float3x3 viewToLightProj,
uniform float4 lightParams,
uniform float shadowSoftness ) : COLOR0
{
// Compute scene UV
float3 ssPos = IN.ssPos.xyz / IN.ssPos.w;
float2 uvScene = getUVFromSSPos( ssPos, rtParams0 );
// Sample/unpack the normal/z data
float4 prepassSample = prepassUncondition( prePassBuffer, uvScene );
float3 normal = prepassSample.rgb;
float depth = prepassSample.a;
// Eye ray - Eye -> Pixel
float3 eyeRay = getDistanceVectorToPlane( -vsFarPlane.w, IN.vsEyeDir.xyz, vsFarPlane );
float3 viewSpacePos = eyeRay * depth;
// Build light vec, get length, clip pixel if needed
float3 lightVec = lightPosition - viewSpacePos;
float lenLightV = length( lightVec );
clip( lightRange - lenLightV );
// Get the attenuated falloff.
float atten = attenuate( lightColor, lightAttenuation, lenLightV );
clip( atten - 1e-6 );
// Normalize lightVec
lightVec /= lenLightV;
// If we can do dynamic branching then avoid wasting
// fillrate on pixels that are backfacing to the light.
float nDotL = dot( lightVec, normal );
//DB_CLIP( nDotL < 0 );
#ifdef NO_SHADOW
float shadowed = 1.0;
#else
// Get a linear depth from the light source.
float distToLight = lenLightV / lightRange;
#ifdef SHADOW_CUBE
// TODO: We need to fix shadow cube to handle soft shadows!
float occ = texCUBE( shadowMap, mul( viewToLightProj, -lightVec ) ).r;
float shadowed = saturate( exp( lightParams.y * ( occ - distToLight ) ) );
#else
float2 shadowCoord = decodeShadowCoord( mul( viewToLightProj, -lightVec ) ).xy;
float shadowed = softShadow_filter( shadowMap,
ssPos.xy,
shadowCoord,
shadowSoftness,
distToLight,
nDotL,
lightParams.y );
#endif
#endif // !NO_SHADOW
#ifdef USE_COOKIE_TEX
// Lookup the cookie sample.
float4 cookie = texCUBE( cookieMap, mul( 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 = AL_CalcSpecular( lightVec,
normal,
normalize( -eyeRay ) ) * lightColor.a;
float Sat_NL_Att = saturate( nDotL * atten * shadowed ) * lightBrightness;
float3 lightColorOut = lightMapParams.rgb * lightColor.rgb;
float4 addToResult = 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 = lerp( 1.0f, shadowed, atten );
lightColorOut = shadowed;
specular *= lightBrightness;
addToResult = ( 1.0 - shadowed ) * abs(lightMapParams);
}
return lightinfoCondition( lightColorOut, Sat_NL_Att, specular, addToResult );
}

View file

@ -0,0 +1,159 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#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.
static float2 sNonUniformTaps[NUM_TAPS] =
{
// These first 4 taps are located around the edges
// of the disk and are used to predict fully shadowed
// or unshadowed areas.
{ 0.992833, 0.979309 },
{ -0.998585, 0.985853 },
{ 0.949299, -0.882562 },
{ -0.941358, -0.893924 },
// The rest of the samples.
{ 0.545055, -0.589072 },
{ 0.346526, 0.385821 },
{ -0.260183, 0.334412 },
{ 0.248676, -0.679605 },
{ -0.569502, -0.390637 },
{ -0.614096, 0.212577 },
{ -0.259178, 0.876272 },
{ 0.649526, 0.864333 },
};
#else
#define NUM_PRE_TAPS 5
/// The non-uniform poisson disk used in the
/// high quality shadow filtering.
static float2 sNonUniformTaps[NUM_PRE_TAPS] =
{
{ 0.892833, 0.959309 },
{ -0.941358, -0.873924 },
{ -0.260183, 0.334412 },
{ 0.348676, -0.679605 },
{ -0.569502, -0.390637 },
};
#endif
/// The texture used to do per-pixel pseudorandom
/// rotations of the filter taps.
uniform sampler2D gTapRotationTex : register(S3);
float softShadow_sampleTaps( sampler2D shadowMap,
float2 sinCos,
float2 shadowPos,
float filterRadius,
float distToLight,
float esmFactor,
int startTap,
int endTap )
{
float shadow = 0;
float2 tap = 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, float4( shadowPos + tap, 0, 0 ) ).r;
float esm = saturate( exp( esmFactor * ( occluder - distToLight ) ) );
shadow += esm / float( endTap - startTap );
}
return shadow;
}
float softShadow_filter( sampler2D shadowMap,
float2 vpos,
float2 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, float4( shadowPos, 0, 0 ) ).r;
float shadow = saturate( exp( esmFactor * ( occluder - distToLight ) ) );
#else
// Lookup the random rotation for this screen pixel.
float2 sinCos = ( tex2Dlod( gTapRotationTex, float4( 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;
}

View file

@ -0,0 +1,167 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "shadergen:/autogenConditioners.h"
#include "farFrustumQuad.hlsl"
#include "lightingUtils.hlsl"
#include "../../lighting.hlsl"
#include "../shadowMap/shadowMapIO_HLSL.h"
#include "softShadow.hlsl"
struct ConvexConnectP
{
float4 wsEyeDir : TEXCOORD0;
float4 ssPos : TEXCOORD1;
float4 vsEyeDir : TEXCOORD2;
};
#ifdef USE_COOKIE_TEX
/// The texture for cookie rendering.
uniform sampler2D cookieMap : register(S2);
#endif
float4 main( ConvexConnectP IN,
uniform sampler2D prePassBuffer : register(S0),
uniform sampler2D shadowMap : register(S1),
uniform float4 rtParams0,
uniform float3 lightPosition,
uniform float4 lightColor,
uniform float lightBrightness,
uniform float lightRange,
uniform float2 lightAttenuation,
uniform float3 lightDirection,
uniform float4 lightSpotParams,
uniform float4 lightMapParams,
uniform float4 vsFarPlane,
uniform float4x4 viewToLightProj,
uniform float4 lightParams,
uniform float shadowSoftness ) : COLOR0
{
// Compute scene UV
float3 ssPos = IN.ssPos.xyz / IN.ssPos.w;
float2 uvScene = getUVFromSSPos( ssPos, rtParams0 );
// Sample/unpack the normal/z data
float4 prepassSample = prepassUncondition( prePassBuffer, uvScene );
float3 normal = prepassSample.rgb;
float depth = prepassSample.a;
// Eye ray - Eye -> Pixel
float3 eyeRay = getDistanceVectorToPlane( -vsFarPlane.w, IN.vsEyeDir.xyz, vsFarPlane );
float3 viewSpacePos = eyeRay * depth;
// Build light vec, get length, clip pixel if needed
float3 lightToPxlVec = viewSpacePos - lightPosition;
float lenLightV = length( lightToPxlVec );
lightToPxlVec /= lenLightV;
//lightDirection = float3( -lightDirection.xy, lightDirection.z ); //float3( 0, 0, -1 );
float cosAlpha = dot( lightDirection, lightToPxlVec );
clip( cosAlpha - lightSpotParams.x );
clip( lightRange - lenLightV );
float atten = attenuate( lightColor, lightAttenuation, lenLightV );
atten *= ( cosAlpha - lightSpotParams.x ) / lightSpotParams.y;
clip( atten - 1e-6 );
atten = saturate( atten );
float nDotL = dot( normal, -lightToPxlVec );
// Get the shadow texture coordinate
float4 pxlPosLightProj = mul( viewToLightProj, float4( viewSpacePos, 1 ) );
float2 shadowCoord = ( ( pxlPosLightProj.xy / pxlPosLightProj.w ) * 0.5 ) + float2( 0.5, 0.5 );
shadowCoord.y = 1.0f - shadowCoord.y;
#ifdef NO_SHADOW
float shadowed = 1.0;
#else
// Get a linear depth from the light source.
float distToLight = pxlPosLightProj.z / lightRange;
float shadowed = softShadow_filter( shadowMap,
ssPos.xy,
shadowCoord,
shadowSoftness,
distToLight,
nDotL,
lightParams.y );
#endif // !NO_SHADOW
#ifdef USE_COOKIE_TEX
// Lookup the cookie sample.
float4 cookie = tex2D( 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 = AL_CalcSpecular( -lightToPxlVec,
normal,
normalize( -eyeRay ) ) * lightColor.a;
float Sat_NL_Att = saturate( nDotL * atten * shadowed ) * lightBrightness;
float3 lightColorOut = lightMapParams.rgb * lightColor.rgb;
float4 addToResult = 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 = lerp( 1.0f, shadowed, atten );
lightColorOut = shadowed;
specular *= lightBrightness;
addToResult = ( 1.0 - shadowed ) * abs(lightMapParams);
}
return lightinfoCondition( lightColorOut, Sat_NL_Att, specular, addToResult );
}

View file

@ -0,0 +1,233 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "shadergen:/autogenConditioners.h"
#include "farFrustumQuad.hlsl"
#include "../../torque.hlsl"
#include "../../lighting.hlsl"
#include "lightingUtils.hlsl"
#include "../shadowMap/shadowMapIO_HLSL.h"
#include "softShadow.hlsl"
uniform sampler2D ShadowMap : register(S1);
#ifdef USE_SSAO_MASK
uniform sampler2D ssaoMask : register(S2);
uniform float4 rtParams2;
#endif
float4 main( FarFrustumQuadConnectP IN,
uniform sampler2D prePassBuffer : register(S0),
uniform float3 lightDirection,
uniform float4 lightColor,
uniform float lightBrightness,
uniform float4 lightAmbient,
uniform float3 eyePosWorld,
uniform float4x4 worldToLightProj,
uniform float4 scaleX,
uniform float4 scaleY,
uniform float4 offsetX,
uniform float4 offsetY,
uniform float4 atlasXOffset,
uniform float4 atlasYOffset,
uniform float2 atlasScale,
uniform float4 zNearFarInvNearFar,
uniform float4 lightMapParams,
uniform float2 fadeStartLength,
uniform float4 farPlaneScalePSSM,
uniform float4 overDarkPSSM,
uniform float shadowSoftness ) : COLOR0
{
// Sample/unpack the normal/z data
float4 prepassSample = prepassUncondition( prePassBuffer, IN.uv0 );
float3 normal = prepassSample.rgb;
float depth = prepassSample.a;
// Use eye ray to get ws pos
float4 worldPos = float4(eyePosWorld + IN.wsEyeRay * depth, 1.0f);
// Get the light attenuation.
float dotNL = dot(-lightDirection, normal);
#ifdef PSSM_DEBUG_RENDER
float3 debugColor = 0;
#endif
#ifdef NO_SHADOW
// Fully unshadowed.
float shadowed = 1.0;
#ifdef PSSM_DEBUG_RENDER
debugColor = 1.0;
#endif
#else
// Compute shadow map coordinate
float4 pxlPosLightProj = mul(worldToLightProj, worldPos);
float2 baseShadowCoord = pxlPosLightProj.xy / pxlPosLightProj.w;
// Distance to light, in shadowmap space
float distToLight = pxlPosLightProj.z / pxlPosLightProj.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.
float4 shadowCoordX = baseShadowCoord.xxxx;
float4 shadowCoordY = baseShadowCoord.yyyy;
float4 farPlaneDists = distToLight.xxxx;
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.
float4 finalMask;
if ( shadowCoordX.x > -0.99 && shadowCoordX.x < 0.99 &&
shadowCoordY.x > -0.99 && shadowCoordY.x < 0.99 &&
farPlaneDists.x < 1.0 )
finalMask = float4(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 = float4(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 = float4(0, 0, 1, 0);
else
finalMask = float4(0, 0, 0, 1);
#ifdef PSSM_DEBUG_RENDER
if ( finalMask.x > 0 )
debugColor += float3( 1, 0, 0 );
else if ( finalMask.y > 0 )
debugColor += float3( 0, 1, 0 );
else if ( finalMask.z > 0 )
debugColor += float3( 0, 0, 1 );
else if ( finalMask.w > 0 )
debugColor += float3( 1, 1, 0 );
#endif
// 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.
float2 finalScale;
finalScale.x = dot(finalMask, scaleX);
finalScale.y = dot(finalMask, scaleY);
float2 finalOffset;
finalOffset.x = dot(finalMask, offsetX);
finalOffset.y = dot(finalMask, offsetY);
float2 shadowCoord;
shadowCoord = baseShadowCoord * finalScale;
shadowCoord += finalOffset;
// Convert to texcoord space
shadowCoord = 0.5 * shadowCoord + float2(0.5, 0.5);
shadowCoord.y = 1.0f - shadowCoord.y;
// Move around inside of atlas
float2 aOffset;
aOffset.x = dot(finalMask, atlasXOffset);
aOffset.y = dot(finalMask, atlasYOffset);
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,
IN.uv0.xy,
shadowCoord,
farPlaneScale * shadowSoftness,
distToLight,
dotNL,
dot( finalMask, overDarkPSSM ) );
// Fade out the shadow at the end of the range.
float4 zDist = (zNearFarInvNearFar.x + zNearFarInvNearFar.y * depth);
float fadeOutAmt = ( zDist.x - fadeStartLength.x ) * fadeStartLength.y;
shadowed = lerp( shadowed, 1.0, saturate( fadeOutAmt ) );
#ifdef PSSM_DEBUG_RENDER
if ( fadeOutAmt > 1.0 )
debugColor = 1.0;
#endif
#endif // !NO_SHADOW
// Specular term
float specular = AL_CalcSpecular( -lightDirection,
normal,
normalize(-IN.vsEyeRay) ) * lightColor.a;
float Sat_NL_Att = saturate( dotNL * shadowed ) * lightBrightness;
float3 lightColorOut = lightMapParams.rgb * lightColor.rgb;
float4 addToResult = lightAmbient;
// 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;
Sat_NL_Att = 1.0f;
lightColorOut = shadowed;
specular *= lightBrightness;
addToResult = ( 1.0 - shadowed ) * abs(lightMapParams);
}
// Sample the AO texture.
#ifdef USE_SSAO_MASK
float ao = 1.0 - tex2D( ssaoMask, viewportCoordToRenderTarget( IN.uv0.xy, rtParams2 ) ).r;
addToResult *= ao;
#endif
#ifdef PSSM_DEBUG_RENDER
lightColorOut = debugColor;
#endif
return lightinfoCondition( lightColorOut, Sat_NL_Att, specular, addToResult );
}

View file

@ -0,0 +1,54 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
uniform sampler2D diffuseMap;
varying vec2 uv;
uniform vec2 oneOverTargetSize;
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);
gl_FragColor = vec4(0.0);
vec2 texScale = vec2(1.0);
for ( int i=0; i < 4; i++ )
{
vec2 offset = (oneOverTargetSize * texScale) * sNonUniformTaps[i];
gl_FragColor += texture2D( diffuseMap, uv + offset );
}
gl_FragColor /= vec4(4.0);
gl_FragColor.rgb = vec3(0.0);
}

View file

@ -0,0 +1,34 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "../../../../../../shaders/common/gl/torque.glsl"
uniform vec2 oneOverTargetSize;
uniform vec4 rtParams0;
varying vec2 uv;
void main()
{
gl_Position = gl_Vertex;
uv = viewportCoordToRenderTarget( gl_MultiTexCoord0.st, rtParams0 );
}

View file

@ -0,0 +1,50 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "shaders/common/postFx/postFx.hlsl"
uniform sampler2D diffuseMap : register(S0);
struct VertToPix
{
float4 hpos : POSITION;
float2 uv : TEXCOORD0;
};
static float offset[3] = { 0.0, 1.3846153846, 3.2307692308 };
static float weight[3] = { 0.2270270270, 0.3162162162, 0.0702702703 };
uniform float2 oneOverTargetSize;
float4 main( VertToPix IN ) : COLOR
{
float4 OUT = tex2D( diffuseMap, IN.uv ) * weight[0];
for ( int i=1; i < 3; i++ )
{
float2 sample = (BLUR_DIR * offset[i]) * oneOverTargetSize;
OUT += tex2D( diffuseMap, IN.uv + sample ) * weight[i];
OUT += tex2D( diffuseMap, IN.uv - sample ) * weight[i];
}
return OUT;
}

View file

@ -0,0 +1,42 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "../../../../../../shaders/common/postFx/postFx.hlsl"
#include "../../../../../../shaders/common/torque.hlsl"
float4 rtParams0;
struct VertToPix
{
float4 hpos : POSITION;
float2 uv : TEXCOORD0;
};
VertToPix main( PFXVert IN )
{
VertToPix OUT;
OUT.hpos = IN.pos;
OUT.uv = viewportCoordToRenderTarget( IN.uv, rtParams0 );
return OUT;
}

View file

@ -0,0 +1,80 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
//*****************************************************************************
// Box Filter
//*****************************************************************************
struct ConnectData
{
float2 tex0 : TEXCOORD0;
};
// If not defined from ShaderData then define
// the default blur kernel size here.
//#ifndef blurSamples
// #define blurSamples 4
//#endif
float log_conv ( float x0, float X, float y0, float Y )
{
return (X + log(x0 + (y0 * exp(Y - X))));
}
float4 main( ConnectData IN,
uniform sampler2D diffuseMap0 : register(S0),
uniform float texSize : register(C0),
uniform float2 blurDimension : register(C2),
uniform float2 blurBoundaries : register(C3)
) : COLOR0
{
// 5x5
if (IN.tex0.x <= blurBoundaries.x)
{
float texelSize = 1.2f / texSize;
float2 sampleOffset = texelSize * blurDimension;
//float2 offset = 0.5 * float( blurSamples ) * sampleOffset;
float2 texCoord = IN.tex0;
float accum = log_conv(0.3125, tex2D(diffuseMap0, texCoord - sampleOffset), 0.375, tex2D(diffuseMap0, texCoord));
accum = log_conv(1, accum, 0.3125, tex2D(diffuseMap0, texCoord + sampleOffset));
return accum;
} else {
// 3x3
if (IN.tex0.x <= blurBoundaries.y)
{
float texelSize = 1.3f / texSize;
float2 sampleOffset = texelSize * blurDimension;
//float2 offset = 0.5 * float( blurSamples ) * sampleOffset;
float2 texCoord = IN.tex0;
float accum = log_conv(0.5, tex2D(diffuseMap0, texCoord - sampleOffset), 0.5, tex2D(diffuseMap0, texCoord + sampleOffset));
return accum;
} else {
return tex2D(diffuseMap0, IN.tex0);
}
}
}

View file

@ -0,0 +1,54 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
//*****************************************************************************
// Box Filter
//*****************************************************************************
//-----------------------------------------------------------------------------
// Structures
//-----------------------------------------------------------------------------
struct VertData
{
float2 texCoord : TEXCOORD0;
float4 position : POSITION;
};
struct ConnectData
{
float4 hpos : POSITION;
float2 tex0 : TEXCOORD0;
};
//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------
ConnectData main( VertData IN,
uniform float4x4 modelview : register(C0))
{
ConnectData OUT;
OUT.hpos = mul(modelview, IN.position);
OUT.tex0 = IN.texCoord;
return OUT;
}

View file

@ -0,0 +1,47 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#define blurSamples 4.0
uniform sampler2D diffuseMap0;
uniform float texSize;
uniform vec2 blurDimension;
varying vec2 tex0;
void main()
{
// Preshader
float TexelSize = 1.0 / texSize;
vec2 SampleOffset = TexelSize * blurDimension;
vec2 Offset = 0.5 * float(blurSamples - 1.0) * SampleOffset;
vec2 BaseTexCoord = tex0 - Offset;
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 /= blurSamples;
gl_FragColor = accum;
}

View file

@ -0,0 +1,31 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
uniform mat4 modelview;
varying vec2 tex0;
void main()
{
gl_Position = modelview * gl_Vertex;
tex0 = gl_MultiTexCoord0.st;
}

View file

@ -0,0 +1,50 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
//#define SM_Fmt_R8G8B8A8
#define pkDepthBitShft 65536.0
#define pkDepthChanMax 256.0
#define bias -0.5/255.0
#define coeff 0.9999991
//#define coeff 1.0
vec4 encodeShadowMap( float depth )
{
#if defined(SM_Fmt_R8G8B8A8)
return frac( vec4(1.0, 255.0, 65025.0, 160581375.0) * depth ) + vec4(bias);
//float4 packedValue = frac((depth / coeff) * float4(16777216.0, 65536.0, 256.0, 1.0));
//return (packedValue - packedValue.xxyz * float4(0, 1.0 / 256, 1.0 / 256, 1.0 / 256));
#else
return vec4(depth);
#endif
}
float decodeShadowMap( vec4 smSample )
{
#if defined(SM_Fmt_R8G8B8A8)
return dot( smSample, vec4(1.0, 1/255.0, 1/65025.0, 1/160581375.0) );
#else
return smSample.x;
#endif
}

View file

@ -0,0 +1,50 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
//#define SM_Fmt_R8G8B8A8
#define pkDepthBitShft 65536.0
#define pkDepthChanMax 256.0
#define bias -0.5/255.0
#define coeff 0.9999991
//#define coeff 1.0
float4 encodeShadowMap( float depth )
{
#if defined(SM_Fmt_R8G8B8A8)
return frac( float4(1.0, 255.0, 65025.0, 160581375.0) * depth ) + bias;
//float4 packedValue = frac((depth / coeff) * float4(16777216.0, 65536.0, 256.0, 1.0));
//return (packedValue - packedValue.xxyz * float4(0, 1.0 / 256, 1.0 / 256, 1.0 / 256));
#else
return depth;
#endif
}
float decodeShadowMap( float4 smSample )
{
#if defined(SM_Fmt_R8G8B8A8)
return dot( smSample, float4(1.0, 1/255.0, 1/65025.0, 1/160581375.0) );
#else
return smSample.x;
#endif
}