Anyone familiar with shaders and able to tell me how this works?
Shader:
Include ( less likely to be crucial ) :
I know the general principle of working with Post Processing shaders now, thanks to a simple tutorial I read. I can now implement Post_Bloom, Post_Negative and Post Sepia just fine, but Post_Halo is kicking my butt.
I've tried pretty much every combination I can think of but to no avail so if someone could give me an idea of what I need to be doing in my app, that would be very helpful.
At the moment, I'm rendering the current view to GlowMap1, then drawing back to the screen with Passes 1 and 2, but I've tried drawing to GlowMap2 with Pass 1 and then drawing back to the screen with Pass 2 and various other combinations. There's something here I'm not getting. Something which is different between how this shader works and how the others I already have working work.
Any ideas?
Shader:
/*********************************************************************NVMH3**** File: $Id: //sw/devtools/SDK/9.5/SDK/MEDIA/HLSL/post_halo.fx#3 $ Copyright NVIDIA Corporation 2004 TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED *AS IS* AND NVIDIA AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL NVIDIA OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Comments: Render-to-Texture (RTT) glow example. Blurs is done in two separable passes. ******************************************************************************/ #include "Quad.fxh" float Script : STANDARDSGLOBAL < string UIWidget = "none"; string ScriptClass = "scene"; string ScriptOrder = "postprocess"; string ScriptOutput = "color"; string Script = "Technique=Main;"; > = 0.8; // version # float4 ClearColor < string UIWidget = "color"; string UIName = "background"; > = {0,0,0,0}; float ClearDepth <string UIWidget = "none";> = 1.0; /////////////////////////////////////////////////////////// /////////////////////////////////////// Tweakables //////// /////////////////////////////////////////////////////////// float4 GlowCol < string UIName = "Glow Color"; string UIWidget = "Color"; > = {0.0f, 1.0f, 0.0f, 1.0f}; float Glowness < string UIName = "Glow Strength"; string UIWidget = "slider"; float UIMin = 0.0f; float UIMax = 3.0f; float UIStep = 0.02f; > = 1.6f; /////////////////////////////////////////////////////////// ///////////////////////////// Render-to-Texture Data ////// /////////////////////////////////////////////////////////// DECLARE_QUAD_TEX(GlowMap1,GlowSamp1,"A8R8G8B8") DECLARE_QUAD_TEX(GlowMap2,GlowSamp2,"A8R8G8B8") DECLARE_QUAD_DEPTH_BUFFER(DepthBuffer,"D24S8") /////////////////////////////////////////////////////////// /////////////////////////////////// data structures /////// /////////////////////////////////////////////////////////// struct VS_OUTPUT_BLUR { float4 Position : POSITION; float4 TexCoord0 : TEXCOORD0; float4 TexCoord1 : TEXCOORD1; float4 TexCoord2 : TEXCOORD2; float4 TexCoord3 : TEXCOORD3; float4 TexCoord4 : TEXCOORD4; float4 TexCoord5 : TEXCOORD5; float4 TexCoord6 : TEXCOORD6; float4 TexCoord7 : TEXCOORD7; float4 TexCoord8 : COLOR1; }; //////////////////////////////////////////////////////////// ////////////////////////////////// vertex shaders ////////// //////////////////////////////////////////////////////////// VS_OUTPUT_BLUR VS_Quad_Horizontal_9tap(float3 Position : POSITION, float3 TexCoord : TEXCOORD0) { VS_OUTPUT_BLUR OUT = (VS_OUTPUT_BLUR)0; OUT.Position = float4(Position, 1); float TexelIncrement = 1/QuadScreenSize.x; float3 Coord = float3(TexCoord.x, TexCoord.y, 1); OUT.TexCoord0 = float4(Coord.x + TexelIncrement, Coord.y, TexCoord.z, 1); OUT.TexCoord1 = float4(Coord.x + TexelIncrement * 2, Coord.y, TexCoord.z, 1); OUT.TexCoord2 = float4(Coord.x + TexelIncrement * 3, Coord.y, TexCoord.z, 1); OUT.TexCoord3 = float4(Coord.x + TexelIncrement * 4, Coord.y, TexCoord.z, 1); OUT.TexCoord4 = float4(Coord.x, Coord.y, TexCoord.z, 1); OUT.TexCoord5 = float4(Coord.x - TexelIncrement, Coord.y, TexCoord.z, 1); OUT.TexCoord6 = float4(Coord.x - TexelIncrement * 2, Coord.y, TexCoord.z, 1); OUT.TexCoord7 = float4(Coord.x - TexelIncrement * 3, Coord.y, TexCoord.z, 1); OUT.TexCoord8 = float4(Coord.x - TexelIncrement * 4, Coord.y, TexCoord.z, 1); return OUT; } VS_OUTPUT_BLUR VS_Quad_Vertical_9tap(float3 Position : POSITION, float3 TexCoord : TEXCOORD0) { VS_OUTPUT_BLUR OUT = (VS_OUTPUT_BLUR)0; OUT.Position = float4(Position, 1); float TexelIncrement = 1/QuadScreenSize.y; float3 Coord = float3(TexCoord.x, TexCoord.y, 1); OUT.TexCoord0 = float4(Coord.x, Coord.y + TexelIncrement, TexCoord.z, 1); OUT.TexCoord1 = float4(Coord.x, Coord.y + TexelIncrement * 2, TexCoord.z, 1); OUT.TexCoord2 = float4(Coord.x, Coord.y + TexelIncrement * 3, TexCoord.z, 1); OUT.TexCoord3 = float4(Coord.x, Coord.y + TexelIncrement * 4, TexCoord.z, 1); OUT.TexCoord4 = float4(Coord.x, Coord.y, TexCoord.z, 1); OUT.TexCoord5 = float4(Coord.x, Coord.y - TexelIncrement, TexCoord.z, 1); OUT.TexCoord6 = float4(Coord.x, Coord.y - TexelIncrement * 2, TexCoord.z, 1); OUT.TexCoord7 = float4(Coord.x, Coord.y - TexelIncrement * 3, TexCoord.z, 1); OUT.TexCoord8 = float4(Coord.x, Coord.y - TexelIncrement * 4, TexCoord.z, 1); return OUT; } ////////////////////////////////////////////////////// ////////////////////////////////// pixel shaders ///// ////////////////////////////////////////////////////// // For two-pass blur, we have chosen to do the horizontal blur FIRST. The // vertical pass includes a post-blur scale factor. // Relative filter weights indexed by distance from "home" texel // This set for 9-texel sampling #define WT9_0 1.0 #define WT9_1 0.8 #define WT9_2 0.6 #define WT9_3 0.4 #define WT9_4 0.2 // Alt pattern -- try your own! // #define WT9_0 0.1 // #define WT9_1 0.2 // #define WT9_2 3.0 // #define WT9_3 1.0 // #define WT9_4 0.4 #define WT9_NORMALIZE (WT9_0+2.0*(WT9_1+WT9_2+WT9_3+WT9_4)) float4 PS_Blur_Horizontal_9tap(VS_OUTPUT_BLUR IN) : COLOR { float OutCol = tex2D(GlowSamp1, IN.TexCoord0).w * (WT9_1/WT9_NORMALIZE); OutCol += tex2D(GlowSamp1, IN.TexCoord1).w * (WT9_2/WT9_NORMALIZE); OutCol += tex2D(GlowSamp1, IN.TexCoord2).w * (WT9_3/WT9_NORMALIZE); OutCol += tex2D(GlowSamp1, IN.TexCoord3).w * (WT9_4/WT9_NORMALIZE); OutCol += tex2D(GlowSamp1, IN.TexCoord4).w * (WT9_0/WT9_NORMALIZE); OutCol += tex2D(GlowSamp1, IN.TexCoord5).w * (WT9_1/WT9_NORMALIZE); OutCol += tex2D(GlowSamp1, IN.TexCoord6).w * (WT9_2/WT9_NORMALIZE); OutCol += tex2D(GlowSamp1, IN.TexCoord7).w * (WT9_3/WT9_NORMALIZE); OutCol += tex2D(GlowSamp1, IN.TexCoord8).w * (WT9_4/WT9_NORMALIZE); return OutCol.xxxx; } float4 PS_Blur_Vertical_9tap(VS_OUTPUT_BLUR IN) : COLOR { float OutCol = tex2D(GlowSamp2, IN.TexCoord0).x * (WT9_1/WT9_NORMALIZE); OutCol += tex2D(GlowSamp2, IN.TexCoord1).x * (WT9_2/WT9_NORMALIZE); OutCol += tex2D(GlowSamp2, IN.TexCoord2).x * (WT9_3/WT9_NORMALIZE); OutCol += tex2D(GlowSamp2, IN.TexCoord3).x * (WT9_4/WT9_NORMALIZE); OutCol += tex2D(GlowSamp2, IN.TexCoord4).x * (WT9_0/WT9_NORMALIZE); OutCol += tex2D(GlowSamp2, IN.TexCoord5).x * (WT9_1/WT9_NORMALIZE); OutCol += tex2D(GlowSamp2, IN.TexCoord6).x * (WT9_2/WT9_NORMALIZE); OutCol += tex2D(GlowSamp2, IN.TexCoord7).x * (WT9_3/WT9_NORMALIZE); OutCol += tex2D(GlowSamp2, IN.TexCoord8).x * (WT9_4/WT9_NORMALIZE); float4 glo = (Glowness*OutCol)*GlowCol; float4 orig = tex2D(GlowSamp1,IN.TexCoord4); float4 final = orig + (1.0-orig.w)*glo; return final; } //////////////////////////////////////////////////////////// /////////////////////////////////////// techniques ///////// //////////////////////////////////////////////////////////// technique Main < string ScriptClass = "scene"; string ScriptOrder = "postprocess"; string ScriptOutput = "color"; string Script = "RenderColorTarget0=GlowMap1;" "RenderDepthStencilTarget=DepthBuffer;" "ClearSetColor=ClearColor;" "ClearSetDepth=ClearDepth;" "Clear=Color;" "Clear=Depth;" "ScriptExternal=color;" "Pass=BlurGlowBuffer_Horz;" "Pass=BlurGlowBuffer_Vert;"; > { pass BlurGlowBuffer_Horz < string Script ="RenderColorTarget0=GlowMap2;" "Draw=Buffer;"; > { cullmode = none; ZEnable = false; AlphaBlendEnable = false; VertexShader = compile vs_2_0 VS_Quad_Horizontal_9tap(); PixelShader = compile ps_2_0 PS_Blur_Horizontal_9tap(); } pass BlurGlowBuffer_Vert < string Script = "RenderColorTarget0=;" "Draw=Buffer;"; > { cullmode = none; ZEnable = false; AlphaBlendEnable = false; VertexShader = compile vs_2_0 VS_Quad_Vertical_9tap(); PixelShader = compile ps_2_0 PS_Blur_Vertical_9tap(); } } ////////////// eof ///
Include ( less likely to be crucial ) :
/*********************************************************************NVMH3**** File: $Id: //sw/devtools/FXComposer/1.8/SDK/MEDIA/HLSL/Quad.fxh#1 $ Copyright NVIDIA Corporation 2004 TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED *AS IS* AND NVIDIA AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL NVIDIA OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Comments: Header file with lots of useful macros, types, and functions for use with textures and render-to-texture-buffer effects in DirectX. Example Macro Usages: Texture-declaration Macros: FILE_TEXTURE_2D(SurfTexture,SurfSampler,"myfile.dds") // simple 2D wrap texture FILE_TEXTURE_2D_MODAL(SpotTexture,SpotSampler,"myfile.dds",CLAMP) // user-defined addr mode RenderTarget Texture-declaration Macros: DECLARE_QUAD_TEX(ObjTexture,ObjSampler,"A8R8G8B8") DECLARE_QUAD_DEPTH_BUFFER(DepthTexture,"D24S8") DECLARE_SIZED_QUAD_TEX(GlowTexture,GlowSampler,"A8R8G8B8",0.5) // scaled versions of above DECLARE_SIZED_QUAD_DEPTH_BUFFER(DepthTexture,"D24S8",0.5) DECLARE_SIZED_TEX(BlahMap,BlahSampler,"R32F",128,1) // address mode is "clamp" DECLARE_SQUARE_QUAD_TEX(ShadTexture,ShadObjSampler,"A16R16G16B16F",512) // for shadows etc DECLARE_SQUARE_QUAD_DEPTH_BUFFER(ShadDepth,"D24S8",512) Data types used in shaders: QUAD_REAL & QUAD_REAL# -- defaults to HALF but you can define QUAD_REAL float before #including "Quad.fxh" either by explicitly declaring all the QUAD_REAL types yourself, or #define-ing the symbol QUAD_FLOAT Flags (define before #including "Quad.fxh"): TWEAKABLE_TEXEL_OFFSET // shows in paramter panel NO_TEXEL_OFFSET // disables Structure: QuadVertexOutput -- used by shaders, defines simple connection for "Draw=buffer" VS and PS Shader Functions for "Draw=buffer" passes: QuadVertexOutput ScreenQuadVS(): standard vertex shader for screen-aligned quads QUAD_REAL4 TexQuadPS(QuadVertexOutput IN,uniform sampler2D InputSampler) pass this pixel shader a sampler -- will draw it to the screen QUAD_REAL4 TexQuadBiasPS(QuadVertexOutput IN,uniform sampler2D InputSampler,QUAD_REAL TBias) Same as above, but uses tex2Dbias() Utility Functions for Texture-Based Lookup Tables: QUAD_REAL scale_lookup(QUAD_REAL Value,const QUAD_REAL TableSize) QUAD_REAL2 scale_lookup(QUAD_REAL2 Value,const QUAD_REAL TableSize) QUAD_REAL3 scale_lookup(QUAD_REAL3 Value,const QUAD_REAL TableSize) Other Utility Functions: QUAD_REAL4 premultiply(QUAD_REAL4 C) QUAD_REAL4 unpremultiply(QUAD_REAL4 C) // uses macro value NV_ALPHA_EPSILON Global Variables: QUAD_REAL QuadTexOffset // reconciles difference between pixel and texel centers QUAD_REAL2 QuadScreenSize // VIEWPORTPIXELSIZE, contains dimensions of render window ******************************************************************************/ #ifndef _QUAD_FXH #define _QUAD_FXH // Numeric types we are likely to encounter.... // Redefine these before including "Quad.fxh" if you want // to use a type other than "half" for these data or just // define the symbol QUAD_FLOAT to use "floats" #ifndef QUAD_REAL #ifdef QUAD_FLOAT #define QUAD_REAL float #define QUAD_REAL2 float2 #define QUAD_REAL3 float3 #define QUAD_REAL4 float4 #define QUAD_REAL3x3 float3x3 #define QUAD_REAL4x3 float4x3 #define QUAD_REAL3x4 float3x4 #define QUAD_REAL4x4 float4x4 #else /* ! QUAD_FLOAT */ #define QUAD_REAL half #define QUAD_REAL2 half2 #define QUAD_REAL3 half3 #define QUAD_REAL4 half4 #define QUAD_REAL3x3 half3x3 #define QUAD_REAL4x3 half4x3 #define QUAD_REAL3x4 half3x4 #define QUAD_REAL4x4 half4x4 #endif /* ! QUAD_FLOAT */ #endif /* ! QUAD_REAL */ /////////////////////////////////////////////////////////////////////// /// Texture-Declaration Macros //////////////////////////////////////// /////////////////////////////////////////////////////////////////////// // // Modal 2D File Textures // // example usage: FILE_TEXTURE_2D_MODAL(GlowMap,GlowSampler,"myfile.dds",CLAMP) // #define FILE_TEXTURE_2D_MODAL(TexName,SampName,Filename,AddrMode) texture TexName < \ string ResourceName = (Filename); \ string ResourceType = "2D"; \ >; \ sampler SampName = sampler_state { \ texture = <TexName>; \ AddressU = AddrMode; \ AddressV = AddrMode; \ MipFilter = LINEAR; \ MinFilter = LINEAR; \ MagFilter = LINEAR; \ }; // // Simple 2D File Textures // // example usage: FILE_TEXTURE_2D(GlowMap,GlowSampler,"myfile.dds") // #define FILE_TEXTURE_2D(TextureName,SamplerName,Diskfile) FILE_TEXTURE_2D_MODAL(TextureName,SamplerName,(Diskfile),WRAP) // // Use this variation of DECLARE_QUAD_TEX() if you want a *scaled* render target // // example usage: DECLARE_SIZED_QUAD_TEX(GlowMap,GlowSampler,"A8R8G8B8",1.0) #define DECLARE_SIZED_QUAD_TEX(TexName,SampName,PixFmt,Multiple) texture TexName : RENDERCOLORTARGET < \ float2 ViewPortRatio = {Multiple,Multiple}; \ int MipLevels = 1; \ string Format = PixFmt ; \ string UIWidget = "None"; \ >; \ sampler SampName = sampler_state { \ texture = <TexName>; \ AddressU = CLAMP; \ AddressV = CLAMP; \ MipFilter = POINT; \ MinFilter = LINEAR; \ MagFilter = LINEAR; \ }; // // Use this macro to easily declare typical color render targets // // example usage: DECLARE_QUAD_TEX(ObjMap,ObjSampler,"A8R8G8B8") #define DECLARE_QUAD_TEX(TextureName,SamplerName,PixelFormat) DECLARE_SIZED_QUAD_TEX(TextureName,SamplerName,(PixelFormat),1.0) // // Use this macro to easily declare variable-sized depth render targets // // example usage: DECLARE_SIZED_QUAD_DEPTH_BUFFER(DepthMap,"D24S8",0.5) #define DECLARE_SIZED_QUAD_DEPTH_BUFFER(TextureName,PixelFormat,Multiple) texture TextureName : RENDERDEPTHSTENCILTARGET < \ float2 ViewPortRatio = {Multiple,Multiple}; \ string Format = (PixelFormat); \ string UIWidget = "None"; \ >; // // Use this macro to easily declare typical depth render targets // // example usage: DECLARE_QUAD_DEPTH_BUFFER(DepthMap,"D24S8") #define DECLARE_QUAD_DEPTH_BUFFER(TexName,PixFmt) DECLARE_SIZED_QUAD_DEPTH_BUFFER(TexName,PixFmt,1.0) // // declare exact-sized arbitrary texture // // example usage: DECLARE_SIZED_TEX(BlahMap,BlahSampler,"R32F",128,1) #define DECLARE_SIZED_TEX(Tex,Samp,Fmt,Wd,Ht) texture Tex : RENDERCOLORTARGET < \ float2 Dimensions = { Wd, Ht }; \ string Format = Fmt ; \ string UIWidget = "None"; \ int miplevels=1;\ >; \ sampler Samp = sampler_state { \ texture = <Tex>; \ AddressU = CLAMP; \ AddressV = CLAMP; \ MipFilter = NONE; \ MinFilter = LINEAR; \ MagFilter = LINEAR; \ }; // // declare exact-sized square texture, as for shadow maps // // example usage: DECLARE_SQUARE_QUAD_TEX(ShadMap,ShadObjSampler,"A16R16G16B16F",512) #define DECLARE_SQUARE_QUAD_TEX(TexName,SampName,PixFmt,Size) DECLARE_SIZED_TEX(TexName,SampName,(PixFmt),Size,Size) // // likewise for shadow depth targets // // example usage: DECLARE_SQUARE_QUAD_DEPTH_BUFFER(ShadDepth,"D24S8",512) #define DECLARE_SQUARE_QUAD_DEPTH_BUFFER(TextureName,PixelFormat,Size) texture TextureName : RENDERDEPTHSTENCILTARGET < \ float2 Dimensions = { Size, Size }; \ string Format = (PixelFormat) ; \ string UIWidget = "None"; \ >; //////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////// Utility Functions //////// //////////////////////////////////////////////////////////////////////////// // // Scale inputs for use with texture-based lookup tables. A value ranging from zero to one needs // a slight scaling and offset to be sure to point at the centers of the first and last pixels // of that lookup texture. Pass the integer size of the table in TableSize // For now we'll assume that all tables are 1D, square, or cube-shaped -- all axes of equal size // // Cost of this operation for pixel shaders: two const-register // entries and a MAD (one cycle) QUAD_REAL scale_lookup(QUAD_REAL Value,const QUAD_REAL TableSize) { QUAD_REAL scale = ((TableSize - 1.0)/TableSize); QUAD_REAL shift = (0.5 / TableSize); return (scale*Value + shift); } QUAD_REAL2 scale_lookup(QUAD_REAL2 Value,const QUAD_REAL TableSize) { QUAD_REAL scale = ((TableSize - 1.0)/TableSize); QUAD_REAL shift = (0.5 / TableSize); return (scale.xx*Value + shift.xx); } QUAD_REAL3 scale_lookup(QUAD_REAL3 Value,const QUAD_REAL TableSize) { QUAD_REAL scale = ((TableSize - 1.0)/TableSize); QUAD_REAL shift = (0.5 / TableSize); return (scale.xxx*Value + shift.xxx); } // pre-multiply and un-pre-mutliply functions. The precision // of thse operatoions is often limited to 8-bit so don't // always count on them! // The macro value of NV_ALPHA_EPSILON, if defined, is used to // avoid IEEE "NaN" values that may occur when erroneously // dividing by a zero alpha (thanks to Pete Warden @ Apple // Computer for the suggestion in GPU GEMS II) // multiply color by alpha to turn an un-premultipied // pixel value into a premultiplied one QUAD_REAL4 premultiply(QUAD_REAL4 C) { return QUAD_REAL4((C.w*C.xyz),C.w); } #define NV_ALPHA_EPSILON 0.0001 // given a premultiplied pixel color, try to undo the premultiplication. // beware of precision errors QUAD_REAL4 unpremultiply(QUAD_REAL4 C) { #ifdef NV_ALPHA_EPSILON QUAD_REAL a = C.w + NV_ALPHA_EPSILON; return QUAD_REAL4((C.xyz / a),C.w); #else /* ! NV_ALPHA_EPSILON */ return QUAD_REAL4((C.xyz / C.w),C.w); #endif /* ! NV_ALPHA_EPSILON */ } ///////////////////////////////////////////////////////////////////////////////////// // Structure Declaration //////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////// struct QuadVertexOutput { QUAD_REAL4 Position : POSITION; QUAD_REAL2 UV : TEXCOORD0; }; ///////////////////////////////////////////////////////////////////////////////////// // Hidden tweakables declared by this .fxh file ///////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////// #ifndef NO_TEXEL_OFFSET #ifdef TWEAKABLE_TEXEL_OFFSET QUAD_REAL QuadTexOffset = 0.5; #else /* !TWEAKABLE_TEXEL_OFFSET */ QUAD_REAL QuadTexOffset < string UIWidget="None"; > = 0.5; #endif /* !TWEAKABLE_TEXEL_OFFSET */ QUAD_REAL2 QuadScreenSize : VIEWPORTPIXELSIZE < string UIWidget="None"; >; #endif /* NO_TEXEL_OFFSET */ //////////////////////////////////////////////////////////// ////////////////////////////////// vertex shaders ////////// //////////////////////////////////////////////////////////// QuadVertexOutput ScreenQuadVS( QUAD_REAL3 Position : POSITION, QUAD_REAL3 TexCoord : TEXCOORD0 ) { QuadVertexOutput OUT; OUT.Position = QUAD_REAL4(Position, 1); #ifdef NO_TEXEL_OFFSET OUT.UV = TexCoord.xy; #else /* NO_TEXEL_OFFSET */ QUAD_REAL2 off = QUAD_REAL2(QuadTexOffset/(QuadScreenSize.x),QuadTexOffset/(QuadScreenSize.y)); OUT.UV = QUAD_REAL2(TexCoord.xy+off); #endif /* NO_TEXEL_OFFSET */ return OUT; } ////////////////////////////////////////////////////// ////////////////////////////////// pixel shaders ///// ////////////////////////////////////////////////////// // add glow on top of model QUAD_REAL4 TexQuadPS(QuadVertexOutput IN,uniform sampler2D InputSampler) : COLOR { QUAD_REAL4 texCol = tex2D(InputSampler, IN.UV); return texCol; } QUAD_REAL4 TexQuadBiasPS(QuadVertexOutput IN,uniform sampler2D InputSampler,QUAD_REAL TBias) : COLOR { QUAD_REAL4 texCol = tex2Dbias(InputSampler, QUAD_REAL4(IN.UV,0,TBias)); return texCol; } ////////////////////////////////////////////////////////////////// /// Macros to define passes within Techniques //////////////////// ////////////////////////////////////////////////////////////////// // older HLSL syntax #define TEX_TECH(TechName,SamplerName) technique TechName { \ pass TexturePass { \ VertexShader = compile vs_2_0 ScreenQuadVS(); \ AlphaBlendEnable = false; ZEnable = false; \ PixelShader = compile ps_2_a TexQuadPS(SamplerName); } } #define TEX_BLEND_TECH(TechName,SamplerName) technique TechName { \ pass TexturePass { \ VertexShader = compile vs_2_0 ScreenQuadVS(); \ ZEnable = false; AlphaBlendEnable = true; \ SrcBlend = SrcAlpha; DestBlend = InvSrcAlpha; \ PixelShader = compile ps_2_a TexQuadPS(SamplerName); } } // newer HLSL syntax #define TEX_TECH2(TechName,SamplerName,TargName) technique TechName { \ pass TexturePass < \ string ScriptFunction = "RenderColorTarget0=" (TargName) ";" \ "DrawInternal=Buffer;"; \ > { \ VertexShader = compile vs_2_0 ScreenQuadVS(); \ AlphaBlendEnable = false; ZEnable = false; \ PixelShader = compile ps_2_a TexQuadPS(SamplerName); } } #define TEX_BLEND_TECH2(TechName,SamplerName) technique TechName { \ pass TexturePass < \ string ScriptFunction = "RenderColorTarget0=" (TargName) ";" \ "DrawInternal=Buffer;"; \ > { \ VertexShader = compile vs_2_0 ScreenQuadVS(); \ ZEnable = false; AlphaBlendEnable = true; \ SrcBlend = SrcAlpha; DestBlend = InvSrcAlpha; \ PixelShader = compile ps_2_a TexQuadPS(SamplerName); } } #endif /* _QUAD_FXH */ ////////////// eof ///
I know the general principle of working with Post Processing shaders now, thanks to a simple tutorial I read. I can now implement Post_Bloom, Post_Negative and Post Sepia just fine, but Post_Halo is kicking my butt.
I've tried pretty much every combination I can think of but to no avail so if someone could give me an idea of what I need to be doing in my app, that would be very helpful.
At the moment, I'm rendering the current view to GlowMap1, then drawing back to the screen with Passes 1 and 2, but I've tried drawing to GlowMap2 with Pass 1 and then drawing back to the screen with Pass 2 and various other combinations. There's something here I'm not getting. Something which is different between how this shader works and how the others I already have working work.
Any ideas?