HLSL position
HLSL position
HLSL position
HLSL position
HLSL position
HLSL position HLSL position HLSL position HLSL position HLSL position HLSL position HLSL position HLSL position
HLSL position HLSL position
HLSL position
Go Back  Xtreme Visual Basic Talk > > > > HLSL position


Reply
 
Thread Tools Display Modes
  #1  
Old 07-15-2009, 10:44 AM
Chris Ara Chris Ara is offline
Centurion
 
Join Date: Feb 2005
Posts: 176
Default HLSL position


I'm working on using shadows with HLSL. I downloaded a working sample of shadow projection with HLSL. I studied the project learned how it worked and implemented it in my own project. The problem is when I pass my objects through the shader it only draws the shadows and it positions everything in the default position of (0,0,0). Here is an example

Code:
        nDevice.BeginScene()

        Xeffect.BeginPass(0)
        ' nDevice.Transform.View = Matrix.LookAtLH(New Vector3(0, 100 / 2, -200 / 2), New Vector3(0, 0, 0), New Vector3(0, 1, 0))
        nDevice.Transform.Projection = Matrix.PerspectiveFovLH(CSng(Math.PI / 4), Window.Width / Window.Height, 1, 10000)
        ' nDevice.Transform.View = Matrix.LookAtLH(camPos, New Vector3(0, 0, 0), New Vector3(0, 1, 0))

        nDevice.Clear(ClearFlags.Target Or ClearFlags.ZBuffer, Color.Blue, 1, 0)
        Xeffect.SetValueTranspose(Hview_proj_matrix, Matrix.Multiply(nDevice.Transform.View, nDevice.Transform.Projection))
        Xeffect.SetValue(HlightPos, New Single() {p.X, p.Y, p.Z, 1})
       Xeffect.SetValue(HshadowT, renderT)

'draws meshes
        DrawScene2()

        Xeffect.EndPass()

       Xeffect.End()

        nDevice.VertexShader = Nothing
        nDevice.PixelShader = Nothing

        nDevice.EndScene()
        nDevice.Present()
This is the second rendering of the scene. I already rendered it from the lights view to get my shadow matrix. Now I render it and pass the scene through the effects for shadowing. I tried setting the world matrix using
ndevice.transform.world = objposmatrix before drawing the mesh , but it seems the effect file overrides the world matrix I set in the device and thus no matrix is applied to the world. Here is the effects file I am using perhaps there is way I can tweak the functions so I can position my objects.

float4x4 view_proj_matrix;
float3 lightPos;
//float scale=1;
//float bias=0;


Texture baseT;


Texture shadowT;




sampler2D Base =
sampler_state
{
Texture = <baseT>;
MinFilter = Linear;
MagFilter = Linear;
};



samplerCUBE Shadow =
sampler_state
{
Texture = <shadowT>;
MinFilter = Linear;
MagFilter = Linear;


};



struct VS_OUTPUT {
float4 Pos: POSITION;
float2 texCoord: TEXCOORD0;
float3 pos: TEXCOORD1;
float dist: TEXCOORD2;
float3 normal: TEXCOORD3;
};

VS_OUTPUT VSLight(float4 pos: POSITION, float3 normal: NORMAL, float2 texCoord: TEXCOORD0){
VS_OUTPUT Out;

Out.Pos = mul(view_proj_matrix, pos);
Out.texCoord = texCoord;

Out.normal=normal;
Out.pos=pos-lightPos;
Out.dist=distance(pos,lightPos);
return Out;
}


float4 PSLight(float2 texCoord: TEXCOORD0, float3 pos: TEXCOORD1,float dist:TEXCOORD2,float3 normal:TEXCOORD3) : COLOR {


float bias=dist*0.03f;
float shadow=texCUBE(Shadow,normalize(pos))+bias;


shadow=dist<(shadow);//*scale

float4 baseColor=tex2D(Base,texCoord);

return (shadow+0.5f)*baseColor*dot(-normalize(pos),normal);

}




struct VS_OUTPUTShadow {
float4 Pos: POSITION;
float3 dist: TEXCOORD0;
};

VS_OUTPUTShadow VS_Shadow(float4 pos: POSITION){
VS_OUTPUTShadow Out;

Out.Pos = mul(view_proj_matrix, pos);
Out.dist = distance(lightPos,pos);///scale;

return Out;
}



float4 PS_Shadow(float3 dist: TEXCOORD0) : COLOR {
return float4(dist,1);
}




technique shadowProiection
{
pass p0
{
VertexShader = compile vs_2_0 VSLight();
PixelShader = compile ps_2_0 PSLight();
}

pass p1
{
VertexShader = compile vs_2_0 VS_Shadow();
PixelShader = compile ps_2_0 PS_Shadow();
}
}

The only thing I can think of would be to add a new pass but I'm not to sure I'm relativley new to FX files and HLSL. Thank you in advance for any help.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
HLSL position
HLSL position
HLSL position HLSL position
HLSL position
HLSL position
HLSL position HLSL position HLSL position HLSL position HLSL position HLSL position HLSL position
HLSL position
HLSL position
 
HLSL position
HLSL position
 
-->