/*============================================================================= PostProcess.cg: Scene post processing pixel shaders. Copyright ?2003-2005 Epic Games, Inc. All Rights Reserved. =============================================================================*/ #include "Common.cg" static const float3 LUMINANCE_VECTOR = float3(0.0532f, 0.1788f, 0.018f); //float3(0.2125f, 0.7154f, 0.0721f) * 0.25f; #ifdef NUM_SAMPLES sampler BlurTexture; //+xuricai //float4 SampleWeights[NUM_SAMPLES]; //float4 SampleOffsets[(NUM_SAMPLES + 1) / 2]; float4 SampleInformation[NUM_SAMPLES]; //-xuricai struct blurInterpolants { float4 OffsetUVs[(NUM_SAMPLES + 1) / 2] : TEXCOORD0; }; #ifdef FAST_BLUR_FOR_BLOOM //+MT float4 blur(float4 InPosition : POSITION, float2 UV : TEXCOORD0 ) : COLOR0 { float4 Sum = 0; float4 tmp1, tmp2, tmp3, tmp4; asm { tfetch2D Sum, UV, BlurTexture }; asm { tfetch2D tmp1, UV, BlurTexture, OffsetX = -0.5f, OffsetY = 0.5f }; asm { tfetch2D tmp2, UV, BlurTexture, OffsetX = -0.5f, OffsetY = -0.5f }; asm { tfetch2D tmp3, UV, BlurTexture, OffsetX = 0.5f, OffsetY = 0.5f }; asm { tfetch2D tmp4, UV, BlurTexture, OffsetX = 0.5f, OffsetY = -0.5f }; Sum += tmp1; Sum += tmp2; Sum += tmp3; Sum += tmp4; Sum /= 5.0f; return Sum; } void blurvertexshader(float4 InPosition : POSITION,float2 UV : TEXCOORD0,out float4 OutPosition : POSITION,out float2 OutUV : TEXCOORD0 ) { OutPosition = InPosition; OutUV = UV; } //-MT #else //+xuricai //half4 blur(float4 InPosition : POSITION, blurInterpolants Interpolants) : COLOR0 //{ // int SampleIndex; // half4 Sum = 0; // for(SampleIndex = 0;SampleIndex < NUM_SAMPLES - 1;SampleIndex += 2) // { // Sum += tex2D(BlurTexture,Interpolants.OffsetUVs[SampleIndex / 2].xy) * SampleWeights[SampleIndex + 0]; // Sum += tex2D(BlurTexture,Interpolants.OffsetUVs[SampleIndex / 2].wz) * SampleWeights[SampleIndex + 1]; // } // if(SampleIndex < NUM_SAMPLES) // Sum += tex2D(BlurTexture,Interpolants.OffsetUVs[SampleIndex / 2].xy) * SampleWeights[SampleIndex + 0]; // return Sum; //} half4 blur(float4 InPosition : POSITION, float2 TexUV : TEXCOORD0) : COLOR0 { int SampleIndex; half4 Sum = 0; for(SampleIndex = 0;SampleIndex < NUM_SAMPLES;SampleIndex++) { Sum += tex2D(BlurTexture,TexUV+SampleInformation[SampleIndex].xy ) * SampleInformation[SampleIndex].zzzz; } return Sum; } //void blurvertexshader(float4 InPosition : POSITION,float2 UV : TEXCOORD0,out float4 OutPosition : POSITION,out blurInterpolants Interpolants) //{ // for(int OffsetIndex = 0;OffsetIndex < (NUM_SAMPLES + 1) / 2;OffsetIndex++) // { // Interpolants.OffsetUVs[OffsetIndex] = UV.xyyx + SampleOffsets[OffsetIndex]; // } // OutPosition = InPosition; //} void blurvertexshader(float4 InPosition : POSITION,float2 UV : TEXCOORD0,out float4 OutPosition : POSITION,out float2 OutUV : TEXCOORD0 ) { OutPosition = InPosition; OutUV = UV; } //-xuricai #endif #endif sampler LinearImage : register(s0); sampler DepthTexture : register(s1); float4 LinearImageResolution; float4 LinearImageScaleBias; float4 ScaleFactor; #if SUPPORTS_FP_FILTERING half4 bilinearFilterTexture(sampler TexInput,float2 UV, float2 scale, float2 bias) { return tex2D(TexInput, UV * scale + bias); } #else float4 bilinearFilterTexture(sampler TexInput,float2 UV, float2 scale, float2 bias) { UV = UV*scale + bias; float2 IntUV = floor(UV * LinearImageResolution.xy - 0.5); float2 FracUV = frac(UV * LinearImageResolution.xy - 0.5); return lerp( lerp( tex2D(TexInput,(IntUV + float2(0.5,0.5)) * LinearImageResolution.wz), tex2D(TexInput,(IntUV + float2(1.5,0.5)) * LinearImageResolution.wz), FracUV.x ), lerp( tex2D(TexInput,(IntUV + float2(0.5,1.5)) * LinearImageResolution.wz), tex2D(TexInput,(IntUV + float2(1.5,1.5)) * LinearImageResolution.wz), FracUV.x ), FracUV.y ); } #endif float4 accumulateimage(float4 InPosition : POSITION, float3 UV : TEXCOORD0) : COLOR0 { half4 light = tex2D(PreviousLightingTexture,UV+float2(0.5/FRAME_BUFFER_WIDTH, 0.5/FRAME_BUFFER_HEIGHT)); float4 color = light * (1.0f - ScaleFactor) + bilinearFilterTexture(LinearImage,UV,LinearImageScaleBias.xy,LinearImageScaleBias.wz) * ScaleFactor ; //color.rgb = pow(color.rgb, 1.f / 1.25); return color; } half4 blendImage(float4 InPosition : POSITION,float3 UV : TEXCOORD0) : COLOR0 { return float4( tex2D(PreviousLightingTexture,UV).rgb * tex2D(LinearImage,UV).a + tex2D(LinearImage,UV).rgb, tex2D(PreviousLightingTexture,UV).a ); } sampler ExposureTexture; half MaxDeltaExposure; half ManualExposure; half4 calcExposure(float4 InPosition : POSITION,float3 UV : TEXCOORD0) : COLOR0 { half Luminosity = dot(tex2D(LinearImage,0).rgb,float3(0.3,0.59,0.11)), TargetExposure = sqrt(0.25 / clamp(Luminosity,0.1,50.0)), LastExposure = sqrt(tex2D(ExposureTexture,0).r); //+xyweng - Avoid some abnormal value LastExposure = clamp(LastExposure, 0.0707, 1.5811); //-xyweng return square(LastExposure + clamp(TargetExposure - LastExposure,-MaxDeltaExposure,MaxDeltaExposure)) * ManualExposure; } //+WbXie //Sobel filter. sampler SilhouetteTexture; half4 RegionOffsets[4]; half4 EdgeDetect( float4 Position : POSITION, float3 UV : TEXCOORD0 ) : COLOR0 { half4 Color; float2 texCoords; int texSamples[8]; half4 vertGradient; half4 horzGradient; float4 SilhouetteColor = tex2D(SilhouetteTexture, UV.xy); #if XBOX if(dot(SilhouetteColor,SilhouetteColor) < 0.000001f) return tex2D(PreviousLightingTexture, UV.xy); #endif float4 EdgeDetectResult; for(int i = 0; i < 4;i++) { texCoords = UV.xy + RegionOffsets[i].xy; Color = tex2D( SilhouetteTexture, texCoords); texSamples[i*2] = dot(Color,Color) > 0.0f ? 1 : 0; texCoords = UV.xy + RegionOffsets[i].zw; Color = tex2D( SilhouetteTexture, texCoords); texSamples[i*2+1] = dot(Color,Color) > 0.0f ? 1 : 0; } if(dot(SilhouetteColor,SilhouetteColor) && ((texSamples[0] != texSamples[7]) || (texSamples[1] != texSamples[6]) || (texSamples[2] != texSamples[5]) || (texSamples[4] != texSamples[3]))) EdgeDetectResult = SilhouetteColor; else EdgeDetectResult = half4(0.0f,0.0f,0.0f,1.0f); return EdgeDetectResult + tex2D(PreviousLightingTexture, UV.xy); } //-WbXie half4 OverlayColor; half InverseGamma; float4 finishimage( float4 Position : POSITION, float3 UV : TEXCOORD0 ) : COLOR0 { float4 Colork = tex2D(LinearImage,UV.xy+float2(0.5/FRAME_BUFFER_WIDTH, 0.5/FRAME_BUFFER_HEIGHT)); //Exposure = tex2D(ExposureTexture,0).r; //Exposure = 0.8; return Colork ; //+xyweng // if (InverseGamma == 0) // return (0,0,0,0); // else // return pow(lerp(saturate(Color*ScaleFactor*Exposure),OverlayColor,OverlayColor.a), InverseGamma); // return lerp(saturate(Color*ScaleFactor* Exposure),OverlayColor,OverlayColor.a); //-xyweng } sampler CopyTexture; float4 FillValue, FillAlpha; half4 copy( float4 Position : POSITION, float3 UV : TEXCOORD0 ) : COLOR0 { return tex2D(CopyTexture,UV.xy); } half4 copyfill( float4 Position : POSITION, float3 UV : TEXCOORD0 ) : COLOR0 { return FillAlpha > 0.5 ? FillValue : tex2D(CopyTexture,UV.xy); } float4 fill( float4 Position : POSITION, float3 UV : TEXCOORD0 ) : COLOR0 { return FillValue; } //+WbXie //pixelshader to improve constrast in fog of war. sampler TextureConst; sampler ContrastTexture; float4 contrastshader( float4 Position : POSITION, float3 UV : TEXCOORD0 ) : COLOR0 { float4 Result = tex2D(TextureConst, UV.xy); /*Result.r = tex2D(ContrastTexture, float2(Result.r,0)).r; Result.g = tex2D(ContrastTexture, float2(Result.g,0)).r; Result.b = tex2D(ContrastTexture, float2(Result.b,0)).r;*/ return Result; } float BlurStart; float BlurWidth; float SampleNumber; float Intensitity; const float2 Center = float2(0.5f,0.5f); float4 pixelshader( float4 Position : POSITION, float3 UV : TEXCOORD0 ) : COLOR0 { float4 Result = float4(0.0f,0.0f,0.0f,0.0f); for(int i=0; i<8; i++) { float scale = BlurStart + BlurWidth*(i/8.0f); Result += tex2D(TextureConst, UV.xy*scale + 0.5f); } return Result/9.0f*(Intensitity); } //-WbXie struct vertexShaderOutput { float4 Position : POSITION; float3 TexCoord : TEXCOORD0; }; vertexShaderOutput vertexshader(float4 Position : POSITION,float3 TexCoord : TEXCOORD0) { vertexShaderOutput Result; Result.Position = Position; Result.TexCoord = TexCoord; return Result; } // +zhou qi #if 1 float4 pixelshader_haloglow(float2 ScreenUV : TEXCOORD0) : COLOR0 { float4 sunligtVector = float4( -7.0f / FRAME_BUFFER_WIDTH, 18.5f / FRAME_BUFFER_HEIGHT, 900.0f / FRAME_BUFFER_WIDTH, 0.0f / FRAME_BUFFER_HEIGHT ); // x, y // get the vector float2 TexCoord = ScreenUV; float Depth = tex2D( DepthBufferTexture, TexCoord ).r; TexCoord += sunligtVector.xy; float DepthNext = tex2D( DepthBufferTexture, TexCoord ).r; float Color = ( Depth>0.98f && DepthNext<0.98f ) ? 1.0f : 0.0f; return float4( Color, Color, Color, 1.0f); } sampler HaloGlowTexture; float HaloScale; float4 HaloBuild_PS(float2 ScreenUV : TEXCOORD0) : COLOR0 { // sampler core float4 sunligtVector = float4( 1.0f/427.0f, 1.0f/242.0f, 840.0f / FRAME_BUFFER_WIDTH, 370.0f / FRAME_BUFFER_HEIGHT ); // y = ax+b float4 colorA = float4( 0.9f, 1.3f, 11.0f, 1.0f ); float4 colorB = float4( 0.0f, -0.3f, -10.0f, 0.0f ); float len = length(ScreenUV - sunligtVector.zw) * 4; float4 Color = tex2D(HaloGlowTexture, ScreenUV) / len; Color *= colorA; Color += colorB; Color = clamp(Color, 0.0f, 10.0f) * HaloScale; Color += tex2D( PreviousLightingTexture, ScreenUV ); return float4(Color.rgb, 1.0f); } #endif // -zhou qi sampler TransTexture; float InvTranslucencyColorScale = 1.0f; void singlemerge( float4 Position : POSITION, float2 UV : TEXCOORD0, //out float DepthValue: DEPTH0, out float4 ColorValue:COLOR0 ) { ColorValue = tex2D(TransTexture, UV.xy); #if USE_LOG_EXP float4 LightingColor = tex2D(PreviousLightingTexture, UV.xy); LightingColor.rgb = exp(LightingColor.rgb * EXP_SCALE_SHIFT); ColorValue.rgb = ColorValue.rgb * InvTranslucencyColorScale + LightingColor.rgb * ColorValue.a; ColorValue.rgb = log(saturate(ColorValue.rgb) + LOG_BIAS) * LOG_SCALE_SHIFT; #endif } sampler QuarterTexture; sampler FullResTexture; sampler QuarterDepthTexture; sampler QuarterTextureNearest; float4 transmerge( float4 Position : POSITION, float2 UV : TEXCOORD0, float2 ScrPos : WPOS) : COLOR0 { const float3 depthFactor = float3( 255 * 65536.0/16777215.0, 255 * 256.0/16777215.0, 255.0/16777215.0 ); half4 FullResColor = h4tex2D(FullResTexture, UV); float QuarterSpaceW = dot(depthFactor, h4tex2D(QuarterDepthTexture, UV).rgb); float FullSpaceW = dot(depthFactor, h4tex2D(DepthTexture, UV).rgb); const float2 Offset = float2(1.5f / FRAME_BUFFER_WIDTH, 1.5f / FRAME_BUFFER_HEIGHT); half2 Div4_align = frac(ScrPos * 0.5f); half2 expansion = float2(Div4_align.x > 0.45 ? Offset.x : -Offset.x, Div4_align.y > 0.45 ? -Offset.y : Offset.y); float QuarterSpaceW_Nearby = dot(depthFactor, h4tex2D(QuarterDepthTexture, UV + half2(expansion.x, 0)).rgb) / 2; QuarterSpaceW_Nearby += dot(depthFactor, h4tex2D(QuarterDepthTexture, UV + half2(0, expansion.y)).rgb) / 2; half2 dudv = 0; [flatten] if (abs(QuarterSpaceW - FullSpaceW) > 0.01) // check if there is an egde, if so, shift the sample point away from the quarter buffer texel center. dudv = expansion; else if (abs(QuarterSpaceW - QuarterSpaceW_Nearby) > 0.001) dudv = -0.33333f * expansion; //equals to nearest filter half4 QuarterColor = h4tex2D(QuarterTexture, UV + dudv); half4 ColorValue = 0; #if USE_LOG_EXP half3 LightingColor = h4tex2D(PreviousLightingTexture, UV); LightingColor = exp(LightingColor * EXP_SCALE_SHIFT); LightingColor = saturate(FullResColor.rgb * InvTranslucencyColorScale + LightingColor * FullResColor.a); LightingColor = saturate(QuarterColor.rgb + LightingColor * QuarterColor.a); ColorValue.rgb = log(LightingColor + LOG_BIAS) * LOG_SCALE_SHIFT; #else ColorValue = half4(lerp(FullResColor.rgb, QuarterColor.rgb, QuarterColor.a), FullResColor.a + QuarterColor.a); #endif return ColorValue; } //+xuricai float Time; float2 Panner(float2 InUV,float2 Speed,float Tiling,float Time1) { float2 OutUV = Speed.xy*Time1; OutUV = OutUV-floor(OutUV)+Tiling*InUV.xy; return OutUV; } float ScreenNoisyIntensity; sampler WhiteNoisyTexture; sampler ScanlieNoisyTexture; float3 MagmaNoisy(float2 UV) { float2 NoisyUV = Panner(UV,float2(10.0f,1.0f),3.0f,Time); float2 PannerUV1 = Panner(UV,float2(0.2f,0.6f),3.0f,Time); float2 PannerUV2 = Panner(UV,float2(0,2),0.2,sin(Time)); float GradientFactor = tex2D(ScanlieNoisyTexture,PannerUV1).r; GradientFactor = clamp(GradientFactor+0.00001f,0.0f, 0.8f); float4 ScreenNoisyColor = (tex2D(WhiteNoisyTexture,NoisyUV))*2.0f; //ScreenNoisyColor.rgb = lerp(float3(0.3f,0.9f,0.1f),ScreenNoisyColor.rgb,GradientFactor); return float3(lerp(1.0f,ScreenNoisyColor.rgb,ScreenNoisyIntensity)); } sampler MosaicTexture; float2 DistortedUV(float2 UV) { float2 UV1 = 100.0f*float2(1.3f,1.0f)*UV; float2 PannerUV = Panner(float2(1.5f,1.0f)*UV,float2(10.0f,10.0f),1.0f,Time); UV1 = tex2D(MosaicTexture, UV1).rr*PannerUV; float2 UV2 = Panner(UV*float2(0.12f,0.8f),float2(1.0f,10.0f),1.0f,Time); float4 Color = tex2D(MosaicTexture, UV2); Color.r = lerp(tex2D(MosaicTexture, UV1).r,Color.r,Color.a); return float2(20.0f,5.0f).xy*Color.rr; } float Magma_Tranparency; float MagmaDistoredIntensity; float SceneDistoredIntensity; float4 MagmaEffect_PS(float4 UV : TEXCOORD0) : COLOR0 { float4 OutputColor; float2 DisTexUV = float2(0.0f,0.0f); if(MagmaDistoredIntensity > 0.0f || SceneDistoredIntensity > 0.0f) DisTexUV = DistortedUV(UV); float2 MagmaUV = UV.zw + DisTexUV * MagmaDistoredIntensity; float2 SceneUV = UV.zw + DisTexUV * SceneDistoredIntensity; float4 LightColor = tex2D(PreviousLightingTexture,SceneUV); float4 MagmaColor = MagmaTexture(MagmaUV); //MagmaColor.a = 1.0f-(1.0f-MagmaColor.a)*Magma_Tranparency; MagmaColor.a = MagmaColor.a * Magma_Tranparency; OutputColor = float4(LightColor.rgb*(1.0f- MagmaColor.a) + MagmaColor.rgb*Magma_Tranparency, 1.0f); //if(MagmaColor.a > 0.0f) if(ScreenNoisyIntensity > 0.0f) { float3 NoisyColor = MagmaNoisy(MagmaUV); OutputColor.rgb = OutputColor.rgb * NoisyColor.rgb; } return OutputColor; } struct vertexOutput { float4 Position : POSITION; float4 TexCoord : TEXCOORD0; }; vertexOutput MagmaEffect_VS(float4 Position : POSITION,float2 TexCoord : TEXCOORD0) { vertexOutput Result; Result.Position = Position; Result.TexCoord = float4(Position.xy,TexCoord.xy); return Result; } //-xuricai // ******************************************************************************* // *** MSAA // ******************************************************************************* #define MSAA_NUM_SAMPLES_DOWNSCALE 9 #define MAX_SAMPLES MSAA_NUM_SAMPLES_DOWNSCALE const float3 samplesFilter[MSAA_NUM_SAMPLES_DOWNSCALE] : register(c0); // ******************************************************************************* // *** float4 DownSample2x_sampled(sampler TexSampler, float2 vUV) { const float recDoubleWidth = 1.0f / (FRAME_BUFFER_WIDTH * 2); float2 uv = vUV; uv.x = uv.x * FRAME_BUFFER_WIDTH; uv.x = floor(uv.x + 0.75f) * 2.0f - 1.0f; uv.x = (uv.x + 0.5f) * recDoubleWidth; float4 sample = float4( 0.0f, 0.0f, 0.0f, 0.0f); const float minSample = 0; const float maxSample = MAX_SAMPLES; for (int i = minSample; i < maxSample ; ++i) { sample += (tex2D(TexSampler, uv + samplesFilter[i].xy)) * samplesFilter[i].z; } return sample; } #define MSAA_ONLY_RESOLVE_COLOR 0 #if MSAA_ONLY_RESOLVE_COLOR // ******************************************************************************* float4 MsaaDownScale2x_PS( float4 Position : POSITION, float3 _UV : TEXCOORD0 ) : COLOR0 { const float2 du = float2(0.0001, 0.0); // *** quincunx return f4tex2D(LinearImage, _UV + du); } #else // if MSAA_ONLY_RESOLVE_COLOR // ******************************************************************************* // ******************************************************************************* struct PS_OUTPUT { float4 Color : COLOR0; float Z : DEPTH; }; PS_OUTPUT MsaaDownScale2x_PS( float4 Position : POSITION, float3 UV : TEXCOORD0 ) { PS_OUTPUT output; // *** downsample COLOR ************************************ const float fFrameBuffer_Width = FRAME_BUFFER_WIDTH * 2; const float fFrameBuffer_Height = FRAME_BUFFER_HEIGHT; //const float2 du = float2(0.0001, 0.0); // *** quincunx const float2 du = float2(0.5f/fFrameBuffer_Width, 0.5f/fFrameBuffer_Height); output.Color = f4tex2D(LinearImage, UV.xy + du); //output.Color = DownSample2x_sampled(LinearImage, UV.xy + du); // *** downsample DEPTH : NEAREST filtering needed for depth sampler!!! ****************** const float3 depthFactor = float3( 65536.0/16777215.0, 256.0/16777215.0, 1.0/16777215.0 ); float3 depthColor = tex2D(DepthTexture, UV.xy + du).rgb; output.Z = dot( round( depthColor * 255.0 ), depthFactor ); return output; } // ******************************************************************************* #endif // MSAA_ONLY_RESOLVE_COLOR PS_OUTPUT downscale2x2depth(float4 Position : POSITION, float3 UV : TEXCOORD0) { PS_OUTPUT output; output.Color = float4(0, 0, 0, 1); const float3 depthFactor = float3( 65536.0/16777215.0, 256.0/16777215.0, 1.0/16777215.0 ); const float2 du = float2(0.5f/(FRAME_BUFFER_WIDTH * 2), 0.5f/FRAME_BUFFER_HEIGHT); const float2 offset = float2(0.5f/FRAME_BUFFER_WIDTH, 0.5f/FRAME_BUFFER_HEIGHT); float3 depthColor; depthColor = tex2D(DepthTexture, du + UV - float2(0.f/FRAME_BUFFER_WIDTH, 0.f/FRAME_BUFFER_HEIGHT)).rgb; output.Z = dot( round(depthColor * 255.0) , depthFactor ); depthColor = tex2D(DepthTexture, du + UV - float2(1.f/FRAME_BUFFER_WIDTH, 0.f/FRAME_BUFFER_HEIGHT)).rgb; output.Z = max(output.Z, dot( round(depthColor * 255.0) , depthFactor )); depthColor = tex2D(DepthTexture, du + UV - float2(1.f/FRAME_BUFFER_WIDTH, 1.f/FRAME_BUFFER_HEIGHT)).rgb; output.Z = max(output.Z, dot( round(depthColor * 255.0) , depthFactor )); depthColor = tex2D(DepthTexture, du + UV - float2(0.f/FRAME_BUFFER_WIDTH, 1.f/FRAME_BUFFER_HEIGHT)).rgb; output.Z = max(output.Z, dot( round(depthColor * 255.0) , depthFactor )); return output; } // ******************************************************************************* // ******************************************************************************* #define RADIAL_SAMPLES_NUM 4 sampler RadialTexture; sampler BloomTexture; float BloomScale; float2 RadialParameter; //(x:BlurWidth,y:Intensitity,z:SampleNumber) float2 RadialTexelSizeAndBlurCenter;//(xy BlurCenter) void radialvs(float4 Position : POSITION,float3 TexCoord : TEXCOORD0, out float4 oPosition: POSITION , out float2 oTexCoord:TEXCOORD0, out float2 oDeltaTexCoord: TEXCOORD1) { float factor = 0.25f; //*** 1.0f / RADIAL_SAMPLES_NUM; oPosition = Position; oTexCoord.xy = TexCoord.xy; oDeltaTexCoord = TexCoord.xy - RadialTexelSizeAndBlurCenter.xy; oDeltaTexCoord *= factor * RadialParameter.x; } float4 radialps(float2 UV : TEXCOORD0 , float2 deltaTexCoord : TEXCOORD1 ) : COLOR0 { float factor = 0.25f; //*** 1.0f / RADIAL_SAMPLES_NUM; //*** Calcluate delta texCoord //float2 deltaTexCoord = UV.xy - RadialTexelSizeAndBlurCenter.xy; //deltaTexCoord *= factor * RadialParameter.x; float4 color = float4(0.0f,0.0f,0.0f,0.0f); float4 bloomColor = tex2D(BloomTexture,UV.xy); //*** Blur for(int i =0; i < RADIAL_SAMPLES_NUM; i++) { float4 sample = tex2D(RadialTexture,UV.xy); color += sample; UV += deltaTexCoord; } float Intensity = dot(color.rgb,LUMINANCE_VECTOR); //*** Multiply radial blur intensity, and add bloom return color * RadialParameter.y * factor + bloomColor * BloomScale * (1.01f-saturate(Intensity)*0.98f);; } // ******************************************************************************* // ******************************************************************************* // ******************************************************************************* sampler SharpenOriTexture; sampler SharpenBlurTexture; float ImageSharpenCoffe; float4 imagesharpen(float2 UV : TEXCOORD0 ) : COLOR0 { float4 OriColor = tex2D(SharpenOriTexture,UV); float4 BlurColor = tex2D(SharpenBlurTexture,UV); //float4 finalColor = lerp(OriColor, BlurColor, 2.0f); float4 finalColor = BlurColor + (OriColor - BlurColor) * ImageSharpenCoffe; return finalColor; } // ******************************************************************************* // ******************************************************************************* // ******************************************************************************* struct simpleVertexShaderOutput { float4 Position : POSITION; float2 TexCoord : TEXCOORD0; }; float InvIndirectColorScale = 1.0f; float InvOpacityColorScale = 1.0f; sampler IndirectLightingTexture; //*** use indirect color for some map that do not has fog effect PS_OUTPUT nofoguseindirectcolor(simpleVertexShaderOutput Input) { PS_OUTPUT output; half4 ResultColor; half4 PrevColor = tex2D(PreviousLightingTexture, Input.TexCoord); float3 DepthColor = round(tex2D(DepthBufferTexture, Input.TexCoord + float2(-0.01 / FRAME_BUFFER_WIDTH, 0)) * 255.0); const float3 depthFactor = float3( 65536.0/16777215.0, 256.0/16777215.0, 1.0/16777215.0 ); output.Z = dot(DepthColor, depthFactor); //*** when remove indirect color form sunlight color, will use these code. //half4 IndirectColor = tex2D(IndirectLightingTexture,Input.TexCoord); //ResultColor.rgb = (PrevColor.rgb * InvOpacityColorScale + IndirectColor.rgb * InvIndirectColorScale); ResultColor.rgb = PrevColor.rgb * InvOpacityColorScale; ResultColor.a = PrevColor.a; #if USE_LOG_EXP ResultColor.rgb = log(saturate(ResultColor.rgb) + LOG_BIAS) * LOG_SCALE_SHIFT; #endif output.Color = ResultColor; return output; } // ******************************************************************************* // ******************************************************************************* // ******************************************************************************* float RampBrightness; float RampContrast; float RampGamma; sampler BackBufferTexture; float4 applygammaramp(simpleVertexShaderOutput Input) : COLOR0 { float4 ResultColor = tex2D(BackBufferTexture, Input.TexCoord); //ResultColor.rgb = clamp((RampContrast * pow(ResultColor.rgb,RampGamma) + RampBrightness),0.0f,1.0f); ResultColor.rgb = saturate(RampContrast * ResultColor.rgb + RampBrightness); return ResultColor; } // ******************************************************************************* // ******************************************************************************* // ******************************************************************************* simpleVertexShaderOutput simplevertexshader(float4 Position : POSITION,float2 TexCoord : TEXCOORD0) { simpleVertexShaderOutput Result; Result.Position = Position; Result.TexCoord = TexCoord; return Result; } // *******************************************************************************