mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-16 09:04:38 +00:00
Templates changes for OpenGL shaders.
This commit is contained in:
parent
c354f59b72
commit
5bcd1458c4
140 changed files with 9210 additions and 6 deletions
|
|
@ -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 );
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue