Jump to content
  • Advertisement
Sign in to follow this  
Deep314

DX9 HLSL Vertex shader problem

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

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
Advertisement
You cant use the position information in the pixelshader if im not mistaken. Youll have to pass it as an additional float4 texcoord slot to further process it.

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
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!