DX9 Shader: inverse Vignette as torch effect

Started by
0 comments, last by Robbo5000 1 year ago

I am trying to convert a post processing vignette into a torchlight effect and have the centre position brighter instead of the dark edges but unable to work out depth buffer so as to get depth adjustments.

My code is in HSLS (Dx9) and this is what I have (based off CopperCube game engine - irrLicht) :

Seems to be a problem with my calculation of ‘lightDistance’ as works basic when I remove it

const char* POSTPROCESS_SHADER_VIGNETTE_D3D =

"sampler2D tex0 : register(s0); \n"\

"float4x4 mWorld; // world matrix \n"\

"float PARAM_Vignette_Intensity; \n"\

"float PARAM_Vignette_RadiusA; \n"\

"float PARAM_Vignette_RadiusB; \n"\

"float4 pixelMain( float2 TexCoord : TEXCOORD0, float4 Position : POSITION) : COLOR0 { \n"\

" const float centerX = 0.5; \n"\

" const float centerY = 0.5; \n"\

" float4 col = tex2D( tex0, TexCoord ); \n"\

" float e1 = ( TexCoord.x - centerX ) / ( PARAM_Vignette_RadiusA ); \n"\

" float e2 = ( TexCoord.y - centerY ) / ( PARAM_Vignette_RadiusB ); \n"\

" float3 camPos = float3(0,0,0); \n"\

// just for testing fdor now - later camera position \n"\

" float3 camToLight = camPos - float3(Position.xyz); \n"\

" float objDistance = length(camToLight); \n"\

" float lightDistance = (1.0 / objDistance) * 0.25; \n"\

" float distanceFromCentre = clamp(2.0 - ((e1 * e1) + (e2 * e2)), 0.0, 1.0); \n"\

" return col * (1.0 + (PARAM_Vignette_Intensity * distanceFromCentre)) * lightDistance); \n"\

This topic is closed to new replies.

Advertisement