Simple HLSL questions

Started by
2 comments, last by FoxHunter2 16 years, 1 month ago
I have some questions about HLSL. First of all, when I pass things from the program to the vertex shader, or between the VS and the PS, do I have to give them a certain "type", like NORMAL0 or POSITION0? Cant I just simply pass a float between the PS and the VS without any information about what it is? I've seen people doing it by passing that kinda stuff as texture coordinates, but is it neccesary? In GLSL for instance, I can just pass a varying variable. Another thing is, when I pass the normal to the VS from my code, I use the following D3DVERTEXELEMENT9 (for the normals) { 0, 20, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 }, The problem is that the normal appears as a float4 with w = 1.0. Is there any way I can fix so the w coordinate is 0 by default for normals? It's easy to take care of in the VS, but I just find it weird that it seems to be 1 by default.
Advertisement
Quote:Original post by zurekx
I have some questions about HLSL. First of all, when I pass things from the program to the vertex shader, or between the VS and the PS, do I have to give them a certain "type", like NORMAL0 or POSITION0? Cant I just simply pass a float between the PS and the VS without any information about what it is? I've seen people doing it by passing that kinda stuff as texture coordinates, but is it neccesary? In GLSL for instance, I can just pass a varying variable.


You can basically pass any type between the VS to the PS, like float, but they need to have a semantic so they can be distinguished by the compiler/runtime. The normal approach is to use one of the available TEXCOORDn semantics, so you can pass your float like:
float someValue : TEXCOORD0/1/2/3. NORMAL is usually reserved for normals in the VS and POSITION as input and output from the VS.

Quote:Another thing is, when I pass the normal to the VS from my code, I use the following D3DVERTEXELEMENT9 (for the normals)

The problem is that the normal appears as a float4 with w = 1.0. Is there any way I can fix so the w coordinate is 0 by default for normals? It's easy to take care of in the VS, but I just find it weird that it seems to be 1 by default.


Why do you need .w to be 0? float3 are usually expanded to a float4 because the hardware calculates with four components, thus resulting in .w being 1.
Yeah, but I want my normals to have w = 0 (so it wont be affected by translations when I multiply it). Just wondered if it could be set to 0 automatically.
well, you can do something like

output.Normal = mul((float3x3)WorldIT, Normal)

or

output.Normal = mul(WorldIT, float4(Normal, 0));

I'm not sure which one is correct here.

This topic is closed to new replies.

Advertisement