Jump to content
  • Advertisement
Sign in to follow this  
XVincentX

HLSL - Depth of field

This topic is 4508 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Good morning, i'm Vincenzo From italy, i'm17 I'm studing DirectX9 and now i'm doing some shaders. I've done Blur but now it's time for depth of field, but i do not know how to proceed because i do not know teory of this effect. I've tried to read ATI paper about this effect but nothing, and on shaderx2 implement it via Multiple Render Targets that i do not know how to use... I've done this but i do not know how to continue //Funzioni di ausilio float4 PhongLight(float3 DirLuce, float3 Normale, float4 ColoreLuce, int SpecularPower) { DirLuce = normalize(DirLuce); DirLuce = -DirLuce; float4 Lambertian = max( dot( DirLuce, Normale ) * ColoreLuce, 0 ); float3 Reflection = normalize( ( ( 2.0f * Normale ) * dot(DirLuce,Normale) ) - DirLuce ); float3 RDotE = max( 0.0f, dot( Reflection, DirLuce ) ); float4 Phong = pow(ColoreLuce * float4(RDotE,0),SpecularPower); return Lambertian + Phong; } float4x4 matTotale : matWorldViewProjection; float4x4 matWorld : matWorld; float PuntoFuoco; //******************************************************* // Mesh Pass //******************************************************* texture TextMesh; sampler SamplerMesh = sampler_state { texture = <TextMesh>; MAGFILTER = Linear; MIPFILTER = Linear; MINFILTER = Linear; }; struct Vs_InMesh { float4 Position : POSITION0; float3 Normal : NORMAL0; float2 TexCoord : TEXCOORD0; }; struct Vs_OutMesh { float4 Position : POSITION0; float3 Normal : TEXCOORD0; float2 TexCoord : TEXCOORD1; float3 PfToVx : TEXCOORD2; }; struct Ps_InMesh { float3 Normal : TEXCOORD0; float2 TexCoord : TEXCOORD1; float3 PfToVx : TEXCOORD2; }; Vs_OutMesh VsMesh(Vs_InMesh Input) { Vs_OutMesh Output; Output.Position = mul(Input.Position,matTotale); Output.TexCoord = Input.TexCoord; Output.PfToVx = (Output.Position - PuntoFuoco); Output.Normal = normalize(mul(Input.Normal,matWorld)); return Output; } float4 PsMesh(Ps_InMesh Input) : COLOR0 { float4 TexLuce = (tex2D(SamplerMesh,Input.TexCoord) * PhongLight(float3(1,1,1),Input.Normal,float4(1,1,1,0),2)); TexLuce.w = length(Input.PfToVx); } //******************************************************** // Pass per il blur //******************************************************** struct Vs_InBlur { float4 Position : POSITON0; float3 Normal : NORMAL0; float2 TexCoord : TEXCOORD0; }; struct Vs_OutBlur { float4 Position : TEXCOORD0; float3 Normal : TEXCOORD1; float2 TexCoord : TEXCOORD2; }; Vs_OutBlur VsBlur(Vs_InBlur Input) { Input.Position = mul(Input.Position,matTotale); return (Vs_OutBlur)Input; }; //******************************************************** // Tecniche e pass //******************************************************** technique DepthOfField { pass Mesh { VertexShader = compile vs_2_0 VsMesh(); PixelShader = compile ps_2_0 PsMesh(); } pass Blur { VertexShader = compile vs_2_0 VsBlur(); PixelShader = compile ps_2_0 PsBlur(); } }

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!