Sign in to follow this  

HLSL - Depth of field

This topic is 4201 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

This topic is 4201 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this