Merge pull request #939 from BeamNG/templates_opengl

Templates changes for OpenGL shaders.
This commit is contained in:
LuisAntonRebollo 2014-11-30 02:23:37 +01:00
commit 04d069daa0
140 changed files with 9210 additions and 6 deletions

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.
//-----------------------------------------------------------------------------
uniform sampler2D diffuseMap;
in vec4 color;
in vec2 texCoord;
out vec4 OUT_FragColor0;
void main()
{
OUT_FragColor0 = vec4(color.rgb, color.a * texture(diffuseMap, texCoord).a);
}

View file

@ -0,0 +1,38 @@
//-----------------------------------------------------------------------------
// 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"
in vec4 vPosition;
in vec4 vColor;
in vec2 vTexCoord0;
uniform mat4 modelview;
out vec4 color;
out vec2 texCoord;
void main()
{
gl_Position = tMul(modelview, vPosition);
correctSSP(gl_Position);
color = vColor;
texCoord = vTexCoord0.st;
}

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.
//-----------------------------------------------------------------------------
in vec4 color;
out vec4 OUT_FragColor0;
void main()
{
OUT_FragColor0 = color;
}

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.
//-----------------------------------------------------------------------------
#include "../../gl/hlslCompat.glsl"
in vec4 vPosition;
in vec4 vColor;
uniform mat4 modelview;
out vec4 color;
void main()
{
gl_Position = tMul(modelview, vPosition);
correctSSP(gl_Position);
color = vColor;
}

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.
//-----------------------------------------------------------------------------
uniform sampler2D diffuseMap;
in vec4 color;
in vec2 texCoord;
out vec4 OUT_FragColor0;
void main()
{
OUT_FragColor0 = texture(diffuseMap, texCoord) * color;
}

View file

@ -0,0 +1,38 @@
//-----------------------------------------------------------------------------
// 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"
in vec4 vPosition;
in vec4 vColor;
in vec2 vTexCoord0;
uniform mat4 modelview;
out vec4 color;
out vec2 texCoord;
void main()
{
gl_Position = tMul(modelview, vPosition);
correctSSP(gl_Position);
color = vColor;
texCoord = vTexCoord0.st;
}

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 sampler2D colorTarget0Texture ;
vec4 main( vec2 ScreenPos : VPOS ) : COLOR0
{
vec2 TexCoord = ScreenPos;
vec4 diffuse;
asm { tfetch2D diffuse, TexCoord, colorTarget0Texture, UnnormalizedTextureCoords = true };
return diffuse;
}

View file

@ -0,0 +1,22 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------

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 sampler2D diffuseMap;
in vec2 texCoord;
out vec4 OUT_FragColor0;
void main()
{
OUT_FragColor0 = texture(diffuseMap, texCoord);
}

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.
//-----------------------------------------------------------------------------
#include "../../gl/hlslCompat.glsl"
in vec4 vPosition;
in vec2 vTexCoord0;
uniform mat4 modelview;
out vec2 texCoord;
void main()
{
gl_Position = tMul(modelview, vPosition);
correctSSP(gl_Position);
texCoord = vTexCoord0.st;
}

View file

@ -0,0 +1,37 @@
//-----------------------------------------------------------------------------
// 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 "torque.glsl"
#include "hlslCompat.glsl"
//ConnectData
in vec2 texCoord;
#define IN_texCoord texCoord
uniform sampler2D diffuseMap ;
void main()
{
vec4 col = texture( diffuseMap, IN_texCoord );
OUT_FragColor0 = hdrEncode( col );
}

View file

@ -0,0 +1,53 @@
//-----------------------------------------------------------------------------
// 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 "hlslCompat.glsl"
//CloudVert
in vec4 vPosition;
in vec2 vTexCoord0;
#define IN_pos vPosition
#define IN_uv0 vTexCoord0
uniform mat4 modelview;
uniform float accumTime;
uniform float texScale;
uniform vec2 texDirection;
uniform vec2 texOffset;
out vec2 texCoord;
#define OUT_texCoord texCoord
void main()
{
gl_Position = tMul(modelview, IN_pos);
vec2 uv = IN_uv0;
uv += texOffset;
uv *= texScale;
uv += accumTime * texDirection;
OUT_texCoord = uv;
correctSSP(gl_Position);
}

View file

@ -48,14 +48,14 @@
#define lerp mix #define lerp mix
void tSetMatrixRow(out float3x3 m, int row, float3 value) void tSetMatrixRow(inout float3x3 m, int row, float3 value)
{ {
m[0][row] = value.x; m[0][row] = value.x;
m[1][row] = value.y; m[1][row] = value.y;
m[2][row] = value.z; m[2][row] = value.z;
} }
void tSetMatrixRow(out float4x4 m, int row, float4 value) void tSetMatrixRow(inout float4x4 m, int row, float4 value)
{ {
m[0][row] = value.x; m[0][row] = value.x;
m[1][row] = value.y; m[1][row] = value.y;

View file

@ -0,0 +1,85 @@
//-----------------------------------------------------------------------------
// 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 "../../gl/postFX.glsl"
#include "shadergen:/autogenConditioners.h"
uniform vec3 eyePosWorld;
uniform vec4 rtParams0;
uniform vec4 waterFogPlane;
uniform float accumTime;
uniform sampler2D prepassTex;
uniform sampler2D causticsTex0;
uniform sampler2D causticsTex1;
uniform vec2 targetSize;
float distanceToPlane(vec4 plane, vec3 pos)
{
return (plane.x * pos.x + plane.y * pos.y + plane.z * pos.z) + plane.w;
}
void main()
{
//Sample the pre-pass
vec4 prePass = prepassUncondition( prepassTex, IN_uv0 );
//Get depth
float depth = prePass.w;
if(depth > 0.9999)
{
OUT_FragColor0 = vec4(0,0,0,0);
return;
}
//Get world position
vec3 pos = eyePosWorld + IN_wsEyeRay * depth;
// Check the water depth
float waterDepth = -distanceToPlane(waterFogPlane, pos);
if(waterDepth < 0)
{
OUT_FragColor0 = vec4(0,0,0,0);
return;
}
waterDepth = saturate(waterDepth);
//Use world position X and Y to calculate caustics UV
vec2 causticsUV0 = mod(abs(pos.xy * 0.25), vec2(1, 1));
vec2 causticsUV1 = mod(abs(pos.xy * 0.2), vec2(1, 1));
//Animate uvs
float timeSin = sin(accumTime);
causticsUV0.xy += vec2(accumTime*0.1, timeSin*0.2);
causticsUV1.xy -= vec2(accumTime*0.15, timeSin*0.15);
//Sample caustics texture
vec4 caustics = texture(causticsTex0, causticsUV0);
caustics *= texture(causticsTex1, causticsUV1);
//Use normal Z to modulate caustics
//float waterDepth = 1 - saturate(pos.z + waterFogPlane.w + 1);
caustics *= saturate(prePass.z) * pow(1-depth, 64) * waterDepth;
OUT_FragColor0 = caustics;
}

View file

@ -0,0 +1,53 @@
//-----------------------------------------------------------------------------
// 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 "../../gl/postFX.glsl"
// These are set by the game engine.
uniform sampler2D shrunkSampler; // Output of DofDownsample()
uniform sampler2D blurredSampler; // Blurred version of the shrunk sampler
// This is the pixel shader function that calculates the actual
// value used for the near circle of confusion.
// "texCoords" are 0 at the bottom left pixel and 1 at the top right.
void main()
{
vec3 color;
float coc;
half4 blurred;
half4 shrunk;
shrunk = texture( shrunkSampler, IN_uv0 );
blurred = texture( blurredSampler, IN_uv1 );
color = shrunk.rgb;
//coc = shrunk.a;
//coc = blurred.a;
//coc = max( blurred.a, shrunk.a );
coc = 2 * max( blurred.a, shrunk.a ) - shrunk.a;
//OUT_FragColor0 = vec4( coc.rrr, 1.0 );
//OUT_FragColor0 = vec4( color, 1.0 );
OUT_FragColor0 = vec4( color, coc );
//OUT_FragColor0 = vec4( 1.0, 0.0, 1.0, 1.0 );
}

View file

@ -0,0 +1,69 @@
//-----------------------------------------------------------------------------
// 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 "../../../gl/torque.glsl"
#include "../../gl/postFX.glsl"
uniform vec4 rtParams0;
uniform vec4 rtParams1;
uniform vec4 rtParams2;
uniform vec4 rtParams3;
void main()
{
/*
OUT_hpos = IN.pos;
OUT_uv0 = IN_uv;
OUT_uv1 = IN_uv;
OUT_uv2 = IN_uv;
OUT_uv3 = IN_uv;
*/
/*
OUT_hpos = IN_pos;
OUT_uv0 = IN_uv + rtParams0.xy;
OUT_uv1 = IN_uv + rtParams1.xy;
OUT_uv2 = IN_uv + rtParams2.xy;
OUT_uv3 = IN_uv + rtParams3.xy;
*/
/*
OUT_hpos = IN_pos;
OUT_uv0 = IN_uv * rtParams0.zw;
OUT_uv1 = IN_uv * rtParams1.zw;
OUT_uv2 = IN_uv * rtParams2.zw;
OUT_uv3 = IN_uv * rtParams3.zw;
*/
OUT_hpos = IN_pos;
OUT_uv0 = viewportCoordToRenderTarget( IN_uv, rtParams0 );
OUT_uv1 = viewportCoordToRenderTarget( IN_uv, rtParams1 );
OUT_uv2 = viewportCoordToRenderTarget( IN_uv, rtParams2 );
OUT_uv3 = viewportCoordToRenderTarget( IN_uv, rtParams3 );
OUT_wsEyeRay = IN_wsEyeRay;
correctSSP(gl_Position);;
}

View file

@ -0,0 +1,138 @@
//-----------------------------------------------------------------------------
// 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"
// These are set by the game engine.
// The render target size is one-quarter the scene rendering size.
uniform sampler2D colorSampler;
uniform sampler2D depthSampler;
uniform vec2 dofEqWorld;
uniform float depthOffset;
uniform vec2 targetSize;
uniform float maxWorldCoC;
//uniform vec2 dofEqWeapon;
//uniform vec2 dofRowDelta; // vec2( 0, 0.25 / renderTargetHeight )
in vec2 tcColor0;
#define IN_tcColor0 tcColor0
in vec2 tcColor1;
#define IN_tcColor1 tcColor1
in vec2 tcDepth0;
#define IN_tcDepth0 tcDepth0
in vec2 tcDepth1;
#define IN_tcDepth1 tcDepth1
in vec2 tcDepth2;
#define IN_tcDepth2 tcDepth2
in vec2 tcDepth3;
#define IN_tcDepth3 tcDepth3
void main()
{
//return vec4( 1.0, 0.0, 1.0, 1.0 );
vec2 dofRowDelta = vec2( 0, 0.25 / targetSize.y );
//vec2 dofEqWorld = vec2( -60, 1.0 );
half3 color;
half maxCoc;
vec4 depth;
half4 viewCoc;
half4 sceneCoc;
half4 curCoc;
half4 coc;
vec2 rowOfs[4];
// "rowOfs" reduces how many moves PS2.0 uses to emulate swizzling.
rowOfs[0] = vec2(0);
rowOfs[1] = dofRowDelta.xy;
rowOfs[2] = dofRowDelta.xy * 2;
rowOfs[3] = dofRowDelta.xy * 3;
// Use bilinear filtering to average 4 color samples for free.
color = half3(0);
color += texture( colorSampler, IN_tcColor0.xy + rowOfs[0] ).rgb;
color += texture( colorSampler, IN_tcColor1.xy + rowOfs[0] ).rgb;
color += texture( colorSampler, IN_tcColor0.xy + rowOfs[2] ).rgb;
color += texture( colorSampler, IN_tcColor1.xy + rowOfs[2] ).rgb;
color /= 4;
// Process 4 samples at a time to use vector hardware efficiently.
// The CoC will be 1 if the depth is negative, so use "min" to pick
// between "sceneCoc" and "viewCoc".
for ( int i = 0; i < 4; i++ )
{
depth[0] = prepassUncondition( depthSampler, ( IN_tcDepth0.xy + rowOfs[i] ) ).w;
depth[1] = prepassUncondition( depthSampler, ( IN_tcDepth1.xy + rowOfs[i] ) ).w;
depth[2] = prepassUncondition( depthSampler, ( IN_tcDepth2.xy + rowOfs[i] ) ).w;
depth[3] = prepassUncondition( depthSampler, ( IN_tcDepth3.xy + rowOfs[i] ) ).w;
coc[i] = clamp( dofEqWorld.x * depth + dofEqWorld.y, 0.0, maxWorldCoC );
}
/*
depth[0] = texture( depthSampler, pixel.tcDepth0.xy + rowOfs[0] ).r;
depth[1] = texture( depthSampler, pixel.tcDepth1.xy + rowOfs[0] ).r;
depth[2] = texture( depthSampler, pixel.tcDepth2.xy + rowOfs[0] ).r;
depth[3] = texture( depthSampler, pixel.tcDepth3.xy + rowOfs[0] ).r;
viewCoc = saturate( dofEqWeapon.x * -depth + dofEqWeapon.y );
sceneCoc = saturate( dofEqWorld.x * depth + dofEqWorld.y );
curCoc = min( viewCoc, sceneCoc );
coc = curCoc;
depth[0] = texture( depthSampler, pixel.tcDepth0.xy + rowOfs[1] ).r;
depth[1] = texture( depthSampler, pixel.tcDepth1.xy + rowOfs[1] ).r;
depth[2] = texture( depthSampler, pixel.tcDepth2.xy + rowOfs[1] ).r;
depth[3] = texture( depthSampler, pixel.tcDepth3.xy + rowOfs[1] ).r;
viewCoc = saturate( dofEqWeapon.x * -depth + dofEqWeapon.y );
sceneCoc = saturate( dofEqWorld.x * depth + dofEqWorld.y );
curCoc = min( viewCoc, sceneCoc );
coc = max( coc, curCoc );
depth[0] = texture( depthSampler, pixel.tcDepth0.xy + rowOfs[2] ).r;
depth[1] = texture( depthSampler, pixel.tcDepth1.xy + rowOfs[2] ).r;
depth[2] = texture( depthSampler, pixel.tcDepth2.xy + rowOfs[2] ).r;
depth[3] = texture( depthSampler, pixel.tcDepth3.xy + rowOfs[2] ).r;
viewCoc = saturate( dofEqWeapon.x * -depth + dofEqWeapon.y );
sceneCoc = saturate( dofEqWorld.x * depth + dofEqWorld.y );
curCoc = min( viewCoc, sceneCoc );
coc = max( coc, curCoc );
depth[0] = texture( depthSampler, pixel.tcDepth0.xy + rowOfs[3] ).r;
depth[1] = texture( depthSampler, pixel.tcDepth1.xy + rowOfs[3] ).r;
depth[2] = texture( depthSampler, pixel.tcDepth2.xy + rowOfs[3] ).r;
depth[3] = texture( depthSampler, pixel.tcDepth3.xy + rowOfs[3] ).r;
viewCoc = saturate( dofEqWeapon.x * -depth + dofEqWeapon.y );
sceneCoc = saturate( dofEqWorld.x * depth + dofEqWorld.y );
curCoc = min( viewCoc, sceneCoc );
coc = max( coc, curCoc );
*/
maxCoc = max( max( coc[0], coc[1] ), max( coc[2], coc[3] ) );
//OUT_FragColor0 = half4( 1.0, 0.0, 1.0, 1.0 );
OUT_FragColor0 = half4( color, maxCoc );
//OUT_FragColor0 = half4( color, 1.0f );
//OUT_FragColor0 = half4( maxCoc.rrr, 1.0 );
}

View file

@ -0,0 +1,67 @@
//-----------------------------------------------------------------------------
// 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 "../../../gl/torque.glsl"
in vec4 vPosition;
in vec2 vTexCoord0;
in vec3 vTexCoord1;
#define IN_pos vPosition
#define IN_tc vTexCoord0
#define IN_wsEyeRay vTexCoord1
#define OUT_position gl_Position
out vec2 tcColor0;
#define OUT_tcColor0 tcColor0
out vec2 tcColor1;
#define OUT_tcColor1 tcColor1
out vec2 tcDepth0;
#define OUT_tcDepth0 tcDepth0
out vec2 tcDepth1;
#define OUT_tcDepth1 tcDepth1
out vec2 tcDepth2;
#define OUT_tcDepth2 tcDepth2
out vec2 tcDepth3;
#define OUT_tcDepth3 tcDepth3
uniform vec4 rtParams0;
uniform vec2 oneOverTargetSize;
void main()
{
OUT_position = IN_pos;
vec2 uv = viewportCoordToRenderTarget( IN_tc, rtParams0 );
//OUT_position = tMul( IN_pos, modelView );
OUT_tcColor1 = uv + vec2( +1.0, -0.0 ) * oneOverTargetSize;
OUT_tcColor0 = uv + vec2( -1.0, -0.0 ) * oneOverTargetSize;
OUT_tcDepth0 = uv + vec2( -0.5, -0.0 ) * oneOverTargetSize;
OUT_tcDepth1 = uv + vec2( -1.5, -0.0 ) * oneOverTargetSize;
OUT_tcDepth2 = uv + vec2( +1.5, -0.0 ) * oneOverTargetSize;
OUT_tcDepth3 = uv + vec2( +2.5, -0.0 ) * oneOverTargetSize;
correctSSP(gl_Position);
}

View file

@ -0,0 +1,145 @@
//-----------------------------------------------------------------------------
// 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 "../../gl/postFX.glsl"
uniform sampler2D colorSampler; // Original source image
uniform sampler2D smallBlurSampler; // Output of SmallBlurPS()
uniform sampler2D largeBlurSampler; // Blurred output of DofDownsample()
uniform sampler2D depthSampler; //
uniform vec2 oneOverTargetSize;
uniform vec4 dofLerpScale;
uniform vec4 dofLerpBias;
uniform vec3 dofEqFar;
uniform float maxFarCoC;
//static float d0 = 0.1;
//static float d1 = 0.1;
//static float d2 = 0.8;
//static vec4 dofLerpScale = vec4( -1.0 / d0, -1.0 / d1, -1.0 / d2, 1.0 / d2 );
//static vec4 dofLerpBias = vec4( 1.0, (1.0 - d2) / d1, 1.0 / d2, (d2 - 1.0) / d2 );
//static vec3 dofEqFar = vec3( 2.0, 0.0, 1.0 );
vec4 tex2Doffset( sampler2D s, vec2 tc, vec2 offset )
{
return texture( s, tc + offset * oneOverTargetSize );
}
half3 GetSmallBlurSample( vec2 tc )
{
half3 sum;
const half weight = 4.0 / 17;
sum = half3(0); // Unblurred sample done by alpha blending
//sum += weight * tex2Doffset( colorSampler, tc, vec2( 0, 0 ) ).rgb;
sum += weight * tex2Doffset( colorSampler, tc, vec2( +0.5, -1.5 ) ).rgb;
sum += weight * tex2Doffset( colorSampler, tc, vec2( -1.5, -0.5 ) ).rgb;
sum += weight * tex2Doffset( colorSampler, tc, vec2( -0.5, +1.5 ) ).rgb;
sum += weight * tex2Doffset( colorSampler, tc, vec2( +1.5, +0.5 ) ).rgb;
return sum;
}
half4 InterpolateDof( half3 small, half3 med, half3 large, half t )
{
//t = 2;
half4 weights;
half3 color;
half alpha;
// Efficiently calculate the cross-blend weights for each sample.
// Let the unblurred sample to small blur fade happen over distance
// d0, the small to medium blur over distance d1, and the medium to
// large blur over distance d2, where d0 + d1 + d2 = 1.
//vec4 dofLerpScale = vec4( -1 / d0, -1 / d1, -1 / d2, 1 / d2 );
//vec4 dofLerpBias = vec4( 1, (1 d2) / d1, 1 / d2, (d2 1) / d2 );
weights = saturate( t * dofLerpScale + dofLerpBias );
weights.yz = min( weights.yz, 1 - weights.xy );
// Unblurred sample with weight "weights.x" done by alpha blending
color = weights.y * small + weights.z * med + weights.w * large;
//color = med;
alpha = dot( weights.yzw, half3( 16.0 / 17, 1.0, 1.0 ) );
//alpha = 0.0;
return half4( color, alpha );
}
void main()
{
//return half4( 1,0,1,1 );
//return half4( texture( colorSampler, IN_uv0 ).rgb, 1.0 );
//return half4( texture( colorSampler, texCoords ).rgb, 0 );
half3 small;
half4 med;
half3 large;
half depth;
half nearCoc;
half farCoc;
half coc;
small = GetSmallBlurSample( IN_uv0 );
//small = half3( 1,0,0 );
//return half4( small, 1.0 );
med = texture( smallBlurSampler, IN_uv1 );
//med.rgb = half3( 0,1,0 );
//return half4(med.rgb, 0.0);
large = texture( largeBlurSampler, IN_uv2 ).rgb;
//large = half3( 0,0,1 );
//return large;
//return half4(large.rgb,1.0);
nearCoc = med.a;
// Since the med blur texture is screwed up currently
// replace it with the large, but this needs to be fixed.
//med.rgb = large;
//nearCoc = 0;
depth = prepassUncondition( depthSampler, IN_uv3 ).w;
//return half4(depth.rrr,1);
//return half4(nearCoc.rrr,1.0);
if (depth > 0.999 )
{
coc = nearCoc; // We don't want to blur the sky.
//coc = 0;
}
else
{
// dofEqFar.x and dofEqFar.y specify the linear ramp to convert
// to depth for the distant out-of-focus region.
// dofEqFar.z is the ratio of the far to the near blur radius.
farCoc = clamp( dofEqFar.x * depth + dofEqFar.y, 0.0, maxFarCoC );
coc = max( nearCoc, farCoc * dofEqFar.z );
//coc = nearCoc;
}
//coc = nearCoc;
//coc = farCoc;
//return half4(coc.rrr,0.5);
//return half4(farCoc.rrr,1);
//return half4(nearCoc.rrr,1);
//return half4( 1,0,1,0 );
OUT_FragColor0 = InterpolateDof( small, med.rgb, large, coc );
}

View file

@ -0,0 +1,71 @@
//-----------------------------------------------------------------------------
// 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 "../../../gl/torque.glsl"
#include "../../gl/postFX.glsl"
uniform vec4 rtParams0;
uniform vec4 rtParams1;
uniform vec4 rtParams2;
uniform vec4 rtParams3;
uniform vec2 oneOverTargetSize;
void main()
{
/*
OUT.hpos = IN_pos;
OUT_uv0 = IN_uv;
OUT_uv1 = IN_uv;
OUT_uv2 = IN_uv;
OUT_uv3 = IN_uv;
*/
/*
OUT_hpos = IN_pos;
OUT_uv0 = IN_uv + rtParams0.xy;
OUT_uv1 = IN_uv + rtParams1.xy;
OUT_uv2 = IN_uv + rtParams2.xy;
OUT_uv3 = IN_uv + rtParams3.xy;
*/
/*
OUT_hpos = IN_pos;
OUT_uv0 = IN_uv * rtParams0.zw;
OUT_uv1 = IN_uv * rtParams1.zw;
OUT_uv2 = IN_uv * rtParams2.zw;
OUT_uv3 = IN_uv * rtParams3.zw;
*/
OUT_hpos = IN_pos;
OUT_uv0 = viewportCoordToRenderTarget( IN_uv, rtParams0 );
OUT_uv1 = viewportCoordToRenderTarget( IN_uv, rtParams1 ); // + vec2( -5, 1 ) * oneOverTargetSize;
OUT_uv2 = viewportCoordToRenderTarget( IN_uv, rtParams2 );
OUT_uv3 = viewportCoordToRenderTarget( IN_uv, rtParams3 );
OUT_wsEyeRay = IN_wsEyeRay;
correctSSP(gl_Position);
}

View file

@ -0,0 +1,68 @@
//-----------------------------------------------------------------------------
// 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"
in vec3 wsEyeRay;
#define IN_wsEyeRay wsEyeRay
in vec2 uv0;
#define IN_uv0 uv0
in vec2 uv1;
#define IN_uv1 uv1
in vec2 uv2;
#define IN_uv2 uv2
in vec2 uv3;
#define IN_uv3 uv3
in vec2 uv4;
#define IN_uv4 uv4
in vec2 uv5;
#define IN_uv5 uv5
in vec2 uv6;
#define IN_uv6 uv6
in vec2 uv7;
#define IN_uv7 uv7
#define OUT OUT_FragColor0
uniform sampler2D diffuseMap;
void main()
{
vec4 kernel = vec4( 0.175, 0.275, 0.375, 0.475 ) * 0.5 / 1.3; //25f;
OUT = vec4(0);
OUT += texture( diffuseMap, IN_uv0 ) * kernel.x;
OUT += texture( diffuseMap, IN_uv1 ) * kernel.y;
OUT += texture( diffuseMap, IN_uv2 ) * kernel.z;
OUT += texture( diffuseMap, IN_uv3 ) * kernel.w;
OUT += texture( diffuseMap, IN_uv4 ) * kernel.x;
OUT += texture( diffuseMap, IN_uv5 ) * kernel.y;
OUT += texture( diffuseMap, IN_uv6 ) * kernel.z;
OUT += texture( diffuseMap, IN_uv7 ) * kernel.w;
// Calculate a lumenance value in the alpha so we
// can use alpha test to save fillrate.
//vec3 rgb2lum = vec3( 0.30, 0.59, 0.11 );
//OUT.a = dot( OUT.rgb, rgb2lum );
}

View file

@ -0,0 +1,91 @@
//-----------------------------------------------------------------------------
// 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 "../../../gl/torque.glsl"
in vec4 vPosition;
in vec2 vTexCoord0;
in vec3 vTexCoord1;
#define IN_pos vPosition
#define _IN_uv vTexCoord0
#define IN_wsEyeRay vTexCoord1
#define OUT_hpos gl_Position
out vec3 wsEyeRay;
#define OUT_wsEyeRay wsEyeRay
out vec2 uv0;
#define OUT_uv0 uv0
out vec2 uv1;
#define OUT_uv1 uv1
out vec2 uv2;
#define OUT_uv2 uv2
out vec2 uv3;
#define OUT_uv3 uv3
out vec2 uv4;
#define OUT_uv4 uv4
out vec2 uv5;
#define OUT_uv5 uv5
out vec2 uv6;
#define OUT_uv6 uv6
out vec2 uv7;
#define OUT_uv7 uv7
uniform vec2 texSize0;
uniform vec4 rtParams0;
uniform vec2 oneOverTargetSize;
void main()
{
OUT_hpos = IN_pos;
vec2 IN_uv = viewportCoordToRenderTarget( _IN_uv, rtParams0 );
// I don't know why this offset is necessary, but it is.
//IN_uv = IN_uv * oneOverTargetSize;
OUT_uv0 = IN_uv + ( ( BLUR_DIR * 3.5f ) / texSize0 );
OUT_uv1 = IN_uv + ( ( BLUR_DIR * 2.5f ) / texSize0 );
OUT_uv2 = IN_uv + ( ( BLUR_DIR * 1.5f ) / texSize0 );
OUT_uv3 = IN_uv + ( ( BLUR_DIR * 0.5f ) / texSize0 );
OUT_uv4 = IN_uv - ( ( BLUR_DIR * 3.5f ) / texSize0 );
OUT_uv5 = IN_uv - ( ( BLUR_DIR * 2.5f ) / texSize0 );
OUT_uv6 = IN_uv - ( ( BLUR_DIR * 1.5f ) / texSize0 );
OUT_uv7 = IN_uv - ( ( BLUR_DIR * 0.5f ) / texSize0 );
/*
OUT_uv0 = viewportCoordToRenderTarget( OUT_uv0, rtParams0 );
OUT_uv1 = viewportCoordToRenderTarget( OUT_uv1, rtParams0 );
OUT_uv2 = viewportCoordToRenderTarget( OUT_uv2, rtParams0 );
OUT_uv3 = viewportCoordToRenderTarget( OUT_uv3, rtParams0 );
OUT_uv4 = viewportCoordToRenderTarget( OUT_uv4, rtParams0 );
OUT_uv5 = viewportCoordToRenderTarget( OUT_uv5, rtParams0 );
OUT_uv6 = viewportCoordToRenderTarget( OUT_uv6, rtParams0 );
OUT_uv7 = viewportCoordToRenderTarget( OUT_uv7, rtParams0 );
*/
correctSSP(gl_Position);
}

View file

@ -0,0 +1,69 @@
//-----------------------------------------------------------------------------
// 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 "../../../gl/torque.glsl"
#include "../../gl/postFX.glsl"
uniform vec4 rtParams0;
uniform vec4 rtParams1;
uniform vec4 rtParams2;
uniform vec4 rtParams3;
void main()
{
/*
OUT.hpos = IN_pos;
OUT_uv0 = IN_uv;
OUT_uv1 = IN_uv;
OUT_uv2 = IN_uv;
OUT_uv3 = IN_uv;
*/
/*
OUT_hpos = IN_pos;
OUT_uv0 = IN_uv + rtParams0.xy;
OUT_uv1 = IN_uv + rtParams1.xy;
OUT_uv2 = IN_uv + rtParams2.xy;
OUT_uv3 = IN_uv + rtParams3.xy;
*/
/*
OUT_hpos = IN_pos;
OUT_uv0 = IN_uv * rtParams0.zw;
OUT_uv1 = IN_uv * rtParams1.zw;
OUT_uv2 = IN_uv * rtParams2.zw;
OUT_uv3 = IN_uv * rtParams3.zw;
*/
OUT_hpos = IN_pos;
OUT_uv0 = viewportCoordToRenderTarget( IN_uv, rtParams0 );
OUT_uv1 = viewportCoordToRenderTarget( IN_uv, rtParams1 );
OUT_uv2 = viewportCoordToRenderTarget( IN_uv, rtParams2 );
OUT_uv3 = viewportCoordToRenderTarget( IN_uv, rtParams3 );
OUT_wsEyeRay = IN_wsEyeRay;
correctSSP(gl_Position);
}

View file

@ -0,0 +1,44 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
// This vertex and pixel shader applies a 3 x 3 blur to the image in
// colorMapSampler, which is the same size as the render target.
// The sample weights are 1/16 in the corners, 2/16 on the edges,
// and 4/16 in the center.
#include "../../../gl/hlslCompat.glsl"
uniform sampler2D colorSampler; // Output of DofNearCoc()
in vec4 texCoords;
#define IN_texCoords texCoords
void main()
{
vec4 color;
color = vec4(0.0);
color += texture( colorSampler, IN_texCoords.xz );
color += texture( colorSampler, IN_texCoords.yz );
color += texture( colorSampler, IN_texCoords.xw );
color += texture( colorSampler, IN_texCoords.yw );
OUT_FragColor0 = color / 4.0;
}

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.
//-----------------------------------------------------------------------------
// This vertex and pixel shader applies a 3 x 3 blur to the image in
// colorMapSampler, which is the same size as the render target.
// The sample weights are 1/16 in the corners, 2/16 on the edges,
// and 4/16 in the center.
#include "../../../gl/hlslCompat.glsl"
#include "../../../gl/torque.glsl"
in vec4 vPosition;
in vec2 vTexCoord0;
#define IN_position vPosition
#define IN_texCoords vTexCoord0
#define OUT_position gl_Position
out vec4 texCoords;
#define OUT_texCoords texCoords
uniform vec2 oneOverTargetSize;
uniform vec4 rtParams0;
void main()
{
const vec4 halfPixel = vec4( -0.5, 0.5, -0.5, 0.5 );
OUT_position = IN_position; //Transform_ObjectToClip( IN_position );
//vec2 uv = IN_texCoords + rtParams0.xy;
vec2 uv = viewportCoordToRenderTarget( IN_texCoords, rtParams0 );
OUT_texCoords = uv.xxyy + halfPixel * oneOverTargetSize.xxyy;
correctSSP(gl_Position);
}

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 "../../../gl/hlslCompat.glsl"
#include "shadergen:/autogenConditioners.h"
in vec2 uv0;
#define IN_uv0 uv0
uniform sampler2D edgeBuffer;
void main()
{
OUT_FragColor0 = vec4( texture( edgeBuffer, IN_uv0 ).rrr, 1.0 );
}

View file

@ -0,0 +1,68 @@
//-----------------------------------------------------------------------------
// 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 "../../gl/postFX.glsl"
uniform sampler2D edgeBuffer;
uniform sampler2D backBuffer;
uniform vec2 targetSize;
void main()
{
vec2 pixelSize = 1.0 / targetSize;
// Sample edge buffer, bail if not on an edge
float edgeSample = texture(edgeBuffer, IN_uv0).r;
clip(edgeSample - 1e-6);
// Ok we're on an edge, so multi-tap sample, average, and return
vec2 offsets[9] = vec2[](
vec2( 0.0, 0.0),
vec2(-1.0, -1.0),
vec2( 0.0, -1.0),
vec2( 1.0, -1.0),
vec2( 1.0, 0.0),
vec2( 1.0, 1.0),
vec2( 0.0, 1.0),
vec2(-1.0, 1.0),
vec2(-1.0, 0.0)
);
vec4 accumColor = vec4(0.0);
for(int i = 0; i < 9; i++)
{
// Multiply the intensity of the edge, by the UV, so that things which maybe
// aren't quite full edges get sub-pixel sampling to reduce artifacts
// Scaling offsets by 0.5 to reduce the range bluriness from extending to
// far outward from the edge.
vec2 offsetUV = IN_uv1 + edgeSample * ( offsets[i] * 0.5 ) * pixelSize;//rtWidthHeightInvWidthNegHeight.zw;
//offsetUV *= 0.999;
accumColor+= texture(backBuffer, offsetUV);
}
accumColor /= 9.0;
OUT_FragColor0 = accumColor;
}

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 "../../../gl/hlslCompat.glsl"
#include "../../../gl/torque.glsl"
#include "../../gl/postFX.glsl"
uniform vec4 rtParams0;
uniform vec4 rtParams1;
uniform vec4 rtParams2;
uniform vec4 rtParams3;
void main()
{
OUT_hpos = IN_pos;
OUT_uv0 = viewportCoordToRenderTarget( IN_uv, rtParams0 );
OUT_uv1 = viewportCoordToRenderTarget( IN_uv, rtParams1 );
OUT_uv2 = viewportCoordToRenderTarget( IN_uv, rtParams2 );
OUT_uv3 = viewportCoordToRenderTarget( IN_uv, rtParams3 );
OUT_wsEyeRay = IN_wsEyeRay;
correctSSP(gl_Position);
}

View file

@ -0,0 +1,94 @@
//-----------------------------------------------------------------------------
// 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"
// GPU Gems 3, pg 443-444
float GetEdgeWeight(vec2 uv0, in sampler2D prepassBuffer, in vec2 targetSize)
{
vec2 offsets[9] = vec2[](
vec2( 0.0, 0.0),
vec2(-1.0, -1.0),
vec2( 0.0, -1.0),
vec2( 1.0, -1.0),
vec2( 1.0, 0.0),
vec2( 1.0, 1.0),
vec2( 0.0, 1.0),
vec2(-1.0, 1.0),
vec2(-1.0, 0.0)
);
vec2 PixelSize = 1.0 / targetSize;
float Depth[9];
vec3 Normal[9];
for(int i = 0; i < 9; i++)
{
vec2 uv = uv0 + offsets[i] * PixelSize;
vec4 gbSample = prepassUncondition( prepassBuffer, uv );
Depth[i] = gbSample.a;
Normal[i] = gbSample.rgb;
}
vec4 Deltas1 = vec4(Depth[1], Depth[2], Depth[3], Depth[4]);
vec4 Deltas2 = vec4(Depth[5], Depth[6], Depth[7], Depth[8]);
Deltas1 = abs(Deltas1 - Depth[0]);
Deltas2 = abs(Depth[0] - Deltas2);
vec4 maxDeltas = max(Deltas1, Deltas2);
vec4 minDeltas = max(min(Deltas1, Deltas2), 0.00001);
vec4 depthResults = step(minDeltas * 25.0, maxDeltas);
Deltas1.x = dot(Normal[1], Normal[0]);
Deltas1.y = dot(Normal[2], Normal[0]);
Deltas1.z = dot(Normal[3], Normal[0]);
Deltas1.w = dot(Normal[4], Normal[0]);
Deltas2.x = dot(Normal[5], Normal[0]);
Deltas2.y = dot(Normal[6], Normal[0]);
Deltas2.z = dot(Normal[7], Normal[0]);
Deltas2.w = dot(Normal[8], Normal[0]);
Deltas1 = abs(Deltas1 - Deltas2);
vec4 normalResults = step(0.4, Deltas1);
normalResults = max(normalResults, depthResults);
return dot(normalResults, vec4(1.0, 1.0, 1.0, 1.0)) * 0.25;
}
in vec2 uv0;
#define IN_uv0 uv0
uniform sampler2D prepassBuffer;
uniform vec2 targetSize;
void main()
{
OUT_FragColor0 = vec4( GetEdgeWeight(IN_uv0, prepassBuffer, targetSize ) );//rtWidthHeightInvWidthNegHeight.zw);
}

View file

@ -44,7 +44,7 @@ Etc.
(2.) (2.)
Then include this file, Then include this file,
#include "Fxaa3_11.h" include "Fxaa3_11.h"
(3.) (3.)
Then call the FXAA pixel shader from within your desired shader. Then call the FXAA pixel shader from within your desired shader.

View file

@ -0,0 +1,123 @@
//-----------------------------------------------------------------------------
// 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 FXAA_PC 1
#define FXAA_GLSL_130 1
#define FXAA_QUALITY__PRESET 12
#define FXAA_GREEN_AS_LUMA 1
#include "../Fxaa3_11.h"
#include "../../../gl/hlslCompat.glsl"
uniform sampler2D colorTex ;
uniform vec2 oneOverTargetSize;
in vec4 hpos;
in vec2 uv0;
void main()
{
OUT_FragColor0 = FxaaPixelShader(
uv0, // vertex position
vec4(0), // Unused... console stuff
colorTex, // The color back buffer
colorTex, // Used for 360 optimization
colorTex, // Used for 360 optimization
oneOverTargetSize,
vec4(0), // Unused... console stuff
vec4(0), // Unused... console stuff
vec4(0), // Unused... console stuff
//
// Only used on FXAA Quality.
// This used to be the FXAA_QUALITY__SUBPIX define.
// It is here now to allow easier tuning.
// Choose the amount of sub-pixel aliasing removal.
// This can effect sharpness.
// 1.00 - upper limit (softer)
// 0.75 - default amount of filtering
// 0.50 - lower limit (sharper, less sub-pixel aliasing removal)
// 0.25 - almost off
// 0.00 - completely off
0.75,
//
// Only used on FXAA Quality.
// This used to be the FXAA_QUALITY__EDGE_THRESHOLD define.
// It is here now to allow easier tuning.
// The minimum amount of local contrast required to apply algorithm.
// 0.333 - too little (faster)
// 0.250 - low quality
// 0.166 - default
// 0.125 - high quality
// 0.063 - overkill (slower)
0.166,
//
// Only used on FXAA Quality.
// This used to be the FXAA_QUALITY__EDGE_THRESHOLD_MIN define.
// It is here now to allow easier tuning.
// Trims the algorithm from processing darks.
// 0.0833 - upper limit (default, the start of visible unfiltered edges)
// 0.0625 - high quality (faster)
// 0.0312 - visible limit (slower)
// Special notes when using FXAA_GREEN_AS_LUMA,
// Likely want to set this to zero.
// As colors that are mostly not-green
// will appear very dark in the green channel!
// Tune by looking at mostly non-green content,
// then start at zero and increase until aliasing is a problem.
0,
//
// Only used on FXAA Console.
// This used to be the FXAA_CONSOLE__EDGE_SHARPNESS define.
// It is here now to allow easier tuning.
// This does not effect PS3, as this needs to be compiled in.
// Use FXAA_CONSOLE__PS3_EDGE_SHARPNESS for PS3.
// Due to the PS3 being ALU bound,
// there are only three safe values here: 2 and 4 and 8.
// These options use the shaders ability to a free *|/ by 2|4|8.
// For all other platforms can be a non-power of two.
// 8.0 is sharper (default!!!)
// 4.0 is softer
// 2.0 is really soft (good only for vector graphics inputs)
8,
0, // Unused... console stuff
0, // Unused... console stuff
vec4(0) // Unused... console stuff
);
}

View file

@ -0,0 +1,40 @@
//-----------------------------------------------------------------------------
// 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 "../../../gl/torque.glsl"
in vec4 vPosition;
in vec2 vTexCoord0;
uniform vec4 rtParams0;
out vec4 hpos;
out vec2 uv0;
void main()
{
gl_Position = vPosition;
hpos = gl_Position;
uv0 = viewportCoordToRenderTarget( vTexCoord0, rtParams0 );
correctSSP(gl_Position);
}

View file

@ -0,0 +1,60 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
// Based on 'Cubic Lens Distortion HLSL Shader' by François Tarlier
// www.francois-tarlier.com/blog/index.php/2009/11/cubic-lens-distortion-shader
#include "./postFx.glsl"
#include "../../gl/torque.glsl"
#include "../../gl/hlslCompat.glsl"
uniform sampler2D backBuffer;
uniform float distCoeff;
uniform float cubeDistort;
uniform vec3 colorDistort;
void main()
{
vec2 tex = IN_uv0;
float f = 0;
float r2 = (tex.x - 0.5) * (tex.x - 0.5) + (tex.y - 0.5) * (tex.y - 0.5);
// Only compute the cubic distortion if necessary.
if ( cubeDistort == 0.0 )
f = 1 + r2 * distCoeff;
else
f = 1 + r2 * (distCoeff + cubeDistort * sqrt(r2));
// Distort each color channel seperately to get a chromatic distortion effect.
vec3 outColor;
vec3 distort = vec3(f) + colorDistort;
for ( int i=0; i < 3; i++ )
{
float x = distort[i] * ( tex.x - 0.5 ) + 0.5;
float y = distort[i] * ( tex.y - 0.5 ) + 0.5;
outColor[i] = tex2Dlod( backBuffer, vec4(x,y,0,0) )[i];
}
OUT_FragColor0 = vec4( outColor.rgb, 1 );
}

View file

@ -0,0 +1,37 @@
//-----------------------------------------------------------------------------
// 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 "./postFx.glsl"
#include "../../gl/torque.glsl"
#include "../../gl/hlslCompat.glsl"
uniform float damageFlash;
uniform float whiteOut;
uniform sampler2D backBuffer;
void main()
{
vec4 color1 = texture(backBuffer, IN_uv0);
vec4 color2 = color1 * MUL_COLOR;
vec4 damage = mix(color1,color2,damageFlash);
OUT_FragColor0 = mix(damage,WHITE_COLOR,whiteOut);
}

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 "../../gl/hlslCompat.glsl"
#include "shadergen:/autogenConditioners.h"
#include "../../gl/torque.glsl"
uniform sampler2D prepassTex ;
uniform vec3 eyePosWorld;
uniform vec4 fogColor;
uniform vec3 fogData;
uniform vec4 rtParams0;
in vec2 uv0;
in vec3 wsEyeRay;
void main()
{
//vec2 prepassCoord = ( uv0.xy * rtParams0.zw ) + rtParams0.xy;
float depth = prepassUncondition( prepassTex, uv0 ).w;
//return vec4( depth, 0, 0, 0.7 );
float factor = computeSceneFog( eyePosWorld,
eyePosWorld + ( wsEyeRay * depth ),
fogData.x,
fogData.y,
fogData.z );
OUT_FragColor0 = hdrEncode( vec4( fogColor.rgb, 1.0 - saturate( factor ) ) );
}

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 "../../gl/hlslCompat.glsl"
#include "../../gl/torque.glsl"
#include "shadergen:/autogenConditioners.h"
uniform sampler2D backBuffer;
uniform sampler1D colorCorrectionTex;
uniform float OneOverGamma;
in vec2 uv0;
void main()
{
vec4 color = texture(backBuffer, uv0.xy);
// Apply the color correction.
color.r = texture( colorCorrectionTex, color.r ).r;
color.g = texture( colorCorrectionTex, color.g ).g;
color.b = texture( colorCorrectionTex, color.b ).b;
// Apply gamma correction
color.rgb = pow( abs(color.rgb), vec3(OneOverGamma) );
OUT_FragColor0 = color;
}

View file

@ -0,0 +1,58 @@
//-----------------------------------------------------------------------------
// 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"
uniform sampler2D diffuseMap ;
in vec4 hpos; //POSITION;
in vec2 uv0; //TEXCOORD0;
in vec2 uv1; //TEXCOORD1;
in vec2 uv2; //TEXCOORD2;
in vec2 uv3; //TEXCOORD3;
in vec2 uv4; //TEXCOORD4;
in vec2 uv5; //TEXCOORD5;
in vec2 uv6; //TEXCOORD6;
in vec2 uv7; //TEXCOORD7;
void main()
{
vec4 kernel = vec4( 0.175, 0.275, 0.375, 0.475 ) * 0.5f;
vec4 OUT = vec4(0);
OUT += texture( diffuseMap, uv0 ) * kernel.x;
OUT += texture( diffuseMap, uv1 ) * kernel.y;
OUT += texture( diffuseMap, uv2 ) * kernel.z;
OUT += texture( diffuseMap, uv3 ) * kernel.w;
OUT += texture( diffuseMap, uv4 ) * kernel.x;
OUT += texture( diffuseMap, uv5 ) * kernel.y;
OUT += texture( diffuseMap, uv6 ) * kernel.z;
OUT += texture( diffuseMap, uv7 ) * kernel.w;
// Calculate a lumenance value in the alpha so we
// can use alpha test to save fillrate.
vec3 rgb2lum = vec3( 0.30, 0.59, 0.11 );
OUT.a = dot( OUT.rgb, rgb2lum );
OUT_FragColor0 = OUT;
}

View file

@ -0,0 +1,59 @@
//-----------------------------------------------------------------------------
// 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 "../../gl/torque.glsl"
in vec4 vPosition;
in vec2 vTexCoord0;
uniform vec2 texSize0;
out vec4 hpos; //POSITION;
out vec2 uv0; //TEXCOORD0;
out vec2 uv1; //TEXCOORD1;
out vec2 uv2; //TEXCOORD2;
out vec2 uv3; //TEXCOORD3;
out vec2 uv4; //TEXCOORD4;
out vec2 uv5; //TEXCOORD5;
out vec2 uv6; //TEXCOORD6;
out vec2 uv7; //TEXCOORD7;
void main()
{
gl_Position = vPosition;
hpos = gl_Position;
vec2 uv = vTexCoord0 + (0.5f / texSize0);
uv0 = uv + ( ( BLUR_DIR * 3.5f ) / texSize0 );
uv1 = uv + ( ( BLUR_DIR * 2.5f ) / texSize0 );
uv2 = uv + ( ( BLUR_DIR * 1.5f ) / texSize0 );
uv3 = uv + ( ( BLUR_DIR * 0.5f ) / texSize0 );
uv4 = uv - ( ( BLUR_DIR * 3.5f ) / texSize0 );
uv5 = uv - ( ( BLUR_DIR * 2.5f ) / texSize0 );
uv6 = uv - ( ( BLUR_DIR * 1.5f ) / texSize0 );
uv7 = uv - ( ( BLUR_DIR * 0.5f ) / texSize0 );
correctSSP(gl_Position);
}

View file

@ -0,0 +1,76 @@
//-----------------------------------------------------------------------------
// 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 "../../gl/torque.glsl"
#include "shadergen:/autogenConditioners.h"
#include "postFX.glsl"
#undef IN_uv0
#define _IN_uv0 uv0
uniform mat4 matPrevScreenToWorld;
uniform mat4 matWorldToScreen;
// Passed in from setShaderConsts()
uniform float velocityMultiplier;
uniform sampler2D backBuffer;
uniform sampler2D prepassTex;
void main()
{
vec2 IN_uv0 = _IN_uv0;
float samples = 5;
// First get the prepass texture for uv channel 0
vec4 prepass = prepassUncondition( prepassTex, IN_uv0 );
// Next extract the depth
float depth = prepass.a;
// Create the screen position
vec4 screenPos = vec4(IN_uv0.x*2-1, IN_uv0.y*2-1, depth*2-1, 1);
// Calculate the world position
vec4 D = tMul(screenPos, matWorldToScreen);
vec4 worldPos = D / D.w;
// Now calculate the previous screen position
vec4 previousPos = tMul( worldPos, matPrevScreenToWorld );
previousPos /= previousPos.w;
// Calculate the XY velocity
vec2 velocity = ((screenPos - previousPos) / velocityMultiplier).xy;
// Generate the motion blur
vec4 color = texture(backBuffer, IN_uv0);
IN_uv0 += velocity;
for(int i = 1; i<samples; ++i, IN_uv0 += velocity)
{
vec4 currentColor = texture(backBuffer, IN_uv0);
color += currentColor;
}
OUT_FragColor0 = color / samples;
}

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.
//-----------------------------------------------------------------------------
#include "../../gl/hlslCompat.glsl"
in vec2 uv0;
uniform sampler2D inputTex ;
void main()
{
OUT_FragColor0 = texture( inputTex, uv0 );
}

View file

@ -0,0 +1,63 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
#ifdef TORQUE_VERTEX_SHADER
in vec4 vPosition;
in vec2 vTexCoord0;
in vec3 vTexCoord1;
#define IN_pos vPosition
#define IN_uv vTexCoord0.st
#define IN_wsEyeRay vTexCoord1.xyz
out vec2 uv0;
out vec2 uv1;
out vec2 uv2;
out vec2 uv3;
out vec3 wsEyeRay;
#define OUT_uv0 uv0
#define OUT_uv1 uv1
#define OUT_uv2 uv2
#define OUT_uv3 uv3
#define OUT_wsEyeRay wsEyeRay
#define OUT_hpos gl_Position
#endif //TORQUE_VERTEX_SHADER
#ifdef TORQUE_PIXEL_SHADER
in vec2 uv0;
in vec2 uv1;
in vec2 uv2;
in vec2 uv3;
in vec3 wsEyeRay;
#define IN_uv0 uv0
#define IN_uv1 uv1
#define IN_uv2 uv2
#define IN_uv3 uv3
#define IN_wsEyeRay wsEyeRay
#endif//TORQUE_PIXEL_SHADER

View file

@ -0,0 +1,52 @@
//-----------------------------------------------------------------------------
// 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 "../../gl/torque.glsl"
in vec4 vPosition;
in vec2 vTexCoord0;
in vec3 vTexCoord1;
uniform vec4 rtParams0;
uniform vec4 rtParams1;
uniform vec4 rtParams2;
uniform vec4 rtParams3;
out vec2 uv0;
out vec2 uv1;
out vec2 uv2;
out vec2 uv3;
out vec3 wsEyeRay;
void main()
{
gl_Position = vPosition;
correctSSP(gl_Position);
uv0 = viewportCoordToRenderTarget( vTexCoord0, rtParams0 );
uv1 = viewportCoordToRenderTarget( vTexCoord0, rtParams1 );
uv2 = viewportCoordToRenderTarget( vTexCoord0, rtParams2 );
uv3 = viewportCoordToRenderTarget( vTexCoord0, rtParams3 );
wsEyeRay = vTexCoord1;
}

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 "../../gl/hlslCompat.glsl"
#include "../../gl/torque.glsl"
#include "shadergen:/autogenConditioners.h"
uniform float accumTime;
uniform vec2 projectionOffset;
uniform vec4 targetViewport;
uniform sampler2D inputTex;
in vec2 uv0;
#define IN_uv0 uv0
void main()
{
float speed = 2.0;
float distortion = 6.0;
float y = IN_uv0.y + (cos((IN_uv0.y+projectionOffset.y) * distortion + accumTime * speed) * 0.01);
float x = IN_uv0.x + (sin((IN_uv0.x+projectionOffset.x) * distortion + accumTime * speed) * 0.01);
// Clamp the calculated uv values to be within the target's viewport
y = clamp(y, targetViewport.y, targetViewport.w);
x = clamp(x, targetViewport.x, targetViewport.z);
OUT_FragColor0 = texture (inputTex, vec2(x, y));
}

View file

@ -0,0 +1,138 @@
//-----------------------------------------------------------------------------
// 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 "../../gl/torque.glsl"
#include "postFX.glsl"
#include "shadergen:/autogenConditioners.h"
//-----------------------------------------------------------------------------
// Defines
//-----------------------------------------------------------------------------
// oceanFogData
#define FOG_DENSITY waterFogData[0]
#define FOG_DENSITY_OFFSET waterFogData[1]
#define WET_DEPTH waterFogData[2]
#define WET_DARKENING waterFogData[3]
//-----------------------------------------------------------------------------
// Uniforms
//-----------------------------------------------------------------------------
uniform sampler2D prepassTex ;
uniform sampler2D backbuffer ;
uniform sampler1D waterDepthGradMap;
uniform vec3 eyePosWorld;
uniform vec3 ambientColor;
uniform vec4 waterColor;
uniform vec4 waterFogData;
uniform vec4 waterFogPlane;
uniform vec2 nearFar;
uniform vec4 rtParams0;
uniform float waterDepthGradMax;
void main()
{
//vec2 prepassCoord = IN_uv0;
//IN_uv0 = ( IN_uv0.xy * rtParams0.zw ) + rtParams0.xy;
float depth = prepassUncondition( prepassTex, IN_uv0 ).w;
//return vec4( depth.rrr, 1 );
// Skip fogging the extreme far plane so that
// the canvas clear color always appears.
//clip( 0.9 - depth );
// We assume that the eye position is below water because
// otherwise this shader/posteffect should not be active.
depth *= nearFar.y;
vec3 eyeRay = normalize( IN_wsEyeRay );
vec3 rayStart = eyePosWorld;
vec3 rayEnd = eyePosWorld + ( eyeRay * depth );
//return vec4( rayEnd, 1 );
vec4 plane = waterFogPlane; //vec4( 0, 0, 1, -waterHeight );
//plane.w -= 0.15;
float startSide = dot( plane.xyz, rayStart ) + plane.w;
if ( startSide > 0 )
{
rayStart.z -= ( startSide );
//return vec4( 1, 0, 0, 1 );
}
vec3 hitPos;
vec3 ray = rayEnd - rayStart;
float rayLen = length( ray );
vec3 rayDir = normalize( ray );
float endSide = dot( plane.xyz, rayEnd ) + plane.w;
float planeDist;
if ( endSide < -0.005 )
{
//return vec4( 0, 0, 1, 1 );
hitPos = rayEnd;
planeDist = endSide;
}
else
{
//return vec4( 0, 0, 0, 0 );
float den = dot( ray, plane.xyz );
// Parallal to the plane, return the endPnt.
//if ( den == 0.0f )
// return endPnt;
float dist = -( dot( plane.xyz, rayStart ) + plane.w ) / den;
if ( dist < 0.0 )
dist = 0.0;
//return vec4( 1, 0, 0, 1 );
//return vec4( ( dist ).rrr, 1 );
hitPos = mix( rayStart, rayEnd, dist );
planeDist = dist;
}
float delta = length( hitPos - rayStart );
float fogAmt = 1.0 - saturate( exp( -FOG_DENSITY * ( delta - FOG_DENSITY_OFFSET ) ) );
//return vec4( fogAmt.rrr, 1 );
// Calculate the water "base" color based on depth.
vec4 fogColor = waterColor * texture( waterDepthGradMap, saturate( delta / waterDepthGradMax ) );
// Modulate baseColor by the ambientColor.
fogColor *= vec4( ambientColor.rgb, 1 );
vec3 inColor = hdrDecode( texture( backbuffer, IN_uv0 ).rgb );
inColor.rgb *= 1.0 - saturate( abs( planeDist ) / WET_DEPTH ) * WET_DARKENING;
//return vec4( inColor, 1 );
vec3 outColor = mix( inColor, fogColor.rgb, fogAmt );
OUT_FragColor0 = vec4( hdrEncode( outColor ), 1 );
}

View file

@ -0,0 +1,70 @@
//-----------------------------------------------------------------------------
// 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 "../../gl/postFX.glsl"
uniform sampler2D inputTex ;
uniform vec2 oneOverTargetSize;
uniform float gaussMultiplier;
uniform float gaussMean;
uniform float gaussStdDev;
#define PI 3.141592654
float computeGaussianValue( float x, float mean, float std_deviation )
{
// The gaussian equation is defined as such:
/*
-(x - mean)^2
-------------
1.0 2*std_dev^2
f(x,mean,std_dev) = -------------------- * e^
sqrt(2*pi*std_dev^2)
*/
float tmp = ( 1.0f / sqrt( 2.0f * PI * std_deviation * std_deviation ) );
float tmp2 = exp( ( -( ( x - mean ) * ( x - mean ) ) ) / ( 2.0f * std_deviation * std_deviation ) );
return tmp * tmp2;
}
void main()
{
vec4 color = vec4( 0.0f, 0.0f, 0.0f, 0.0f );
float offset = 0;
float weight = 0;
float x = 0;
float fI = 0;
for( int i = 0; i < 9; i++ )
{
fI = float(i);
offset = (i - 4.0) * oneOverTargetSize.x;
x = (i - 4.0) / 4.0;
weight = gaussMultiplier * computeGaussianValue( x, gaussMean, gaussStdDev );
color += (texture( inputTex, IN_uv0 + vec2( offset, 0.0f ) ) * weight );
}
OUT_FragColor0 = vec4( color.rgb, 1.0f );
}

View file

@ -0,0 +1,69 @@
//-----------------------------------------------------------------------------
// 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 "../../gl/postFX.glsl"
uniform sampler2D inputTex ;
uniform vec2 oneOverTargetSize;
uniform float gaussMultiplier;
uniform float gaussMean;
uniform float gaussStdDev;
#define D3DX_PI 3.141592654
float computeGaussianValue( float x, float mean, float std_deviation )
{
// The gaussian equation is defined as such:
/*
-(x - mean)^2
-------------
1.0 2*std_dev^2
f(x,mean,std_dev) = -------------------- * e^
sqrt(2*pi*std_dev^2)
*/
float tmp = ( 1.0f / sqrt( 2.0f * D3DX_PI * std_deviation * std_deviation ) );
float tmp2 = exp( ( -( ( x - mean ) * ( x - mean ) ) ) / ( 2.0f * std_deviation * std_deviation ) );
return tmp * tmp2;
}
void main()
{
vec4 color = vec4( 0.0f, 0.0f, 0.0f, 0.0f );
float offset = 0;
float weight = 0;
float x = 0;
float fI = 0;
for( int i = 0; i < 9; i++ )
{
fI = float(i);
offset = (fI - 4.0) * oneOverTargetSize.y;
x = (fI - 4.0) / 4.0;
weight = gaussMultiplier * computeGaussianValue( x, gaussMean, gaussStdDev );
color += (texture( inputTex, IN_uv0 + vec2( 0.0f, offset ) ) * weight );
}
OUT_FragColor0 = vec4( color.rgb, 1.0f );
}

View file

@ -0,0 +1,63 @@
//-----------------------------------------------------------------------------
// 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/torque.glsl"
#include "../../../gl/hlslCompat.glsl"
#include "shadergen:/autogenConditioners.h"
#include "../../gl/postFX.glsl"
uniform sampler2D inputTex ;
uniform sampler2D luminanceTex ;
uniform vec2 oneOverTargetSize;
uniform float brightPassThreshold;
uniform float g_fMiddleGray;
const vec3 LUMINANCE_VECTOR = vec3(0.3125f, 0.6154f, 0.0721f);
const vec2 gTapOffsets[4] = vec2[]
(
vec2( -0.5, 0.5 ), vec2( 0.5, -0.5 ),
vec2( -0.5, -0.5 ), vec2( 0.5, 0.5 )
);
void main()
{
vec4 average = vec4( 0.0f, 0.0f, 0.0f, 0.0f );
// Combine and average 4 samples from the source HDR texture.
for( int i = 0; i < 4; i++ )
average += hdrDecode( texture( inputTex, IN_uv0 + ( gTapOffsets[i] * oneOverTargetSize ) ) );
average *= 0.25f;
// Determine the brightness of this particular pixel.
float adaptedLum = texture( luminanceTex, vec2( 0.5f, 0.5f ) ).r;
float lum = (g_fMiddleGray / (adaptedLum + 0.0001)) * hdrLuminance( average.rgb );
//float lum = hdrLuminance( average.rgb );
// Determine whether this pixel passes the test...
if ( lum < brightPassThreshold )
average = vec4( 0.0f, 0.0f, 0.0f, 1.0f );
// Write the colour to the bright-pass render target
OUT_FragColor0 = hdrEncode( average );
}

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 "../../../gl/hlslCompat.glsl"
#include "shadergen:/autogenConditioners.h"
#include "../../gl/postFX.glsl"
uniform sampler2D currLum;
uniform sampler2D lastAdaptedLum;
uniform float adaptRate;
uniform float deltaTime;
void main()
{
float fAdaptedLum = texture( lastAdaptedLum, vec2(0.5f, 0.5f) ).r;
float fCurrentLum = texture( currLum, vec2(0.5f, 0.5f) ).r;
// The user's adapted luminance level is simulated by closing the gap between
// adapted luminance and current luminance by 2% every frame, based on a
// 30 fps rate. This is not an accurate model of human adaptation, which can
// take longer than half an hour.
float diff = fCurrentLum - fAdaptedLum;
float fNewAdaptation = fAdaptedLum + ( diff * ( 1.0 - exp( -deltaTime * adaptRate ) ) );
OUT_FragColor0 = vec4( fNewAdaptation, 0.0, 0.0, 1.0f );
}

View file

@ -0,0 +1,48 @@
//-----------------------------------------------------------------------------
// 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 IN_GLSL
#include "../../../shdrConsts.h"
#include "../../../gl/hlslCompat.glsl"
#include "shadergen:/autogenConditioners.h"
in vec4 texCoords[8];
#define IN_texCoords texCoords
uniform sampler2D inputTex;
//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------
void main()
{
// We calculate the texture coords
// in the vertex shader as an optimization.
vec4 _sample = vec4(0.0f);
for ( int i = 0; i < 8; i++ )
{
_sample += texture( inputTex, IN_texCoords[i].xy );
_sample += texture( inputTex, IN_texCoords[i].zw );
}
OUT_FragColor0 = _sample / 16;
}

View file

@ -0,0 +1,141 @@
//-----------------------------------------------------------------------------
// 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 IN_GLSL
#include "../../../shdrConsts.h"
#include "../../../gl/hlslCompat.glsl"
in vec4 vPosition;
in vec2 vTexCoord0;
#define In_pos vPosition
#define In_uv vTexCoord0
//-----------------------------------------------------------------------------
// Constants
//-----------------------------------------------------------------------------
out vec4 texCoords[8];
#define Out_texCoords texCoords
#define Out_hpos gl_Position
uniform vec2 targetSize;
//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------
void main()
{
Out_hpos = In_pos;
// Sample from the 16 surrounding points. Since the center point will be in
// the exact center of 16 texels, a 0.5f offset is needed to specify a texel
// center.
vec2 texSize = vec2( 1.0 / (targetSize.x - 1.0), 1.0 / (targetSize.y - 1.0) );
vec4 uv;
uv.xy = In_uv.xy;
uv.zw = In_uv.xy;
Out_texCoords[0] = uv;
Out_texCoords[0].x += texSize.x;
Out_texCoords[0].y += texSize.y;
Out_texCoords[0].z += texSize.x;
Out_texCoords[0].w += texSize.y;
Out_texCoords[0].x += ( 0 - 1.5 ) * texSize.x;
Out_texCoords[0].y += ( 0 - 1.5 ) * texSize.y;
Out_texCoords[0].z += ( 1 - 1.5 ) * texSize.x;
Out_texCoords[0].w += ( 0 - 1.5 ) * texSize.y;
Out_texCoords[1] = uv;
Out_texCoords[1].x += texSize.x;
Out_texCoords[1].y += texSize.y;
Out_texCoords[1].z += texSize.x;
Out_texCoords[1].w += texSize.y;
Out_texCoords[1].x += ( 2 - 1.5 ) * texSize.x;
Out_texCoords[1].y += ( 0 - 1.5 ) * texSize.y;
Out_texCoords[1].z += ( 3 - 1.5 ) * texSize.x;
Out_texCoords[1].w += ( 0 - 1.5 ) * texSize.y;
Out_texCoords[2] = uv;
Out_texCoords[2].x += texSize.x;
Out_texCoords[2].y += texSize.y;
Out_texCoords[2].z += texSize.x;
Out_texCoords[2].w += texSize.y;
Out_texCoords[2].x += ( 0 - 1.5 ) * texSize.x;
Out_texCoords[2].y += ( 1 - 1.5 ) * texSize.y;
Out_texCoords[2].z += ( 1 - 1.5 ) * texSize.x;
Out_texCoords[2].w += ( 1 - 1.5 ) * texSize.y;
Out_texCoords[3] = uv;
Out_texCoords[3].x += texSize.x;
Out_texCoords[3].y += texSize.y;
Out_texCoords[3].z += texSize.x;
Out_texCoords[3].w += texSize.y;
Out_texCoords[3].x += ( 2 - 1.5 ) * texSize.x;
Out_texCoords[3].y += ( 1 - 1.5 ) * texSize.y;
Out_texCoords[3].z += ( 3 - 1.5 ) * texSize.x;
Out_texCoords[3].w += ( 1 - 1.5 ) * texSize.y;
Out_texCoords[4] = uv;
Out_texCoords[4].x += texSize.x;
Out_texCoords[4].y += texSize.y;
Out_texCoords[4].z += texSize.x;
Out_texCoords[4].w += texSize.y;
Out_texCoords[4].x += ( 0 - 1.5 ) * texSize.x;
Out_texCoords[4].y += ( 2 - 1.5 ) * texSize.y;
Out_texCoords[4].z += ( 1 - 1.5 ) * texSize.x;
Out_texCoords[4].w += ( 2 - 1.5 ) * texSize.y;
Out_texCoords[5] = uv;
Out_texCoords[5].x += texSize.x;
Out_texCoords[5].y += texSize.y;
Out_texCoords[5].z += texSize.x;
Out_texCoords[5].w += texSize.y;
Out_texCoords[5].x += ( 2 - 1.5 ) * texSize.x;
Out_texCoords[5].y += ( 2 - 1.5 ) * texSize.y;
Out_texCoords[5].z += ( 3 - 1.5 ) * texSize.x;
Out_texCoords[5].w += ( 2 - 1.5 ) * texSize.y;
Out_texCoords[6] = uv;
Out_texCoords[6].x += texSize.x;
Out_texCoords[6].y += texSize.y;
Out_texCoords[6].z += texSize.x;
Out_texCoords[6].w += texSize.y;
Out_texCoords[6].x += ( 0 - 1.5 ) * texSize.x;
Out_texCoords[6].y += ( 3 - 1.5 ) * texSize.y;
Out_texCoords[6].z += ( 1 - 1.5 ) * texSize.x;
Out_texCoords[6].w += ( 3 - 1.5 ) * texSize.y;
Out_texCoords[7] = uv;
Out_texCoords[7].x += texSize.x;
Out_texCoords[7].y += texSize.y;
Out_texCoords[7].z += texSize.x;
Out_texCoords[7].w += texSize.y;
Out_texCoords[7].x += ( 2 - 1.5 ) * texSize.x;
Out_texCoords[7].y += ( 3 - 1.5 ) * texSize.y;
Out_texCoords[7].z += ( 3 - 1.5 ) * texSize.x;
Out_texCoords[7].w += ( 3 - 1.5 ) * texSize.y;
correctSSP(gl_Position);
}

View file

@ -0,0 +1,96 @@
//-----------------------------------------------------------------------------
// 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/torque.glsl"
#include "../../../gl/hlslCompat.glsl"
#include "../../gl/postFX.glsl"
uniform sampler2D sceneTex;
uniform sampler2D luminanceTex;
uniform sampler2D bloomTex;
uniform sampler1D colorCorrectionTex;
uniform vec2 texSize0;
uniform vec2 texSize2;
uniform float g_fEnableToneMapping;
uniform float g_fMiddleGray;
uniform float g_fWhiteCutoff;
uniform float g_fEnableBlueShift;
uniform vec3 g_fBlueShiftColor;
uniform float g_fBloomScale;
uniform float g_fOneOverGamma;
void main()
{
vec4 _sample = hdrDecode( texture( sceneTex, IN_uv0 ) );
float adaptedLum = texture( luminanceTex, vec2( 0.5f, 0.5f ) ).r;
vec4 bloom = texture( bloomTex, IN_uv0 );
// For very low light conditions, the rods will dominate the perception
// of light, and therefore color will be desaturated and shifted
// towards blue.
if ( g_fEnableBlueShift > 0.0f )
{
const vec3 LUMINANCE_VECTOR = vec3(0.2125f, 0.7154f, 0.0721f);
// Define a linear blending from -1.5 to 2.6 (log scale) which
// determines the mix amount for blue shift
float coef = 1.0f - ( adaptedLum + 1.5 ) / 4.1;
coef = saturate( coef * g_fEnableBlueShift );
// Lerp between current color and blue, desaturated copy
vec3 rodColor = dot( _sample.rgb, LUMINANCE_VECTOR ) * g_fBlueShiftColor;
_sample.rgb = mix( _sample.rgb, rodColor, coef );
rodColor = dot( bloom.rgb, LUMINANCE_VECTOR ) * g_fBlueShiftColor;
bloom.rgb = mix( bloom.rgb, rodColor, coef );
}
// Map the high range of color values into a range appropriate for
// display, taking into account the user's adaptation level,
// white point, and selected value for for middle gray.
if ( g_fEnableToneMapping > 0.0f )
{
float Lp = (g_fMiddleGray / (adaptedLum + 0.0001)) * hdrLuminance( _sample.rgb );
//float toneScalar = ( Lp * ( 1.0 + ( Lp / ( g_fWhiteCutoff ) ) ) ) / ( 1.0 + Lp );
float toneScalar = Lp;
_sample.rgb = mix( _sample.rgb, _sample.rgb * toneScalar, g_fEnableToneMapping );
}
// Add the bloom effect.
_sample += g_fBloomScale * bloom;
// Apply the color correction.
_sample.r = texture( colorCorrectionTex, _sample.r ).r;
_sample.g = texture( colorCorrectionTex, _sample.g ).g;
_sample.b = texture( colorCorrectionTex, _sample.b ).b;
// Apply gamma correction
_sample.rgb = pow( abs(_sample.rgb), vec3(g_fOneOverGamma) );
OUT_FragColor0 = _sample;
}

View file

@ -0,0 +1,40 @@
//-----------------------------------------------------------------------------
// 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/torque.glsl"
#include "../../../gl/hlslCompat.glsl"
#include "shadergen:/autogenConditioners.h"
#include "../../gl/postFX.glsl"
uniform sampler2D inputTex;
uniform float brightPassThreshold;
void main()
{
vec4 _sample = hdrDecode( texture( inputTex, IN_uv0 ) );
// Determine the brightness of this particular pixel.
float lum = hdrLuminance( _sample.rgb );
// Write the colour to the bright-pass render target
OUT_FragColor0 = ( vec4( lum.rrr, 1 ) );
}

View file

@ -0,0 +1,60 @@
//-----------------------------------------------------------------------------
// 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/torque.glsl"
#include "../../../gl/hlslCompat.glsl"
#include "../../gl/postFX.glsl"
uniform sampler2D inputTex;
uniform vec2 texSize0;
uniform float g_fMinLuminace;
const vec2 gTapOffsets[9] = vec2[]
(
vec2( -1.0, -1.0 ), vec2( 0.0, -1.0 ), vec2( 1.0, -1.0 ),
vec2( -1.0, 0.0 ), vec2( 0.0, 0.0 ), vec2( 1.0, 0.0 ),
vec2( -1.0, 1.0 ), vec2( 0.0, 1.0 ), vec2( 1.0, 1.0 )
);
void main()
{
vec2 tsize = 1.0 / texSize0;
vec3 _sample;
float average = 0.0;
for ( int i = 0; i < 9; i++ )
{
// Decode the hdr value.
_sample = hdrDecode( texture( inputTex, IN_uv0 + ( gTapOffsets[i] * tsize ) ).rgb );
// Get the luminance and add it to the average.
float lum = max( hdrLuminance( _sample ), g_fMinLuminace );
average += log( lum );
}
average = exp( average / 9.0 );
OUT_FragColor0 = vec4( average, 0.0, 0.0, 1.0 );
}

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.
//-----------------------------------------------------------------------------
#include "../../../gl/hlslCompat.glsl"
#include "../../gl/postFX.glsl"
uniform sampler2D inputTex;
uniform vec2 oneOverTargetSize;
const vec2 gTapOffsets[16] = vec2[]
(
vec2( -1.5, -1.5 ), vec2( -0.5, -1.5 ), vec2( 0.5, -1.5 ), vec2( 1.5, -1.5 ),
vec2( -1.5, -0.5 ), vec2( -0.5, -0.5 ), vec2( 0.5, -0.5 ), vec2( 1.5, -0.5 ),
vec2( -1.5, 0.5 ), vec2( -0.5, 0.5 ), vec2( 0.5, 0.5 ), vec2( 1.5, 0.5 ),
vec2( -1.5, 1.5 ), vec2( -0.5, 1.5 ), vec2( 0.5, 1.5 ), vec2( 1.5, 1.5 )
);
void main()
{
vec2 pixelSize = oneOverTargetSize;
float average = 0.0;
for ( int i = 0; i < 16; i++ )
{
float lum = texture( inputTex, IN_uv0 + ( gTapOffsets[i] * pixelSize ) ).r;
average += lum;
}
OUT_FragColor0 = vec4( average / 16.0, 0.0, 0.0, 1.0 );
}

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.
//-----------------------------------------------------------------------------
#include "../../../gl/hlslCompat.glsl"
#include "shadergen:/autogenConditioners.h"
#include "../../gl/postFx.glsl"
uniform sampler2D backBuffer; // The original backbuffer.
uniform sampler2D prepassTex; // The pre-pass depth and normals.
uniform float brightScalar;
const vec3 LUMINANCE_VECTOR = vec3(0.3125f, 0.6154f, 0.0721f);
void main()
{
vec4 col = vec4( 0, 0, 0, 1 );
// Get the depth at this pixel.
float depth = prepassUncondition( prepassTex, IN_uv0 ).w;
// If the depth is equal to 1.0, read from the backbuffer
// and perform the exposure calculation on the result.
if ( depth >= 0.999 )
{
col = texture( backBuffer, IN_uv0 );
//col = 1 - exp(-120000 * col);
col += dot( vec3(col), LUMINANCE_VECTOR ) + 0.0001f;
col *= brightScalar;
}
OUT_FragColor0 = col;
}

View file

@ -0,0 +1,92 @@
//-----------------------------------------------------------------------------
// 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 "../../gl/postFx.glsl"
uniform sampler2D frameSampler;
uniform sampler2D backBuffer;
uniform vec3 camForward;
uniform vec3 lightDirection;
uniform vec2 screenSunPos;
uniform vec2 oneOverTargetSize;
uniform int numSamples;
uniform float density;
uniform float weight;
uniform float decay;
uniform float exposure;
void main()
{
vec4 texCoord = vec4( IN_uv0.xy, 0, 0 );
// Store initial sample.
half3 color = half3(texture( frameSampler, texCoord.xy ).rgb);
// Store original bb color.
vec4 bbCol = texture( backBuffer, IN_uv1 );
// Set up illumination decay factor.
half illuminationDecay = 1.0;
float amount = saturate( dot( -lightDirection, camForward ) );
int samples = int(numSamples * amount);
if ( samples <= 0 )
{
OUT_FragColor0 = bbCol;
return;
}
// Calculate vector from pixel to light source in screen space.
half2 deltaTexCoord = half2( texCoord.xy - screenSunPos );
// Divide by number of samples and scale by control factor.
deltaTexCoord *= 1.0 / half(samples * density);
// Evaluate summation from Equation 3 NUM_SAMPLES iterations.
for ( int i = 0; i < samples; i++ )
{
// Step sample location along ray.
texCoord.xy -= deltaTexCoord;
// Retrieve sample at new location.
half3 sample_ = half3(tex2Dlod( frameSampler, texCoord ));
// Apply sample attenuation scale/decay factors.
sample_ *= illuminationDecay * weight;
// Accumulate combined color.
color += sample_;
// Update exponential decay factor.
illuminationDecay *= decay;
}
//return saturate( amount ) * color * Exposure;
//return bbCol * decay;
// Output final color with a further scale control factor.
OUT_FragColor0 = saturate( amount ) * vec4( color * exposure, 1 ) + bbCol;
}

View file

@ -0,0 +1,81 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
// An implementation of "Practical Morphological Anti-Aliasing" from
// GPU Pro 2 by Jorge Jimenez, Belen Masia, Jose I. Echevarria,
// Fernando Navarro, and Diego Gutierrez.
//
// http://www.iryoku.com/mlaa/
#include "../../../gl/hlslCompat.glsl"
in vec2 texcoord;
uniform sampler2D edgesMap;
uniform sampler2D edgesMapL;
uniform sampler2D areaMap;
#include "./functions.glsl"
void main()
{
vec4 areas = vec4(0.0);
vec2 e = texture(edgesMap, texcoord).rg;
//[branch]
if (bool(e.g)) // Edge at north
{
// Search distances to the left and to the right:
vec2 d = vec2(SearchXLeft(texcoord), SearchXRight(texcoord));
// Now fetch the crossing edges. Instead of sampling between edgels, we
// sample at -0.25, to be able to discern what value has each edgel:
vec4 coords = mad(vec4(d.x, -0.25, d.y + 1.0, -0.25),
PIXEL_SIZE.xyxy, texcoord.xyxy);
float e1 = tex2Dlevel0(edgesMapL, coords.xy).r;
float e2 = tex2Dlevel0(edgesMapL, coords.zw).r;
// Ok, we know how this pattern looks like, now it is time for getting
// the actual area:
areas.rg = Area(abs(d), e1, e2);
}
//[branch]
if (bool(e.r)) // Edge at west
{
// Search distances to the top and to the bottom:
vec2 d = vec2(SearchYUp(texcoord), SearchYDown(texcoord));
// Now fetch the crossing edges (yet again):
vec4 coords = mad(vec4(-0.25, d.x, -0.25, d.y + 1.0),
PIXEL_SIZE.xyxy, texcoord.xyxy);
float e1 = tex2Dlevel0(edgesMapL, coords.xy).g;
float e2 = tex2Dlevel0(edgesMapL, coords.zw).g;
// Get the area for this direction:
areas.ba = Area(abs(d), e1, e2);
}
OUT_FragColor0 = areas;
}

View file

@ -0,0 +1,74 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
// An implementation of "Practical Morphological Anti-Aliasing" from
// GPU Pro 2 by Jorge Jimenez, Belen Masia, Jose I. Echevarria,
// Fernando Navarro, and Diego Gutierrez.
//
// http://www.iryoku.com/mlaa/
#include "../../../gl/hlslCompat.glsl"
#include "shadergen:/autogenConditioners.h"
uniform sampler2D colorMapG;
uniform sampler2D prepassMap;
uniform vec3 lumaCoefficients;
uniform float threshold;
uniform float depthThreshold;
in vec2 texcoord;
in vec4 offset[2];
void main()
{
// Luma calculation requires gamma-corrected colors (texture 'colorMapG').
//
// Note that there is a lot of overlapped luma calculations; performance
// can be improved if this luma calculation is performed in the main pass,
// which may give you an edge if used in conjunction with a z prepass.
float L = dot(texture(colorMapG, texcoord).rgb, lumaCoefficients);
float Lleft = dot(texture(colorMapG, offset[0].xy).rgb, lumaCoefficients);
float Ltop = dot(texture(colorMapG, offset[0].zw).rgb, lumaCoefficients);
float Lright = dot(texture(colorMapG, offset[1].xy).rgb, lumaCoefficients);
float Lbottom = dot(texture(colorMapG, offset[1].zw).rgb, lumaCoefficients);
vec4 delta = abs(vec4(L) - vec4(Lleft, Ltop, Lright, Lbottom));
vec4 edges = step(threshold, delta);
// Add depth edges to color edges
float D = prepassUncondition(prepassMap, texcoord).w;
float Dleft = prepassUncondition(prepassMap, offset[0].xy).w;
float Dtop = prepassUncondition(prepassMap, offset[0].zw).w;
float Dright = prepassUncondition(prepassMap, offset[1].xy).w;
float Dbottom = prepassUncondition(prepassMap, offset[1].zw).w;
delta = abs(vec4(D) - vec4(Dleft, Dtop, Dright, Dbottom));
edges += step(depthThreshold, delta);
if (dot(edges, vec4(1.0)) == 0.0)
discard;
OUT_FragColor0 = edges;
}

View file

@ -0,0 +1,145 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
// An implementation of "Practical Morphological Anti-Aliasing" from
// GPU Pro 2 by Jorge Jimenez, Belen Masia, Jose I. Echevarria,
// Fernando Navarro, and Diego Gutierrez.
//
// http://www.iryoku.com/mlaa/
uniform vec2 texSize0;
#if !defined(PIXEL_SIZE)
#define PIXEL_SIZE (1.0 / texSize0)
#define MAX_SEARCH_STEPS 8
#define MAX_DISTANCE 33
#endif
// Typical Multiply-Add operation to ease translation to assembly code.
vec4 mad(vec4 m, vec4 a, vec4 b)
{
#if defined(XBOX)
vec4 result;
asm {
mad result, m, a, b
};
return result;
#else
return m * a + b;
#endif
}
// This one just returns the first level of a mip map chain, which allow us to
// avoid the nasty ddx/ddy warnings, even improving the performance a little
// bit.
vec4 tex2Dlevel0(sampler2D map, vec2 texcoord)
{
return tex2Dlod(map, vec4(texcoord, 0.0, 0.0));
}
// Same as above, this eases translation to assembly code;
vec4 tex2Doffset(sampler2D map, vec2 texcoord, vec2 offset)
{
#if defined(XBOX) && MAX_SEARCH_STEPS < 6
vec4 result;
float x = offset.x;
float y = offset.y;
asm {
tfetch2D result, texcoord, map, OffsetX = x, OffsetY = y
};
return result;
#else
return tex2Dlevel0(map, texcoord + PIXEL_SIZE * offset);
#endif
}
// Ok, we have the distance and both crossing edges, can you please return
// the vec2 blending weights?
vec2 Area(vec2 distance, float e1, float e2)
{
// * By dividing by areaSize - 1.0 below we are implicitely offsetting to
// always fall inside of a pixel
// * Rounding prevents bilinear access precision problems
float areaSize = MAX_DISTANCE * 5.0;
vec2 pixcoord = MAX_DISTANCE * round(4.0 * vec2(e1, e2)) + distance;
vec2 texcoord = pixcoord / (areaSize - 1.0);
return tex2Dlevel0(areaMap, texcoord).rg;
}
// Search functions for the 2nd pass.
float SearchXLeft(vec2 texcoord)
{
// We compare with 0.9 to prevent bilinear access precision problems.
float i;
float e = 0.0;
for (i = -1.5; i > -2.0 * MAX_SEARCH_STEPS; i -= 2.0)
{
e = tex2Doffset(edgesMapL, texcoord, vec2(i, 0.0)).g;
/*[flatten]*/ if (e < 0.9) break;
}
return max(i + 1.5 - 2.0 * e, -2.0 * MAX_SEARCH_STEPS);
}
// Search functions for the 2nd pass.
float SearchXRight(vec2 texcoord)
{
float i;
float e = 0.0;
for (i = 1.5; i < 2.0 * MAX_SEARCH_STEPS; i += 2.0)
{
e = tex2Doffset(edgesMapL, texcoord, vec2(i, 0.0)).g;
/*[flatten]*/ if (e < 0.9) break;
}
return min(i - 1.5 + 2.0 * e, 2.0 * MAX_SEARCH_STEPS);
}
// Search functions for the 2nd pass.
float SearchYUp(vec2 texcoord)
{
float i;
float e = 0.0;
for (i = -1.5; i > -2.0 * MAX_SEARCH_STEPS; i -= 2.0)
{
e = tex2Doffset(edgesMapL, texcoord, vec2(i, 0.0).yx).r;
/*[flatten]*/ if (e < 0.9) break;
}
return max(i + 1.5 - 2.0 * e, -2.0 * MAX_SEARCH_STEPS);
}
// Search functions for the 2nd pass.
float SearchYDown(vec2 texcoord)
{
float i;
float e = 0.0;
for (i = 1.5; i < 2.0 * MAX_SEARCH_STEPS; i += 2.0)
{
e = tex2Doffset(edgesMapL, texcoord, vec2(i, 0.0).yx).r;
/*[flatten]*/ if (e < 0.9) break;
}
return min(i - 1.5 + 2.0 * e, 2.0 * MAX_SEARCH_STEPS);
}

View file

@ -0,0 +1,87 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
// An implementation of "Practical Morphological Anti-Aliasing" from
// GPU Pro 2 by Jorge Jimenez, Belen Masia, Jose I. Echevarria,
// Fernando Navarro, and Diego Gutierrez.
//
// http://www.iryoku.com/mlaa/
#include "../../../gl/hlslCompat.glsl"
in vec2 texcoord;
in vec4 offset[2];
uniform sampler2D blendMap;
uniform sampler2D colorMapL;
uniform sampler2D colorMap;
// Dummy sampers to please include.
uniform sampler2D areaMap;
uniform sampler2D edgesMapL;
#include "./functions.glsl"
void main()
{
// Fetch the blending weights for current pixel:
vec4 topLeft = texture(blendMap, texcoord);
float bottom = texture(blendMap, offset[1].zw).g;
float right = texture(blendMap, offset[1].xy).a;
vec4 a = vec4(topLeft.r, bottom, topLeft.b, right);
// Up to 4 lines can be crossing a pixel (one in each edge). So, we perform
// a weighted average, where the weight of each line is 'a' cubed, which
// favors blending and works well in practice.
vec4 w = a * a * a;
// There is some blending weight with a value greater than 0.0?
float sum = dot(w, vec4(1.0));
if (sum < 1e-5)
discard;
vec4 color = vec4(0.0);
// Add the contributions of the possible 4 lines that can cross this pixel:
#ifdef BILINEAR_FILTER_TRICK
vec4 coords = mad(vec4( 0.0, -a.r, 0.0, a.g), PIXEL_SIZE.yyyy, texcoord.xyxy);
color = mad(texture(colorMapL, coords.xy), vec4(w.r), color);
color = mad(texture(colorMapL, coords.zw), vec4(w.g), color);
coords = mad(vec4(-a.b, 0.0, a.a, 0.0), PIXEL_SIZE.xxxx, texcoord.xyxy);
color = mad(texture(colorMapL, coords.xy), vec4(w.b), color);
color = mad(texture(colorMapL, coords.zw), vec4(w.a), color);
#else
vec4 C = texture(colorMap, texcoord);
vec4 Cleft = texture(colorMap, offset[0].xy);
vec4 Ctop = texture(colorMap, offset[0].zw);
vec4 Cright = texture(colorMap, offset[1].xy);
vec4 Cbottom = texture(colorMap, offset[1].zw);
color = mad(mix(C, Ctop, a.r), vec4(w.r), color);
color = mad(mix(C, Cbottom, a.g), vec4(w.g), color);
color = mad(mix(C, Cleft, a.b), vec4(w.b), color);
color = mad(mix(C, Cright, a.a), vec4(w.a), color);
#endif
// Normalize the resulting color and we are finished!
OUT_FragColor0 = color / sum;
}

View file

@ -0,0 +1,57 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
// An implementation of "Practical Morphological Anti-Aliasing" from
// GPU Pro 2 by Jorge Jimenez, Belen Masia, Jose I. Echevarria,
// Fernando Navarro, and Diego Gutierrez.
//
// http://www.iryoku.com/mlaa/
#include "../../../gl/hlslCompat.glsl"
in vec4 vPosition;
in vec2 vTexCoord0;
#define IN_position vPosition
#define IN_texcoord vTexCoord0
#define OUT_position gl_Position
out vec2 texcoord;
#define OUT_texcoord texcoord
out vec4 offset[2];
#define OUT_offset offset
uniform vec2 texSize0;
void main()
{
OUT_position = IN_position;
vec2 PIXEL_SIZE = 1.0 / texSize0;
OUT_texcoord = IN_texcoord;
OUT_texcoord.xy += PIXEL_SIZE * 0.5;
OUT_offset[0] = OUT_texcoord.xyxy + PIXEL_SIZE.xyxy * vec4(-1.0, 0.0, 0.0, -1.0);
OUT_offset[1] = OUT_texcoord.xyxy + PIXEL_SIZE.xyxy * vec4( 1.0, 0.0, 0.0, 1.0);
correctSSP(gl_Position);
}

View file

@ -0,0 +1,52 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
// An implementation of "Practical Morphological Anti-Aliasing" from
// GPU Pro 2 by Jorge Jimenez, Belen Masia, Jose I. Echevarria,
// Fernando Navarro, and Diego Gutierrez.
//
// http://www.iryoku.com/mlaa/
#include "../../../gl/hlslCompat.glsl"
in vec4 vPosition;
in vec2 vTexCoord0;
#define IN_position vPosition
#define IN_texcoord vTexCoord0
#define OUT_position gl_Position
out vec2 texcoord;
#define OUT_texcoord texcoord
uniform vec2 texSize0;
void main()
{
OUT_position = IN_position;
vec2 PIXEL_SIZE = 1.0 / texSize0;
OUT_texcoord = IN_texcoord;
texcoord.xy += PIXEL_SIZE * 0.5;
correctSSP(gl_Position);
}

View file

@ -0,0 +1,95 @@
//-----------------------------------------------------------------------------
// 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.hlsl"
#include "../../torque.hlsl"
uniform sampler2D backBuffer : register(S0);
uniform vec3 LensCenter; // x=Left X, y=Right X, z=Y
uniform vec2 ScreenCenter;
uniform vec2 Scale;
uniform vec2 ScaleIn;
uniform vec4 HmdWarpParam;
uniform vec4 HmdChromaAbParam; // Chromatic aberration correction
vec4 main( PFXVertToPix IN ) : COLOR0
{
vec2 texCoord;
float xOffset;
vec2 lensCenter;
lensCenter.y = LensCenter.z;
if(IN.uv0.x < 0.5)
{
texCoord.x = IN.uv0.x;
texCoord.y = IN.uv0.y;
xOffset = 0.0;
lensCenter.x = LensCenter.x;
}
else
{
texCoord.x = IN.uv0.x - 0.5;
texCoord.y = IN.uv0.y;
xOffset = 0.5;
lensCenter.x = LensCenter.y;
}
// Scales input texture coordinates for distortion.
// ScaleIn maps texture coordinates to Scales to ([-1, 1]), although top/bottom will be
// larger due to aspect ratio.
vec2 theta = (texCoord - lensCenter) * ScaleIn; // Scales to [-1, 1]
float rSq = theta.x * theta.x + theta.y * theta.y;
vec2 theta1 = theta * (HmdWarpParam.x + HmdWarpParam.y * rSq + HmdWarpParam.z * rSq * rSq + HmdWarpParam.w * rSq * rSq * rSq);
// Detect whether blue texture coordinates are out of range
// since these will scaled out the furthest.
vec2 thetaBlue = theta1 * (HmdChromaAbParam.z + HmdChromaAbParam.w * rSq);
vec2 tcBlue = lensCenter + Scale * thetaBlue;
vec4 color;
if (any(clamp(tcBlue, ScreenCenter-vec2(0.25,0.5), ScreenCenter+vec2(0.25, 0.5)) - tcBlue))
{
color = vec4(0,0,0,0);
}
else
{
// Now do blue texture lookup.
tcBlue.x += xOffset;
float blue = texture(backBuffer, tcBlue).b;
// Do green lookup (no scaling).
vec2 tcGreen = lensCenter + Scale * theta1;
tcGreen.x += xOffset;
float green = texture(backBuffer, tcGreen).g;
// Do red scale and lookup.
vec2 thetaRed = theta1 * (HmdChromaAbParam.x + HmdChromaAbParam.y * rSq);
vec2 tcRed = lensCenter + Scale * thetaRed;
tcRed.x += xOffset;
float red = texture(backBuffer, tcRed).r;
color = vec4(red, green, blue, 1);
}
return color;
}

View file

@ -0,0 +1,81 @@
//-----------------------------------------------------------------------------
// 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.hlsl"
#include "../../torque.hlsl"
uniform sampler2D backBuffer : register(S0);
uniform vec3 LensCenter; // x=Left X, y=Right X, z=Y
uniform vec2 ScreenCenter;
uniform vec2 Scale;
uniform vec2 ScaleIn;
uniform vec4 HmdWarpParam;
// Scales input texture coordinates for distortion.
// ScaleIn maps texture coordinates to Scales to ([-1, 1]), although top/bottom will be
// larger due to aspect ratio.
vec2 HmdWarp(vec2 in01, vec2 lensCenter)
{
vec2 theta = (in01 - lensCenter) * ScaleIn; // Scales to [-1, 1]
float rSq = theta.x * theta.x + theta.y * theta.y;
vec2 theta1 = theta * (HmdWarpParam.x + HmdWarpParam.y * rSq + HmdWarpParam.z * rSq * rSq + HmdWarpParam.w * rSq * rSq * rSq);
return lensCenter + Scale * theta1;
}
vec4 main( PFXVertToPix IN ) : COLOR0
{
vec2 texCoord;
float xOffset;
vec2 lensCenter;
lensCenter.y = LensCenter.z;
if(IN.uv0.x < 0.5)
{
texCoord.x = IN.uv0.x;
texCoord.y = IN.uv0.y;
xOffset = 0.0;
lensCenter.x = LensCenter.x;
}
else
{
texCoord.x = IN.uv0.x - 0.5;
texCoord.y = IN.uv0.y;
xOffset = 0.5;
lensCenter.x = LensCenter.y;
}
vec2 tc = HmdWarp(texCoord, lensCenter);
vec4 color;
if (any(clamp(tc, ScreenCenter-vec2(0.25,0.5), ScreenCenter+vec2(0.25, 0.5)) - tc))
{
color = vec4(0,0,0,0);
}
else
{
tc.x += xOffset;
color = texture(backBuffer, tc);
}
return color;
}

View file

@ -0,0 +1,60 @@
//-----------------------------------------------------------------------------
// 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.hlsl"
#include "../../torque.hlsl"
uniform sampler2D backBuffer : register(S0);
uniform vec2 LensXOffsets;
vec4 main( PFXVertToPix IN ) : COLOR0
{
vec2 texCoord;
float xOffset;
vec2 lensCenter;
lensCenter.y = 0.5;
if(IN.uv0.x < 0.5)
{
texCoord.x = IN.uv0.x;
texCoord.y = IN.uv0.y;
xOffset = 0.0;
lensCenter.x = LensXOffsets.x;
}
else
{
texCoord.x = IN.uv0.x - 0.5;
texCoord.y = IN.uv0.y;
xOffset = 0.5;
lensCenter.x = LensXOffsets.y;
}
texCoord.x *= 2.0;
texCoord.x += lensCenter.x;
texCoord.x *= 0.5;
texCoord.x += 0.25;
vec4 color = texture(backBuffer, texCoord);
return color;
}

View file

@ -0,0 +1,107 @@
//-----------------------------------------------------------------------------
// 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"
in vec4 uv0;
#define IN_uv0 uv0
in vec2 uv1;
#define IN_uv1 uv1
in vec2 uv2;
#define IN_uv2 uv2
in vec2 uv3;
#define IN_uv3 uv3
in vec2 uv4;
#define IN_uv4 uv4
in vec2 uv5;
#define IN_uv5 uv5
in vec2 uv6;
#define IN_uv6 uv6
in vec2 uv7;
#define IN_uv7 uv7
uniform sampler2D occludeMap ;
uniform sampler2D prepassMap ;
uniform float blurDepthTol;
uniform float blurNormalTol;
void _sample( vec2 uv, float weight, vec4 centerTap, inout int usedCount, inout float occlusion, inout float total )
{
//return;
vec4 tap = prepassUncondition( prepassMap, uv );
if ( abs( tap.a - centerTap.a ) < blurDepthTol )
{
if ( dot( tap.xyz, centerTap.xyz ) > blurNormalTol )
{
usedCount++;
total += weight;
occlusion += texture( occludeMap, uv ).r * weight;
}
}
}
void main()
{
//vec4 centerTap;
vec4 centerTap = prepassUncondition( prepassMap, IN_uv0.zw );
//return centerTap;
//float centerOcclude = texture( occludeMap, IN_uv0.zw ).r;
//return vec4( centerOcclude.rrr, 1 );
vec4 kernel = vec4( 0.175, 0.275, 0.375, 0.475 ); //25f;
float occlusion = 0;
int usedCount = 0;
float total = 0.0;
_sample( IN_uv0.xy, kernel.x, centerTap, usedCount, occlusion, total );
_sample( IN_uv1, kernel.y, centerTap, usedCount, occlusion, total );
_sample( IN_uv2, kernel.z, centerTap, usedCount, occlusion, total );
_sample( IN_uv3, kernel.w, centerTap, usedCount, occlusion, total );
_sample( IN_uv4, kernel.x, centerTap, usedCount, occlusion, total );
_sample( IN_uv5, kernel.y, centerTap, usedCount, occlusion, total );
_sample( IN_uv6, kernel.z, centerTap, usedCount, occlusion, total );
_sample( IN_uv7, kernel.w, centerTap, usedCount, occlusion, total );
occlusion += texture( occludeMap, IN_uv0.zw ).r * 0.5;
total += 0.5;
//occlusion /= 3.0;
//occlusion /= (float)usedCount / 8.0;
occlusion /= total;
OUT_FragColor0 = vec4( vec3(occlusion), 1 );
//return vec4( 0,0,0,occlusion );
//vec3 color = texture( colorMap, IN_uv0.zw );
//return vec4( color, occlusion );
}

View file

@ -0,0 +1,96 @@
//-----------------------------------------------------------------------------
// 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/torque.glsl"
#include "../../../gl/hlslCompat.glsl"
in vec4 vPosition;
in vec2 vTexCoord0;
#define IN_pos vPosition
#define _IN_uv vTexCoord0
uniform vec2 texSize0;
uniform vec4 rtParams0;
uniform vec2 oneOverTargetSize;
#define OUT_hpos gl_Position
out vec4 uv0;
#define OUT_uv0 uv0
out vec2 uv1;
#define OUT_uv1 uv1
out vec2 uv2;
#define OUT_uv2 uv2
out vec2 uv3;
#define OUT_uv3 uv3
out vec2 uv4;
#define OUT_uv4 uv4
out vec2 uv5;
#define OUT_uv5 uv5
out vec2 uv6;
#define OUT_uv6 uv6
out vec2 uv7;
#define OUT_uv7 uv7
void main()
{
OUT_hpos = IN_pos;
vec2 IN_uv = viewportCoordToRenderTarget( _IN_uv, rtParams0 );
//vec4 step = vec4( 3.5, 2.5, 1.5, 0.5 );
//vec4 step = vec4( 4.0, 3.0, 2.0, 1.0 );
vec4 step = vec4( 9.0, 5.0, 2.5, 0.5 );
// I don't know why this offset is necessary, but it is.
//IN_uv = IN_uv * oneOverTargetSize;
OUT_uv0.xy = IN_uv + ( ( BLUR_DIR * step.x ) / texSize0 );
OUT_uv1 = IN_uv + ( ( BLUR_DIR * step.y ) / texSize0 );
OUT_uv2 = IN_uv + ( ( BLUR_DIR * step.z ) / texSize0 );
OUT_uv3 = IN_uv + ( ( BLUR_DIR * step.w ) / texSize0 );
OUT_uv4 = IN_uv - ( ( BLUR_DIR * step.x ) / texSize0 );
OUT_uv5 = IN_uv - ( ( BLUR_DIR * step.y ) / texSize0 );
OUT_uv6 = IN_uv - ( ( BLUR_DIR * step.z ) / texSize0 );
OUT_uv7 = IN_uv - ( ( BLUR_DIR * step.w ) / texSize0 );
OUT_uv0.zw = IN_uv;
/*
OUT_uv0 = viewportCoordToRenderTarget( OUT_uv0, rtParams0 );
OUT_uv1 = viewportCoordToRenderTarget( OUT_uv1, rtParams0 );
OUT_uv2 = viewportCoordToRenderTarget( OUT_uv2, rtParams0 );
OUT_uv3 = viewportCoordToRenderTarget( OUT_uv3, rtParams0 );
OUT_uv4 = viewportCoordToRenderTarget( OUT_uv4, rtParams0 );
OUT_uv5 = viewportCoordToRenderTarget( OUT_uv5, rtParams0 );
OUT_uv6 = viewportCoordToRenderTarget( OUT_uv6, rtParams0 );
OUT_uv7 = viewportCoordToRenderTarget( OUT_uv7, rtParams0 );
*/
correctSSP(gl_Position);
}

View file

@ -0,0 +1,276 @@
//-----------------------------------------------------------------------------
// 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 "../../gl/postFX.glsl"
#define DOSMALL
#define DOLARGE
uniform sampler2D prepassMap ;
uniform sampler2D randNormalTex ;
uniform sampler1D powTable ;
uniform vec2 nearFar;
uniform vec2 worldToScreenScale;
uniform vec2 texSize0;
uniform vec2 texSize1;
uniform vec2 targetSize;
// Script-set constants.
uniform float overallStrength;
uniform float sRadius;
uniform float sStrength;
uniform float sDepthMin;
uniform float sDepthMax;
uniform float sDepthPow;
uniform float sNormalTol;
uniform float sNormalPow;
uniform float lRadius;
uniform float lStrength;
uniform float lDepthMin;
uniform float lDepthMax;
uniform float lDepthPow;
uniform float lNormalTol;
uniform float lNormalPow;
#ifndef QUALITY
#define QUALITY 2
#endif
#if QUALITY == 0
#define sSampleCount 4
#define totalSampleCount 12
#elif QUALITY == 1
#define sSampleCount 6
#define totalSampleCount 24
#elif QUALITY == 2
#define sSampleCount 8
#define totalSampleCount 32
#endif
float getOcclusion( float depthDiff, float depthMin, float depthMax, float depthPow,
float normalDiff, float dt, float normalTol, float normalPow )
{
if ( depthDiff < 0.0 )
return 0.0;
float delta = abs( depthDiff );
if ( delta < depthMin || delta > depthMax )
return 0.0;
delta = saturate( delta / depthMax );
if ( dt > 0.0 )
normalDiff *= dt;
else
normalDiff = 1.0;
normalDiff *= 1.0 - ( dt * 0.5 + 0.5 );
return ( 1.0 - texture( powTable, delta ).r ) * normalDiff;
}
void main()
{
const vec3 ptSphere[32] = vec3[]
(
vec3( 0.295184, 0.077723, 0.068429 ),
vec3( -0.271976, -0.365221, -0.838363 ),
vec3( 0.547713, 0.467576, 0.488515 ),
vec3( 0.662808, -0.031733, -0.584758 ),
vec3( -0.025717, 0.218955, -0.657094 ),
vec3( -0.310153, -0.365223, -0.370701 ),
vec3( -0.101407, -0.006313, -0.747665 ),
vec3( -0.769138, 0.360399, -0.086847 ),
vec3( -0.271988, -0.275140, -0.905353 ),
vec3( 0.096740, -0.566901, 0.700151 ),
vec3( 0.562872, -0.735136, -0.094647 ),
vec3( 0.379877, 0.359278, 0.190061 ),
vec3( 0.519064, -0.023055, 0.405068 ),
vec3( -0.301036, 0.114696, -0.088885 ),
vec3( -0.282922, 0.598305, 0.487214 ),
vec3( -0.181859, 0.251670, -0.679702 ),
vec3( -0.191463, -0.635818, -0.512919 ),
vec3( -0.293655, 0.427423, 0.078921 ),
vec3( -0.267983, 0.680534, -0.132880 ),
vec3( 0.139611, 0.319637, 0.477439 ),
vec3( -0.352086, 0.311040, 0.653913 ),
vec3( 0.321032, 0.805279, 0.487345 ),
vec3( 0.073516, 0.820734, -0.414183 ),
vec3( -0.155324, 0.589983, -0.411460 ),
vec3( 0.335976, 0.170782, -0.527627 ),
vec3( 0.463460, -0.355658, -0.167689 ),
vec3( 0.222654, 0.596550, -0.769406 ),
vec3( 0.922138, -0.042070, 0.147555 ),
vec3( -0.727050, -0.329192, 0.369826 ),
vec3( -0.090731, 0.533820, 0.463767 ),
vec3( -0.323457, -0.876559, -0.238524 ),
vec3( -0.663277, -0.372384, -0.342856 )
);
// Sample a random normal for reflecting the
// sphere vector later in our loop.
vec4 noiseMapUV = vec4( ( IN_uv1 * ( targetSize / texSize1 ) ).xy, 0, 0 );
vec3 reflectNormal = normalize( tex2Dlod( randNormalTex, noiseMapUV ).xyz * 2.0 - 1.0 );
//return vec4( reflectNormal, 1 );
vec4 prepass = prepassUncondition( prepassMap, IN_uv0 );
vec3 normal = prepass.xyz;
float depth = prepass.a;
//return vec4( ( depth ).xxx, 1 );
// Early out if too far away.
if ( depth > 0.99999999 )
{
OUT_FragColor0 = vec4( 0,0,0,0 );
return;
}
// current fragment coords in screen space
vec3 ep = vec3( IN_uv0, depth );
float bl;
vec3 baseRay, ray, se, occNorm, projRadius;
float normalDiff = 0;
float depthMin, depthMax, dt, depthDiff;
vec4 occluderFragment;
int i;
float sOcclusion = 0.0;
float lOcclusion = 0.0;
//------------------------------------------------------------
// Small radius
//------------------------------------------------------------
#ifdef DOSMALL
bl = 0.0;
projRadius.xy = ( vec2( sRadius ) / ( depth * nearFar.y ) ) * ( worldToScreenScale / texSize0 );
projRadius.z = sRadius / nearFar.y;
depthMin = projRadius.z * sDepthMin;
depthMax = projRadius.z * sDepthMax;
//float maxr = 1;
//radiusDepth = clamp( radiusDepth, 0.0001, maxr.rrr );
//if ( radiusDepth.x < 1.0 / targetSize.x )
// return color;
//radiusDepth.xyz = 0.0009;
for ( i = 0; i < sSampleCount; i++ )
{
baseRay = reflect( ptSphere[i], reflectNormal );
dt = dot( baseRay.xyz, normal );
baseRay *= sign( dt );
ray = ( projRadius * baseRay.xzy );
ray.y = -ray.y;
se = ep + ray;
occluderFragment = prepassUncondition( prepassMap, se.xy );
depthDiff = se.z - occluderFragment.a;
dt = dot( occluderFragment.xyz, baseRay.xyz );
normalDiff = dot( occluderFragment.xyz, normal );
bl += getOcclusion( depthDiff, depthMin, depthMax, sDepthPow, normalDiff, dt, sNormalTol, sNormalPow );
}
sOcclusion = sStrength * ( bl / float(sSampleCount) );
#endif // DOSMALL
//------------------------------------------------------------
// Large radius
//------------------------------------------------------------
#ifdef DOLARGE
bl = 0.0;
projRadius.xy = ( vec2( lRadius ) / ( depth * nearFar.y ) ) * ( worldToScreenScale / texSize0 );
projRadius.z = lRadius / nearFar.y;
depthMin = projRadius.z * lDepthMin;
depthMax = projRadius.z * lDepthMax;
//projRadius.xy = clamp( projRadius.xy, 0.0, 0.01 );
//float maxr = 1;
//radiusDepth = clamp( radiusDepth, 0.0001, maxr.rrr );
//if ( radiusDepth.x < 1.0 / targetSize.x )
// return color;
//radiusDepth.xyz = 0.0009;
for ( i = sSampleCount; i < totalSampleCount; i++ )
{
baseRay = reflect( ptSphere[i], reflectNormal );
dt = dot( baseRay.xyz, normal );
baseRay *= sign( dt );
ray = ( projRadius * baseRay.xzy );
ray.y = -ray.y;
se = ep + ray;
occluderFragment = prepassUncondition( prepassMap, se.xy );
depthDiff = se.z - occluderFragment.a;
normalDiff = dot( occluderFragment.xyz, normal );
dt = dot( occluderFragment.xyz, baseRay.xyz );
bl += getOcclusion( depthDiff, depthMin, depthMax, lDepthPow, normalDiff, dt, lNormalTol, lNormalPow );
}
lOcclusion = lStrength * ( bl / float( totalSampleCount - sSampleCount ) );
#endif // DOLARGE
float occlusion = saturate( max( sOcclusion, lOcclusion ) * overallStrength );
// Note black is unoccluded and white is fully occluded. This
// seems backwards, but it makes it simple to deal with the SSAO
// being disabled in the lighting shaders.
OUT_FragColor0 = vec4(occlusion, vec3(0.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 "../../../gl/hlslCompat.glsl"
in vec2 uv0;
#define IN_uv0 uv0
void main()
{
float power = pow( max( IN_uv0.x, 0 ), 0.1 );
OUT_FragColor0 = vec4( power, 0, 0, 1 );
}

View file

@ -0,0 +1,38 @@
//-----------------------------------------------------------------------------
// 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/torque.glsl"
#include "../../../gl/hlslCompat.glsl"
#include "../../gl/postFX.glsl"
void main()
{
OUT_hpos = IN_pos;
OUT_uv0 = IN_uv; //viewportCoordToRenderTarget( IN_uv, rtParams0 );
OUT_uv1 = IN_uv; //viewportCoordToRenderTarget( IN_uv, rtParams1 );
OUT_uv2 = IN_uv; //viewportCoordToRenderTarget( IN_uv, rtParams2 );
OUT_uv3 = IN_uv; //viewportCoordToRenderTarget( IN_uv, rtParams3 );
OUT_wsEyeRay = IN_wsEyeRay;
correctSSP(gl_Position);
}

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.
//-----------------------------------------------------------------------------
uniform sampler2D diffuseMap;
in vec4 color;
in vec2 texCoord;
out vec4 OUT_FragColor0;
void main()
{
OUT_FragColor0 = vec4(color.rgb, color.a * texture(diffuseMap, texCoord).a);
}

View file

@ -0,0 +1,38 @@
//-----------------------------------------------------------------------------
// 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"
in vec4 vPosition;
in vec4 vColor;
in vec2 vTexCoord0;
uniform mat4 modelview;
out vec4 color;
out vec2 texCoord;
void main()
{
gl_Position = tMul(modelview, vPosition);
correctSSP(gl_Position);
color = vColor;
texCoord = vTexCoord0.st;
}

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.
//-----------------------------------------------------------------------------
in vec4 color;
out vec4 OUT_FragColor0;
void main()
{
OUT_FragColor0 = color;
}

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.
//-----------------------------------------------------------------------------
#include "../../gl/hlslCompat.glsl"
in vec4 vPosition;
in vec4 vColor;
uniform mat4 modelview;
out vec4 color;
void main()
{
gl_Position = tMul(modelview, vPosition);
correctSSP(gl_Position);
color = vColor;
}

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.
//-----------------------------------------------------------------------------
uniform sampler2D diffuseMap;
in vec4 color;
in vec2 texCoord;
out vec4 OUT_FragColor0;
void main()
{
OUT_FragColor0 = texture(diffuseMap, texCoord) * color;
}

View file

@ -0,0 +1,38 @@
//-----------------------------------------------------------------------------
// 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"
in vec4 vPosition;
in vec4 vColor;
in vec2 vTexCoord0;
uniform mat4 modelview;
out vec4 color;
out vec2 texCoord;
void main()
{
gl_Position = tMul(modelview, vPosition);
correctSSP(gl_Position);
color = vColor;
texCoord = vTexCoord0.st;
}

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 sampler2D colorTarget0Texture ;
vec4 main( vec2 ScreenPos : VPOS ) : COLOR0
{
vec2 TexCoord = ScreenPos;
vec4 diffuse;
asm { tfetch2D diffuse, TexCoord, colorTarget0Texture, UnnormalizedTextureCoords = true };
return diffuse;
}

View file

@ -0,0 +1,22 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------

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 sampler2D diffuseMap;
in vec2 texCoord;
out vec4 OUT_FragColor0;
void main()
{
OUT_FragColor0 = texture(diffuseMap, texCoord);
}

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.
//-----------------------------------------------------------------------------
#include "../../gl/hlslCompat.glsl"
in vec4 vPosition;
in vec2 vTexCoord0;
uniform mat4 modelview;
out vec2 texCoord;
void main()
{
gl_Position = tMul(modelview, vPosition);
correctSSP(gl_Position);
texCoord = vTexCoord0.st;
}

View file

@ -0,0 +1,37 @@
//-----------------------------------------------------------------------------
// 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 "torque.glsl"
#include "hlslCompat.glsl"
//ConnectData
in vec2 texCoord;
#define IN_texCoord texCoord
uniform sampler2D diffuseMap ;
void main()
{
vec4 col = texture( diffuseMap, IN_texCoord );
OUT_FragColor0 = hdrEncode( col );
}

View file

@ -0,0 +1,53 @@
//-----------------------------------------------------------------------------
// 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 "hlslCompat.glsl"
//CloudVert
in vec4 vPosition;
in vec2 vTexCoord0;
#define IN_pos vPosition
#define IN_uv0 vTexCoord0
uniform mat4 modelview;
uniform float accumTime;
uniform float texScale;
uniform vec2 texDirection;
uniform vec2 texOffset;
out vec2 texCoord;
#define OUT_texCoord texCoord
void main()
{
gl_Position = tMul(modelview, IN_pos);
vec2 uv = IN_uv0;
uv += texOffset;
uv *= texScale;
uv += accumTime * texDirection;
OUT_texCoord = uv;
correctSSP(gl_Position);
}

View file

@ -48,14 +48,14 @@
#define lerp mix #define lerp mix
void tSetMatrixRow(out float3x3 m, int row, float3 value) void tSetMatrixRow(inout float3x3 m, int row, float3 value)
{ {
m[0][row] = value.x; m[0][row] = value.x;
m[1][row] = value.y; m[1][row] = value.y;
m[2][row] = value.z; m[2][row] = value.z;
} }
void tSetMatrixRow(out float4x4 m, int row, float4 value) void tSetMatrixRow(inout float4x4 m, int row, float4 value)
{ {
m[0][row] = value.x; m[0][row] = value.x;
m[1][row] = value.y; m[1][row] = value.y;

View file

@ -0,0 +1,85 @@
//-----------------------------------------------------------------------------
// 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 "../../gl/postFX.glsl"
#include "shadergen:/autogenConditioners.h"
uniform vec3 eyePosWorld;
uniform vec4 rtParams0;
uniform vec4 waterFogPlane;
uniform float accumTime;
uniform sampler2D prepassTex;
uniform sampler2D causticsTex0;
uniform sampler2D causticsTex1;
uniform vec2 targetSize;
float distanceToPlane(vec4 plane, vec3 pos)
{
return (plane.x * pos.x + plane.y * pos.y + plane.z * pos.z) + plane.w;
}
void main()
{
//Sample the pre-pass
vec4 prePass = prepassUncondition( prepassTex, IN_uv0 );
//Get depth
float depth = prePass.w;
if(depth > 0.9999)
{
OUT_FragColor0 = vec4(0,0,0,0);
return;
}
//Get world position
vec3 pos = eyePosWorld + IN_wsEyeRay * depth;
// Check the water depth
float waterDepth = -distanceToPlane(waterFogPlane, pos);
if(waterDepth < 0)
{
OUT_FragColor0 = vec4(0,0,0,0);
return;
}
waterDepth = saturate(waterDepth);
//Use world position X and Y to calculate caustics UV
vec2 causticsUV0 = mod(abs(pos.xy * 0.25), vec2(1, 1));
vec2 causticsUV1 = mod(abs(pos.xy * 0.2), vec2(1, 1));
//Animate uvs
float timeSin = sin(accumTime);
causticsUV0.xy += vec2(accumTime*0.1, timeSin*0.2);
causticsUV1.xy -= vec2(accumTime*0.15, timeSin*0.15);
//Sample caustics texture
vec4 caustics = texture(causticsTex0, causticsUV0);
caustics *= texture(causticsTex1, causticsUV1);
//Use normal Z to modulate caustics
//float waterDepth = 1 - saturate(pos.z + waterFogPlane.w + 1);
caustics *= saturate(prePass.z) * pow(1-depth, 64) * waterDepth;
OUT_FragColor0 = caustics;
}

View file

@ -0,0 +1,53 @@
//-----------------------------------------------------------------------------
// 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 "../../gl/postFX.glsl"
// These are set by the game engine.
uniform sampler2D shrunkSampler; // Output of DofDownsample()
uniform sampler2D blurredSampler; // Blurred version of the shrunk sampler
// This is the pixel shader function that calculates the actual
// value used for the near circle of confusion.
// "texCoords" are 0 at the bottom left pixel and 1 at the top right.
void main()
{
vec3 color;
float coc;
half4 blurred;
half4 shrunk;
shrunk = texture( shrunkSampler, IN_uv0 );
blurred = texture( blurredSampler, IN_uv1 );
color = shrunk.rgb;
//coc = shrunk.a;
//coc = blurred.a;
//coc = max( blurred.a, shrunk.a );
coc = 2 * max( blurred.a, shrunk.a ) - shrunk.a;
//OUT_FragColor0 = vec4( coc.rrr, 1.0 );
//OUT_FragColor0 = vec4( color, 1.0 );
OUT_FragColor0 = vec4( color, coc );
//OUT_FragColor0 = vec4( 1.0, 0.0, 1.0, 1.0 );
}

View file

@ -0,0 +1,69 @@
//-----------------------------------------------------------------------------
// 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 "../../../gl/torque.glsl"
#include "../../gl/postFX.glsl"
uniform vec4 rtParams0;
uniform vec4 rtParams1;
uniform vec4 rtParams2;
uniform vec4 rtParams3;
void main()
{
/*
OUT_hpos = IN.pos;
OUT_uv0 = IN_uv;
OUT_uv1 = IN_uv;
OUT_uv2 = IN_uv;
OUT_uv3 = IN_uv;
*/
/*
OUT_hpos = IN_pos;
OUT_uv0 = IN_uv + rtParams0.xy;
OUT_uv1 = IN_uv + rtParams1.xy;
OUT_uv2 = IN_uv + rtParams2.xy;
OUT_uv3 = IN_uv + rtParams3.xy;
*/
/*
OUT_hpos = IN_pos;
OUT_uv0 = IN_uv * rtParams0.zw;
OUT_uv1 = IN_uv * rtParams1.zw;
OUT_uv2 = IN_uv * rtParams2.zw;
OUT_uv3 = IN_uv * rtParams3.zw;
*/
OUT_hpos = IN_pos;
OUT_uv0 = viewportCoordToRenderTarget( IN_uv, rtParams0 );
OUT_uv1 = viewportCoordToRenderTarget( IN_uv, rtParams1 );
OUT_uv2 = viewportCoordToRenderTarget( IN_uv, rtParams2 );
OUT_uv3 = viewportCoordToRenderTarget( IN_uv, rtParams3 );
OUT_wsEyeRay = IN_wsEyeRay;
correctSSP(gl_Position);;
}

View file

@ -0,0 +1,138 @@
//-----------------------------------------------------------------------------
// 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"
// These are set by the game engine.
// The render target size is one-quarter the scene rendering size.
uniform sampler2D colorSampler;
uniform sampler2D depthSampler;
uniform vec2 dofEqWorld;
uniform float depthOffset;
uniform vec2 targetSize;
uniform float maxWorldCoC;
//uniform vec2 dofEqWeapon;
//uniform vec2 dofRowDelta; // vec2( 0, 0.25 / renderTargetHeight )
in vec2 tcColor0;
#define IN_tcColor0 tcColor0
in vec2 tcColor1;
#define IN_tcColor1 tcColor1
in vec2 tcDepth0;
#define IN_tcDepth0 tcDepth0
in vec2 tcDepth1;
#define IN_tcDepth1 tcDepth1
in vec2 tcDepth2;
#define IN_tcDepth2 tcDepth2
in vec2 tcDepth3;
#define IN_tcDepth3 tcDepth3
void main()
{
//return vec4( 1.0, 0.0, 1.0, 1.0 );
vec2 dofRowDelta = vec2( 0, 0.25 / targetSize.y );
//vec2 dofEqWorld = vec2( -60, 1.0 );
half3 color;
half maxCoc;
vec4 depth;
half4 viewCoc;
half4 sceneCoc;
half4 curCoc;
half4 coc;
vec2 rowOfs[4];
// "rowOfs" reduces how many moves PS2.0 uses to emulate swizzling.
rowOfs[0] = vec2(0);
rowOfs[1] = dofRowDelta.xy;
rowOfs[2] = dofRowDelta.xy * 2;
rowOfs[3] = dofRowDelta.xy * 3;
// Use bilinear filtering to average 4 color samples for free.
color = half3(0);
color += texture( colorSampler, IN_tcColor0.xy + rowOfs[0] ).rgb;
color += texture( colorSampler, IN_tcColor1.xy + rowOfs[0] ).rgb;
color += texture( colorSampler, IN_tcColor0.xy + rowOfs[2] ).rgb;
color += texture( colorSampler, IN_tcColor1.xy + rowOfs[2] ).rgb;
color /= 4;
// Process 4 samples at a time to use vector hardware efficiently.
// The CoC will be 1 if the depth is negative, so use "min" to pick
// between "sceneCoc" and "viewCoc".
for ( int i = 0; i < 4; i++ )
{
depth[0] = prepassUncondition( depthSampler, ( IN_tcDepth0.xy + rowOfs[i] ) ).w;
depth[1] = prepassUncondition( depthSampler, ( IN_tcDepth1.xy + rowOfs[i] ) ).w;
depth[2] = prepassUncondition( depthSampler, ( IN_tcDepth2.xy + rowOfs[i] ) ).w;
depth[3] = prepassUncondition( depthSampler, ( IN_tcDepth3.xy + rowOfs[i] ) ).w;
coc[i] = clamp( dofEqWorld.x * depth + dofEqWorld.y, 0.0, maxWorldCoC );
}
/*
depth[0] = texture( depthSampler, pixel.tcDepth0.xy + rowOfs[0] ).r;
depth[1] = texture( depthSampler, pixel.tcDepth1.xy + rowOfs[0] ).r;
depth[2] = texture( depthSampler, pixel.tcDepth2.xy + rowOfs[0] ).r;
depth[3] = texture( depthSampler, pixel.tcDepth3.xy + rowOfs[0] ).r;
viewCoc = saturate( dofEqWeapon.x * -depth + dofEqWeapon.y );
sceneCoc = saturate( dofEqWorld.x * depth + dofEqWorld.y );
curCoc = min( viewCoc, sceneCoc );
coc = curCoc;
depth[0] = texture( depthSampler, pixel.tcDepth0.xy + rowOfs[1] ).r;
depth[1] = texture( depthSampler, pixel.tcDepth1.xy + rowOfs[1] ).r;
depth[2] = texture( depthSampler, pixel.tcDepth2.xy + rowOfs[1] ).r;
depth[3] = texture( depthSampler, pixel.tcDepth3.xy + rowOfs[1] ).r;
viewCoc = saturate( dofEqWeapon.x * -depth + dofEqWeapon.y );
sceneCoc = saturate( dofEqWorld.x * depth + dofEqWorld.y );
curCoc = min( viewCoc, sceneCoc );
coc = max( coc, curCoc );
depth[0] = texture( depthSampler, pixel.tcDepth0.xy + rowOfs[2] ).r;
depth[1] = texture( depthSampler, pixel.tcDepth1.xy + rowOfs[2] ).r;
depth[2] = texture( depthSampler, pixel.tcDepth2.xy + rowOfs[2] ).r;
depth[3] = texture( depthSampler, pixel.tcDepth3.xy + rowOfs[2] ).r;
viewCoc = saturate( dofEqWeapon.x * -depth + dofEqWeapon.y );
sceneCoc = saturate( dofEqWorld.x * depth + dofEqWorld.y );
curCoc = min( viewCoc, sceneCoc );
coc = max( coc, curCoc );
depth[0] = texture( depthSampler, pixel.tcDepth0.xy + rowOfs[3] ).r;
depth[1] = texture( depthSampler, pixel.tcDepth1.xy + rowOfs[3] ).r;
depth[2] = texture( depthSampler, pixel.tcDepth2.xy + rowOfs[3] ).r;
depth[3] = texture( depthSampler, pixel.tcDepth3.xy + rowOfs[3] ).r;
viewCoc = saturate( dofEqWeapon.x * -depth + dofEqWeapon.y );
sceneCoc = saturate( dofEqWorld.x * depth + dofEqWorld.y );
curCoc = min( viewCoc, sceneCoc );
coc = max( coc, curCoc );
*/
maxCoc = max( max( coc[0], coc[1] ), max( coc[2], coc[3] ) );
//OUT_FragColor0 = half4( 1.0, 0.0, 1.0, 1.0 );
OUT_FragColor0 = half4( color, maxCoc );
//OUT_FragColor0 = half4( color, 1.0f );
//OUT_FragColor0 = half4( maxCoc.rrr, 1.0 );
}

View file

@ -0,0 +1,67 @@
//-----------------------------------------------------------------------------
// 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 "../../../gl/torque.glsl"
in vec4 vPosition;
in vec2 vTexCoord0;
in vec3 vTexCoord1;
#define IN_pos vPosition
#define IN_tc vTexCoord0
#define IN_wsEyeRay vTexCoord1
#define OUT_position gl_Position
out vec2 tcColor0;
#define OUT_tcColor0 tcColor0
out vec2 tcColor1;
#define OUT_tcColor1 tcColor1
out vec2 tcDepth0;
#define OUT_tcDepth0 tcDepth0
out vec2 tcDepth1;
#define OUT_tcDepth1 tcDepth1
out vec2 tcDepth2;
#define OUT_tcDepth2 tcDepth2
out vec2 tcDepth3;
#define OUT_tcDepth3 tcDepth3
uniform vec4 rtParams0;
uniform vec2 oneOverTargetSize;
void main()
{
OUT_position = IN_pos;
vec2 uv = viewportCoordToRenderTarget( IN_tc, rtParams0 );
//OUT_position = tMul( IN_pos, modelView );
OUT_tcColor1 = uv + vec2( +1.0, -0.0 ) * oneOverTargetSize;
OUT_tcColor0 = uv + vec2( -1.0, -0.0 ) * oneOverTargetSize;
OUT_tcDepth0 = uv + vec2( -0.5, -0.0 ) * oneOverTargetSize;
OUT_tcDepth1 = uv + vec2( -1.5, -0.0 ) * oneOverTargetSize;
OUT_tcDepth2 = uv + vec2( +1.5, -0.0 ) * oneOverTargetSize;
OUT_tcDepth3 = uv + vec2( +2.5, -0.0 ) * oneOverTargetSize;
correctSSP(gl_Position);
}

View file

@ -0,0 +1,145 @@
//-----------------------------------------------------------------------------
// 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 "../../gl/postFX.glsl"
uniform sampler2D colorSampler; // Original source image
uniform sampler2D smallBlurSampler; // Output of SmallBlurPS()
uniform sampler2D largeBlurSampler; // Blurred output of DofDownsample()
uniform sampler2D depthSampler; //
uniform vec2 oneOverTargetSize;
uniform vec4 dofLerpScale;
uniform vec4 dofLerpBias;
uniform vec3 dofEqFar;
uniform float maxFarCoC;
//static float d0 = 0.1;
//static float d1 = 0.1;
//static float d2 = 0.8;
//static vec4 dofLerpScale = vec4( -1.0 / d0, -1.0 / d1, -1.0 / d2, 1.0 / d2 );
//static vec4 dofLerpBias = vec4( 1.0, (1.0 - d2) / d1, 1.0 / d2, (d2 - 1.0) / d2 );
//static vec3 dofEqFar = vec3( 2.0, 0.0, 1.0 );
vec4 tex2Doffset( sampler2D s, vec2 tc, vec2 offset )
{
return texture( s, tc + offset * oneOverTargetSize );
}
half3 GetSmallBlurSample( vec2 tc )
{
half3 sum;
const half weight = 4.0 / 17;
sum = half3(0); // Unblurred sample done by alpha blending
//sum += weight * tex2Doffset( colorSampler, tc, vec2( 0, 0 ) ).rgb;
sum += weight * tex2Doffset( colorSampler, tc, vec2( +0.5, -1.5 ) ).rgb;
sum += weight * tex2Doffset( colorSampler, tc, vec2( -1.5, -0.5 ) ).rgb;
sum += weight * tex2Doffset( colorSampler, tc, vec2( -0.5, +1.5 ) ).rgb;
sum += weight * tex2Doffset( colorSampler, tc, vec2( +1.5, +0.5 ) ).rgb;
return sum;
}
half4 InterpolateDof( half3 small, half3 med, half3 large, half t )
{
//t = 2;
half4 weights;
half3 color;
half alpha;
// Efficiently calculate the cross-blend weights for each sample.
// Let the unblurred sample to small blur fade happen over distance
// d0, the small to medium blur over distance d1, and the medium to
// large blur over distance d2, where d0 + d1 + d2 = 1.
//vec4 dofLerpScale = vec4( -1 / d0, -1 / d1, -1 / d2, 1 / d2 );
//vec4 dofLerpBias = vec4( 1, (1 d2) / d1, 1 / d2, (d2 1) / d2 );
weights = saturate( t * dofLerpScale + dofLerpBias );
weights.yz = min( weights.yz, 1 - weights.xy );
// Unblurred sample with weight "weights.x" done by alpha blending
color = weights.y * small + weights.z * med + weights.w * large;
//color = med;
alpha = dot( weights.yzw, half3( 16.0 / 17, 1.0, 1.0 ) );
//alpha = 0.0;
return half4( color, alpha );
}
void main()
{
//return half4( 1,0,1,1 );
//return half4( texture( colorSampler, IN_uv0 ).rgb, 1.0 );
//return half4( texture( colorSampler, texCoords ).rgb, 0 );
half3 small;
half4 med;
half3 large;
half depth;
half nearCoc;
half farCoc;
half coc;
small = GetSmallBlurSample( IN_uv0 );
//small = half3( 1,0,0 );
//return half4( small, 1.0 );
med = texture( smallBlurSampler, IN_uv1 );
//med.rgb = half3( 0,1,0 );
//return half4(med.rgb, 0.0);
large = texture( largeBlurSampler, IN_uv2 ).rgb;
//large = half3( 0,0,1 );
//return large;
//return half4(large.rgb,1.0);
nearCoc = med.a;
// Since the med blur texture is screwed up currently
// replace it with the large, but this needs to be fixed.
//med.rgb = large;
//nearCoc = 0;
depth = prepassUncondition( depthSampler, IN_uv3 ).w;
//return half4(depth.rrr,1);
//return half4(nearCoc.rrr,1.0);
if (depth > 0.999 )
{
coc = nearCoc; // We don't want to blur the sky.
//coc = 0;
}
else
{
// dofEqFar.x and dofEqFar.y specify the linear ramp to convert
// to depth for the distant out-of-focus region.
// dofEqFar.z is the ratio of the far to the near blur radius.
farCoc = clamp( dofEqFar.x * depth + dofEqFar.y, 0.0, maxFarCoC );
coc = max( nearCoc, farCoc * dofEqFar.z );
//coc = nearCoc;
}
//coc = nearCoc;
//coc = farCoc;
//return half4(coc.rrr,0.5);
//return half4(farCoc.rrr,1);
//return half4(nearCoc.rrr,1);
//return half4( 1,0,1,0 );
OUT_FragColor0 = InterpolateDof( small, med.rgb, large, coc );
}

View file

@ -0,0 +1,71 @@
//-----------------------------------------------------------------------------
// 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 "../../../gl/torque.glsl"
#include "../../gl/postFX.glsl"
uniform vec4 rtParams0;
uniform vec4 rtParams1;
uniform vec4 rtParams2;
uniform vec4 rtParams3;
uniform vec2 oneOverTargetSize;
void main()
{
/*
OUT.hpos = IN_pos;
OUT_uv0 = IN_uv;
OUT_uv1 = IN_uv;
OUT_uv2 = IN_uv;
OUT_uv3 = IN_uv;
*/
/*
OUT_hpos = IN_pos;
OUT_uv0 = IN_uv + rtParams0.xy;
OUT_uv1 = IN_uv + rtParams1.xy;
OUT_uv2 = IN_uv + rtParams2.xy;
OUT_uv3 = IN_uv + rtParams3.xy;
*/
/*
OUT_hpos = IN_pos;
OUT_uv0 = IN_uv * rtParams0.zw;
OUT_uv1 = IN_uv * rtParams1.zw;
OUT_uv2 = IN_uv * rtParams2.zw;
OUT_uv3 = IN_uv * rtParams3.zw;
*/
OUT_hpos = IN_pos;
OUT_uv0 = viewportCoordToRenderTarget( IN_uv, rtParams0 );
OUT_uv1 = viewportCoordToRenderTarget( IN_uv, rtParams1 ); // + vec2( -5, 1 ) * oneOverTargetSize;
OUT_uv2 = viewportCoordToRenderTarget( IN_uv, rtParams2 );
OUT_uv3 = viewportCoordToRenderTarget( IN_uv, rtParams3 );
OUT_wsEyeRay = IN_wsEyeRay;
correctSSP(gl_Position);
}

View file

@ -0,0 +1,68 @@
//-----------------------------------------------------------------------------
// 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"
in vec3 wsEyeRay;
#define IN_wsEyeRay wsEyeRay
in vec2 uv0;
#define IN_uv0 uv0
in vec2 uv1;
#define IN_uv1 uv1
in vec2 uv2;
#define IN_uv2 uv2
in vec2 uv3;
#define IN_uv3 uv3
in vec2 uv4;
#define IN_uv4 uv4
in vec2 uv5;
#define IN_uv5 uv5
in vec2 uv6;
#define IN_uv6 uv6
in vec2 uv7;
#define IN_uv7 uv7
#define OUT OUT_FragColor0
uniform sampler2D diffuseMap;
void main()
{
vec4 kernel = vec4( 0.175, 0.275, 0.375, 0.475 ) * 0.5 / 1.3; //25f;
OUT = vec4(0);
OUT += texture( diffuseMap, IN_uv0 ) * kernel.x;
OUT += texture( diffuseMap, IN_uv1 ) * kernel.y;
OUT += texture( diffuseMap, IN_uv2 ) * kernel.z;
OUT += texture( diffuseMap, IN_uv3 ) * kernel.w;
OUT += texture( diffuseMap, IN_uv4 ) * kernel.x;
OUT += texture( diffuseMap, IN_uv5 ) * kernel.y;
OUT += texture( diffuseMap, IN_uv6 ) * kernel.z;
OUT += texture( diffuseMap, IN_uv7 ) * kernel.w;
// Calculate a lumenance value in the alpha so we
// can use alpha test to save fillrate.
//vec3 rgb2lum = vec3( 0.30, 0.59, 0.11 );
//OUT.a = dot( OUT.rgb, rgb2lum );
}

View file

@ -0,0 +1,91 @@
//-----------------------------------------------------------------------------
// 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 "../../../gl/torque.glsl"
in vec4 vPosition;
in vec2 vTexCoord0;
in vec3 vTexCoord1;
#define IN_pos vPosition
#define _IN_uv vTexCoord0
#define IN_wsEyeRay vTexCoord1
#define OUT_hpos gl_Position
out vec3 wsEyeRay;
#define OUT_wsEyeRay wsEyeRay
out vec2 uv0;
#define OUT_uv0 uv0
out vec2 uv1;
#define OUT_uv1 uv1
out vec2 uv2;
#define OUT_uv2 uv2
out vec2 uv3;
#define OUT_uv3 uv3
out vec2 uv4;
#define OUT_uv4 uv4
out vec2 uv5;
#define OUT_uv5 uv5
out vec2 uv6;
#define OUT_uv6 uv6
out vec2 uv7;
#define OUT_uv7 uv7
uniform vec2 texSize0;
uniform vec4 rtParams0;
uniform vec2 oneOverTargetSize;
void main()
{
OUT_hpos = IN_pos;
vec2 IN_uv = viewportCoordToRenderTarget( _IN_uv, rtParams0 );
// I don't know why this offset is necessary, but it is.
//IN_uv = IN_uv * oneOverTargetSize;
OUT_uv0 = IN_uv + ( ( BLUR_DIR * 3.5f ) / texSize0 );
OUT_uv1 = IN_uv + ( ( BLUR_DIR * 2.5f ) / texSize0 );
OUT_uv2 = IN_uv + ( ( BLUR_DIR * 1.5f ) / texSize0 );
OUT_uv3 = IN_uv + ( ( BLUR_DIR * 0.5f ) / texSize0 );
OUT_uv4 = IN_uv - ( ( BLUR_DIR * 3.5f ) / texSize0 );
OUT_uv5 = IN_uv - ( ( BLUR_DIR * 2.5f ) / texSize0 );
OUT_uv6 = IN_uv - ( ( BLUR_DIR * 1.5f ) / texSize0 );
OUT_uv7 = IN_uv - ( ( BLUR_DIR * 0.5f ) / texSize0 );
/*
OUT_uv0 = viewportCoordToRenderTarget( OUT_uv0, rtParams0 );
OUT_uv1 = viewportCoordToRenderTarget( OUT_uv1, rtParams0 );
OUT_uv2 = viewportCoordToRenderTarget( OUT_uv2, rtParams0 );
OUT_uv3 = viewportCoordToRenderTarget( OUT_uv3, rtParams0 );
OUT_uv4 = viewportCoordToRenderTarget( OUT_uv4, rtParams0 );
OUT_uv5 = viewportCoordToRenderTarget( OUT_uv5, rtParams0 );
OUT_uv6 = viewportCoordToRenderTarget( OUT_uv6, rtParams0 );
OUT_uv7 = viewportCoordToRenderTarget( OUT_uv7, rtParams0 );
*/
correctSSP(gl_Position);
}

View file

@ -0,0 +1,69 @@
//-----------------------------------------------------------------------------
// 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 "../../../gl/torque.glsl"
#include "../../gl/postFX.glsl"
uniform vec4 rtParams0;
uniform vec4 rtParams1;
uniform vec4 rtParams2;
uniform vec4 rtParams3;
void main()
{
/*
OUT.hpos = IN_pos;
OUT_uv0 = IN_uv;
OUT_uv1 = IN_uv;
OUT_uv2 = IN_uv;
OUT_uv3 = IN_uv;
*/
/*
OUT_hpos = IN_pos;
OUT_uv0 = IN_uv + rtParams0.xy;
OUT_uv1 = IN_uv + rtParams1.xy;
OUT_uv2 = IN_uv + rtParams2.xy;
OUT_uv3 = IN_uv + rtParams3.xy;
*/
/*
OUT_hpos = IN_pos;
OUT_uv0 = IN_uv * rtParams0.zw;
OUT_uv1 = IN_uv * rtParams1.zw;
OUT_uv2 = IN_uv * rtParams2.zw;
OUT_uv3 = IN_uv * rtParams3.zw;
*/
OUT_hpos = IN_pos;
OUT_uv0 = viewportCoordToRenderTarget( IN_uv, rtParams0 );
OUT_uv1 = viewportCoordToRenderTarget( IN_uv, rtParams1 );
OUT_uv2 = viewportCoordToRenderTarget( IN_uv, rtParams2 );
OUT_uv3 = viewportCoordToRenderTarget( IN_uv, rtParams3 );
OUT_wsEyeRay = IN_wsEyeRay;
correctSSP(gl_Position);
}

View file

@ -0,0 +1,44 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
// This vertex and pixel shader applies a 3 x 3 blur to the image in
// colorMapSampler, which is the same size as the render target.
// The sample weights are 1/16 in the corners, 2/16 on the edges,
// and 4/16 in the center.
#include "../../../gl/hlslCompat.glsl"
uniform sampler2D colorSampler; // Output of DofNearCoc()
in vec4 texCoords;
#define IN_texCoords texCoords
void main()
{
vec4 color;
color = vec4(0.0);
color += texture( colorSampler, IN_texCoords.xz );
color += texture( colorSampler, IN_texCoords.yz );
color += texture( colorSampler, IN_texCoords.xw );
color += texture( colorSampler, IN_texCoords.yw );
OUT_FragColor0 = color / 4.0;
}

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.
//-----------------------------------------------------------------------------
// This vertex and pixel shader applies a 3 x 3 blur to the image in
// colorMapSampler, which is the same size as the render target.
// The sample weights are 1/16 in the corners, 2/16 on the edges,
// and 4/16 in the center.
#include "../../../gl/hlslCompat.glsl"
#include "../../../gl/torque.glsl"
in vec4 vPosition;
in vec2 vTexCoord0;
#define IN_position vPosition
#define IN_texCoords vTexCoord0
#define OUT_position gl_Position
out vec4 texCoords;
#define OUT_texCoords texCoords
uniform vec2 oneOverTargetSize;
uniform vec4 rtParams0;
void main()
{
const vec4 halfPixel = vec4( -0.5, 0.5, -0.5, 0.5 );
OUT_position = IN_position; //Transform_ObjectToClip( IN_position );
//vec2 uv = IN_texCoords + rtParams0.xy;
vec2 uv = viewportCoordToRenderTarget( IN_texCoords, rtParams0 );
OUT_texCoords = uv.xxyy + halfPixel * oneOverTargetSize.xxyy;
correctSSP(gl_Position);
}

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 "../../../gl/hlslCompat.glsl"
#include "shadergen:/autogenConditioners.h"
in vec2 uv0;
#define IN_uv0 uv0
uniform sampler2D edgeBuffer;
void main()
{
OUT_FragColor0 = vec4( texture( edgeBuffer, IN_uv0 ).rrr, 1.0 );
}

View file

@ -0,0 +1,68 @@
//-----------------------------------------------------------------------------
// 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 "../../gl/postFX.glsl"
uniform sampler2D edgeBuffer;
uniform sampler2D backBuffer;
uniform vec2 targetSize;
void main()
{
vec2 pixelSize = 1.0 / targetSize;
// Sample edge buffer, bail if not on an edge
float edgeSample = texture(edgeBuffer, IN_uv0).r;
clip(edgeSample - 1e-6);
// Ok we're on an edge, so multi-tap sample, average, and return
vec2 offsets[9] = vec2[](
vec2( 0.0, 0.0),
vec2(-1.0, -1.0),
vec2( 0.0, -1.0),
vec2( 1.0, -1.0),
vec2( 1.0, 0.0),
vec2( 1.0, 1.0),
vec2( 0.0, 1.0),
vec2(-1.0, 1.0),
vec2(-1.0, 0.0)
);
vec4 accumColor = vec4(0.0);
for(int i = 0; i < 9; i++)
{
// Multiply the intensity of the edge, by the UV, so that things which maybe
// aren't quite full edges get sub-pixel sampling to reduce artifacts
// Scaling offsets by 0.5 to reduce the range bluriness from extending to
// far outward from the edge.
vec2 offsetUV = IN_uv1 + edgeSample * ( offsets[i] * 0.5 ) * pixelSize;//rtWidthHeightInvWidthNegHeight.zw;
//offsetUV *= 0.999;
accumColor+= texture(backBuffer, offsetUV);
}
accumColor /= 9.0;
OUT_FragColor0 = accumColor;
}

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 "../../../gl/hlslCompat.glsl"
#include "../../../gl/torque.glsl"
#include "../../gl/postFX.glsl"
uniform vec4 rtParams0;
uniform vec4 rtParams1;
uniform vec4 rtParams2;
uniform vec4 rtParams3;
void main()
{
OUT_hpos = IN_pos;
OUT_uv0 = viewportCoordToRenderTarget( IN_uv, rtParams0 );
OUT_uv1 = viewportCoordToRenderTarget( IN_uv, rtParams1 );
OUT_uv2 = viewportCoordToRenderTarget( IN_uv, rtParams2 );
OUT_uv3 = viewportCoordToRenderTarget( IN_uv, rtParams3 );
OUT_wsEyeRay = IN_wsEyeRay;
correctSSP(gl_Position);
}

View file

@ -0,0 +1,94 @@
//-----------------------------------------------------------------------------
// 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"
// GPU Gems 3, pg 443-444
float GetEdgeWeight(vec2 uv0, in sampler2D prepassBuffer, in vec2 targetSize)
{
vec2 offsets[9] = vec2[](
vec2( 0.0, 0.0),
vec2(-1.0, -1.0),
vec2( 0.0, -1.0),
vec2( 1.0, -1.0),
vec2( 1.0, 0.0),
vec2( 1.0, 1.0),
vec2( 0.0, 1.0),
vec2(-1.0, 1.0),
vec2(-1.0, 0.0)
);
vec2 PixelSize = 1.0 / targetSize;
float Depth[9];
vec3 Normal[9];
for(int i = 0; i < 9; i++)
{
vec2 uv = uv0 + offsets[i] * PixelSize;
vec4 gbSample = prepassUncondition( prepassBuffer, uv );
Depth[i] = gbSample.a;
Normal[i] = gbSample.rgb;
}
vec4 Deltas1 = vec4(Depth[1], Depth[2], Depth[3], Depth[4]);
vec4 Deltas2 = vec4(Depth[5], Depth[6], Depth[7], Depth[8]);
Deltas1 = abs(Deltas1 - Depth[0]);
Deltas2 = abs(Depth[0] - Deltas2);
vec4 maxDeltas = max(Deltas1, Deltas2);
vec4 minDeltas = max(min(Deltas1, Deltas2), 0.00001);
vec4 depthResults = step(minDeltas * 25.0, maxDeltas);
Deltas1.x = dot(Normal[1], Normal[0]);
Deltas1.y = dot(Normal[2], Normal[0]);
Deltas1.z = dot(Normal[3], Normal[0]);
Deltas1.w = dot(Normal[4], Normal[0]);
Deltas2.x = dot(Normal[5], Normal[0]);
Deltas2.y = dot(Normal[6], Normal[0]);
Deltas2.z = dot(Normal[7], Normal[0]);
Deltas2.w = dot(Normal[8], Normal[0]);
Deltas1 = abs(Deltas1 - Deltas2);
vec4 normalResults = step(0.4, Deltas1);
normalResults = max(normalResults, depthResults);
return dot(normalResults, vec4(1.0, 1.0, 1.0, 1.0)) * 0.25;
}
in vec2 uv0;
#define IN_uv0 uv0
uniform sampler2D prepassBuffer;
uniform vec2 targetSize;
void main()
{
OUT_FragColor0 = vec4( GetEdgeWeight(IN_uv0, prepassBuffer, targetSize ) );//rtWidthHeightInvWidthNegHeight.zw);
}

View file

@ -44,7 +44,7 @@ Etc.
(2.) (2.)
Then include this file, Then include this file,
#include "Fxaa3_11.h" include "Fxaa3_11.h"
(3.) (3.)
Then call the FXAA pixel shader from within your desired shader. Then call the FXAA pixel shader from within your desired shader.

Some files were not shown because too many files have changed in this diff Show more