Sign in to follow this  
Deep314

DX9 HLSL Vertex shader problem

Recommended Posts

Hi all.

Why it doesnt work?

struct VS_OUTPUT
{
float4 Position : POSITION; // vertex position
float4 Diffuse : COLOR0;
float2 TextureUV : TEXCOORD0;
}


PS_OUTPUT RenderScenePS( VS_OUTPUT In, uniform bool bTexture )
{
PS_OUTPUT Output;

Output.RGBColor = float4(In.Position.x,0,0,0);

return Output;
}


But if i change Output.RGBColor = float4(In.Position.x,0,0,0); to Output.RGBColor = float4(0,0,0,0); all work great!

Where im wrong?

Share this post


Link to post
Share on other sites
Yeah. When i did make copy of Position in VertexShader it works.

Now i need render each pixel of human model in grayscale(or red,bluescale...). It use next algorithm:

exists loaded human 3d model. exist any point in field with coordinates (x1,y1,z1).


for every human point (x,y,z) do

r = sqrt((x-x1)^2+(y-y1)^2+(z-z1)^2)

r = r / 1000 <---normalize. r<1

Output.RGBColor = float4(r,0,0,0) <-----redscale

I did it. But when i load this shader program crashed.

struct VS_OUTPUT
{
float4 Position : POSITION; // vertex position
float4 Diffuse : COLOR0; // vertex diffuse color (note that COLOR0 is clamped from 0..1)
float2 TextureUV : TEXCOORD0; // vertex texture coords
float4 Position4PS : TEXCOORD1; <---Additional field
};




PS_OUTPUT RenderScenePS( VS_OUTPUT In,
uniform bool bTexture )
{
PS_OUTPUT Output;
float r,x,y,z;
x = In.Position4PS.x;
y = In.Position4PS.y;
z = In.Position4PS.z;

r = sqrt((x-10)(x-10)+(y-10)(y-10)+(z-10)(z-10));
r = r/1000;

Output.RGBColor = float4(r,0,0,0);

return Output;
}
It must be something like picture in attach(depth image)

Share this post


Link to post
Share on other sites
[font="Arial"]If you just want to render the depth of the model you simply use:

Add float2 Depth : TEXCOORDX to the vertex output

In the vertex shader do:
[/font][font="Arial"] output.Depth.x = output.Position.z;[/font] [font="Arial"] output.Depth.y = output.Position.w;

In the pixelshader (if you want to output Depth as an COLORX argument):

output.Depth = input.Depth.x / input.Depth.y;


Another tipp:

Add something along the lines of:

if(ErrorMsgs)
{
char* szErrors = (char*)ErrorMsgs->GetBufferPointer();
ErrorMsgs->Release();
}

after you create the effect:
D3DXCreateEffectFromFile(Device,...,..., ...., ...,...., &Effect, &ErrorMsgs);

to see the error message why it is "crashing"
[/font]

Share this post


Link to post
Share on other sites

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