| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386 |
- /**
- * Copyright (C) 2011 Jorge Jimenez (jorge@iryoku.com)
- * Copyright (C) 2011 Belen Masia (bmasia@unizar.es)
- * Copyright (C) 2011 Jose I. Echevarria (joseignacioechevarria@gmail.com)
- * Copyright (C) 2011 Fernando Navarro (fernandn@microsoft.com)
- * Copyright (C) 2011 Diego Gutierrez (diegog@unizar.es)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution:
- *
- * "Uses SMAA. Copyright (C) 2011 by Jorge Jimenez, Jose I. Echevarria,
- * Belen Masia, Fernando Navarro and Diego Gutierrez."
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
- * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- * The views and conclusions contained in the software and documentation are
- * those of the authors and should not be interpreted as representing official
- * policies, either expressed or implied, of the copyright holders.
- */
- //Include SweetFX settings
- #include "SweetFX_preset.txt"
- /**
- * Setup mandatory defines. Use a real macro here for maximum performance!
- */
- #ifndef SMAA_PIXEL_SIZE // It's actually set on runtime, this is for compilation time syntax checking.
- #define SMAA_PIXEL_SIZE float2(1.0 / 1280.0, 1.0 / 720.0)
- #endif
- /**
- * This is only required for temporal modes (SMAA T2x).
- */
- int4 subsampleIndices;
- /*
- #define SMAA_PRESET_CUSTOM
- #ifdef SMAA_PRESET_CUSTOM
- #define SMAA_THRESHOLD threshld
- #define SMAA_MAX_SEARCH_STEPS maxSearchSteps
- #define SMAA_MAX_SEARCH_STEPS_DIAG maxSearchStepsDiag
- #define SMAA_CORNER_ROUNDING cornerRounding
- #define SMAA_FORCE_DIAGONAL_DETECTION 1
- #define SMAA_FORCE_CORNER_DETECTION 1
- #endif
- */
- // Set the HLSL version:
- #ifndef SMAA_HLSL_4_1
- #define SMAA_HLSL_4 1
- #endif
- /*
- #ifdef SMAA_PRESET_CUSTOM
- #include "SMAA_settings.h" //include custom settings
- #endif
- */
- // And include our header!
- #include "SweetFX\Shaders\SMAA.h"
- // Set pixel shader version accordingly:
- #if SMAA_HLSL_4_1 == 1
- #define PS_VERSION ps_4_1
- #else
- #define PS_VERSION ps_4_0
- #endif
- /**
- * DepthStencilState's and company
- */
- DepthStencilState DisableDepthStencil {
- DepthEnable = FALSE;
- StencilEnable = FALSE;
- };
- DepthStencilState DisableDepthReplaceStencil {
- DepthEnable = FALSE;
- StencilEnable = TRUE;
- FrontFaceStencilPass = REPLACE;
- };
- DepthStencilState DisableDepthUseStencil {
- DepthEnable = FALSE;
- StencilEnable = TRUE;
- FrontFaceStencilFunc = EQUAL;
- };
- BlendState NoBlending {
- AlphaToCoverageEnable = FALSE;
- BlendEnable[0] = FALSE;
- };
- /**
- * Input textures
- */
- Texture2D colorTexPrev;
- Texture2D colorTex;
- Texture2D colorTexGamma;
- Texture2D depthTex;
- Texture2D velocityTex;
- /**
- * Temporal textures
- */
- Texture2D edgesTex;
- Texture2D blendTex;
- /**
- * Pre-computed area and search textures
- */
- Texture2D areaTex;
- Texture2D searchTex;
- #include "SweetFX/Shaders/Main.h"
- /**
- * Function wrappers
- */
- void DX10_SMAAEdgeDetectionVS(float4 position : POSITION,
- out float4 svPosition : SV_POSITION,
- inout float2 texcoord : TEXCOORD0,
- out float4 offset[3] : TEXCOORD1) {
- SMAAEdgeDetectionVS(position, svPosition, texcoord, offset);
- }
- void DX10_SMAABlendWeightCalculationVS(float4 position : POSITION,
- out float4 svPosition : SV_POSITION,
- inout float2 texcoord : TEXCOORD0,
- out float2 pixcoord : TEXCOORD1,
- out float4 offset[3] : TEXCOORD2) {
- SMAABlendWeightCalculationVS(position, svPosition, texcoord, pixcoord, offset);
- }
- void DX10_SMAANeighborhoodBlendingVS(float4 position : POSITION,
- out float4 svPosition : SV_POSITION,
- inout float2 texcoord : TEXCOORD0,
- out float4 offset[2] : TEXCOORD1) {
- SMAANeighborhoodBlendingVS(position, svPosition, texcoord, offset);
- }
- void DX10_SMAAResolveVS(float4 position : POSITION,
- out float4 svPosition : SV_POSITION,
- inout float2 texcoord : TEXCOORD0) {
- SMAAResolveVS(position, svPosition, texcoord);
- }
- [earlydepthstencil]
- float4 DX10_SMAALumaEdgeDetectionPS(float4 position : SV_POSITION,
- float2 texcoord : TEXCOORD0,
- float4 offset[3] : TEXCOORD1,
- uniform SMAATexture2D colorTexGamma) : SV_TARGET {
- #if SMAA_PREDICATION == 1
- return SMAALumaEdgeDetectionPS(texcoord, offset, colorTexGamma, depthTex);
- #else
- return SMAALumaEdgeDetectionPS(texcoord, offset, colorTexGamma);
- #endif
- }
- [earlydepthstencil]
- float4 DX10_SMAAColorEdgeDetectionPS(float4 position : SV_POSITION,
- float2 texcoord : TEXCOORD0,
- float4 offset[3] : TEXCOORD1,
- uniform SMAATexture2D colorTexGamma) : SV_TARGET {
- #if SMAA_PREDICATION == 1
- return SMAAColorEdgeDetectionPS(texcoord, offset, colorTexGamma, depthTex);
- #else
- return SMAAColorEdgeDetectionPS(texcoord, offset, colorTexGamma);
- #endif
- }
- [earlydepthstencil]
- float4 DX10_SMAADepthEdgeDetectionPS(float4 position : SV_POSITION,
- float2 texcoord : TEXCOORD0,
- float4 offset[3] : TEXCOORD1,
- uniform SMAATexture2D depthTex) : SV_TARGET {
- return SMAADepthEdgeDetectionPS(texcoord, offset, depthTex);
- }
- [earlydepthstencil]
- float4 DX10_SMAABlendingWeightCalculationPS(float4 position : SV_POSITION,
- float2 texcoord : TEXCOORD0,
- float2 pixcoord : TEXCOORD1,
- float4 offset[3] : TEXCOORD2,
- uniform SMAATexture2D edgesTex,
- uniform SMAATexture2D areaTex,
- uniform SMAATexture2D searchTex) : SV_TARGET {
- return SMAABlendingWeightCalculationPS(texcoord, pixcoord, offset, edgesTex, areaTex, searchTex, subsampleIndices);
- }
- [earlydepthstencil]
- float4 DX10_SMAANeighborhoodBlendingPS(float4 position : SV_POSITION,
- float2 texcoord : TEXCOORD0,
- float4 offset[2] : TEXCOORD1,
- uniform SMAATexture2D colorTex,
- uniform SMAATexture2D blendTex) : SV_TARGET {
-
- float4 SMAAoutput = SMAANeighborhoodBlendingPS(texcoord, offset, colorTex, blendTex);
-
- SMAAoutput = SweetFX_main(texcoord,SMAAoutput); // Add the other effects
- return SMAAoutput; //Returning the pixel
- }
- [earlydepthstencil]
- float4 DX10_SMAAResolvePS(float4 position : SV_POSITION,
- float2 texcoord : TEXCOORD0,
- uniform SMAATexture2D colorTex,
- uniform SMAATexture2D colorTexPrev,
- uniform SMAATexture2D velocityTex) : SV_TARGET {
- #if SMAA_REPROJECTION == 1
- return SMAAResolvePS(texcoord, colorTex, colorTexPrev, velocityTex);
- #else
- return SMAAResolvePS(texcoord, colorTex, colorTexPrev);
- #endif
- }
- #if (USE_SMAA_ANTIALIASING == 1)
- /**
- * Edge detection techniques
- */
- technique10 LumaEdgeDetection {
- pass LumaEdgeDetection {
- SetVertexShader(CompileShader(vs_4_0, DX10_SMAAEdgeDetectionVS()));
- SetGeometryShader(NULL);
- #if COLOR_EDGE_DETECTION == 1
- SetPixelShader(CompileShader(PS_VERSION, DX10_SMAAColorEdgeDetectionPS(colorTexGamma)));
- #else
- SetPixelShader(CompileShader(PS_VERSION, DX10_SMAALumaEdgeDetectionPS(colorTexGamma)));
- #endif
- SetDepthStencilState(DisableDepthReplaceStencil, 1);
- SetBlendState(NoBlending, float4(0.0f, 0.0f, 0.0f, 0.0f), 0xFFFFFFFF);
- }
- }
- technique10 ColorEdgeDetection {
- pass ColorEdgeDetection {
- SetVertexShader(CompileShader(vs_4_0, DX10_SMAAEdgeDetectionVS()));
- SetGeometryShader(NULL);
- SetPixelShader(CompileShader(PS_VERSION, DX10_SMAAColorEdgeDetectionPS(colorTexGamma)));
- SetDepthStencilState(DisableDepthReplaceStencil, 1);
- SetBlendState(NoBlending, float4(0.0f, 0.0f, 0.0f, 0.0f), 0xFFFFFFFF);
- }
- }
- technique10 DepthEdgeDetection {
- pass DepthEdgeDetection {
- SetVertexShader(CompileShader(vs_4_0, DX10_SMAAEdgeDetectionVS()));
- SetGeometryShader(NULL);
- SetPixelShader(CompileShader(PS_VERSION, DX10_SMAADepthEdgeDetectionPS(depthTex)));
- SetDepthStencilState(DisableDepthReplaceStencil, 1);
- SetBlendState(NoBlending, float4(0.0f, 0.0f, 0.0f, 0.0f), 0xFFFFFFFF);
- }
- }
- /**
- * Blending weight calculation technique
- */
- technique10 BlendingWeightCalculation {
- pass BlendingWeightCalculation {
- SetVertexShader(CompileShader(vs_4_0, DX10_SMAABlendWeightCalculationVS()));
- SetGeometryShader(NULL);
- SetPixelShader(CompileShader(PS_VERSION, DX10_SMAABlendingWeightCalculationPS(edgesTex, areaTex, searchTex)));
- SetDepthStencilState(DisableDepthUseStencil, 1);
- SetBlendState(NoBlending, float4(0.0f, 0.0f, 0.0f, 0.0f), 0xFFFFFFFF);
- }
- }
- /**
- * Neighborhood blending technique
- */
- technique10 NeighborhoodBlending {
- pass NeighborhoodBlending {
- SetVertexShader(CompileShader(vs_4_0, DX10_SMAANeighborhoodBlendingVS()));
- SetGeometryShader(NULL);
- SetPixelShader(CompileShader(PS_VERSION, DX10_SMAANeighborhoodBlendingPS(colorTex, blendTex)));
- SetDepthStencilState(DisableDepthStencil, 0);
- SetBlendState(NoBlending, float4(0.0f, 0.0f, 0.0f, 0.0f), 0xFFFFFFFF);
- }
- }
- /**
- * Temporal resolve technique
- */
- technique10 Resolve {
- pass Resolve {
- SetVertexShader(CompileShader(vs_4_0, DX10_SMAAResolveVS()));
- SetGeometryShader(NULL);
- SetPixelShader(CompileShader(PS_VERSION, DX10_SMAAResolvePS(colorTex, colorTexPrev, velocityTex)));
- SetDepthStencilState(DisableDepthStencil, 0);
- SetBlendState(NoBlending, float4(0.0f, 0.0f, 0.0f, 0.0f), 0xFFFFFFFF);
- }
- }
- #else //SMAA off
- /*------------------------.
- | :: SweetFX - structs :: |
- '------------------------*/
- struct Output
- {
- float4 position_cs : SV_POSITION;
- float2 texcoord : TEXCOORD;
- };
- /*---------------------------------------.
- | :: SweetFX - SMAA_off vertex shader :: |
- '---------------------------------------*/
- Output DX10_SMAA_off_VS(uint id: SV_VertexID) {
-
- Output output;
-
- output.texcoord = float2((id << 1) & 2, id & 2);
- output.position_cs = float4(output.texcoord * float2(2, -2) + float2(-1, 1), 0, 1);
- return output;
- }
- /*--------------------------------------.
- | :: SweetFX - SMAA_off pixel shader :: |
- '--------------------------------------*/
- [earlydepthstencil]
- float4 main(float4 position : SV_POSITION,
- float2 texcoord : TEXCOORD0,
- /*float4 offset[2] : TEXCOORD1,*/
- uniform SMAATexture2D colorTexGamma) : SV_TARGET {
-
- float4 SMAAoutput = myTex2D(colorTexGamma, texcoord);
- SMAAoutput = SweetFX_main(texcoord,SMAAoutput); // Add the other effects
- return SMAAoutput; //Returning the pixel
- }
- /*--------------------------.
- | :: SweetFX - Technique :: |
- '--------------------------*/
- /**
- * SMAA_off technique
- */
- technique10 LumaEdgeDetection {
- pass LumaEdgeDetection {
- SetVertexShader(CompileShader(vs_4_0, DX10_SMAA_off_VS()));
- SetGeometryShader(NULL);
- SetPixelShader(CompileShader(PS_VERSION, main(colorTexGamma)));
- SetDepthStencilState(DisableDepthStencil, 0); //SetDepthStencilState(DisableDepthReplaceStencil, 1);
- SetBlendState(NoBlending, float4(0.0f, 0.0f, 0.0f, 0.0f), 0xFFFFFFFF);
- }
- }
- #endif
|