Xtreme Visual Basic Talk

Xtreme Visual Basic Talk (http://www.xtremevbtalk.com/)
-   Managed DirectX (http://www.xtremevbtalk.com/managed-directx/)
-   -   HLSL position (http://www.xtremevbtalk.com/managed-directx/308906-hlsl-position.html)

Chris Ara 07-15-2009 09:44 AM

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



        ' 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



        nDevice.VertexShader = Nothing
        nDevice.PixelShader = Nothing


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 =
Texture = <baseT>;
MinFilter = Linear;
MagFilter = Linear;

samplerCUBE Shadow =
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){

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

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;


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. :D

All times are GMT -6. The time now is 02:52 AM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Search Engine Optimisation provided by DragonByte SEO v2.0.15 (Lite) - vBulletin Mods & Addons Copyright © 2018 DragonByte Technologies Ltd.
All site content is protected by the Digital Millenium Act of 1998. Copyright©2001-2011 MAS Media Inc. and Extreme Visual Basic Forum. All rights reserved.
You may not copy or reproduce any portion of this site without written consent.