# Vertex Shaders and Matrix Transformations

## Recommended Posts

I'm using Cg as my shader API, and when I run any vertex shader, everything disappears! I am using Cg in DX, but I think this is more of a general question. In all the shader examples I have seen, the verts are altered using the current projection matrix, but in my current project, I still want to do that in the FFP, so no matrix transofmration takes place in the shader. Could this be what is messing up the drawing? The current shader I am using is very simple, and should work!
struct Vert
{
float4 pos  : POSITION;
float4 dif  : COLOR0;
float4 tex  : TEXCOORD0;
};

Vert main(Vert In)
{
return In;
}

I have checked that my current vertices are compatable with the shader, and that everythign is rendering inetrnally, just nothing is appearing on screen! Any help would be appreciated Thanks Daisy

##### Share on other sites
deavik    570
I don't know about Cg but in GLSL when I am using a vertex shader *without* a fragment shader I have to set the fragment (pixel) color in the vertex shader so that the fragment shader can read the color value from it. If I don't do this, fragment values are set as black, and chances are that your clear color is black as well, so that might be what's "hiding" your scene.

##### Share on other sites
dave    2187
Why do you want to do the transformation in FFP?

##### Share on other sites
TomBlind    144
When using a shader, you are essentially replacing the fixed-function pipeline. You have to project the vertex position yourself.

##### Share on other sites
jpetrie    13162
You can't do that. When you use a vertex shader, the (majority) of the FFP transformation phase is bypassed, including the application of the projection matrix.

The output of a vertex shader must be coordinates in clip space (the result of the application of the world, view and projection transforms). The shader you've supplied simply outputs model space coordinates. The hardware will take the output coordinates, clip them, apply the perspective division (by w) to bring them into NDC space, then apply the viewport transformation to bring them into screen space, then rasterization will occur. Since what you've outputted from your vertex shader isn't really what the card expects, the vertices are likely to be drawn somewhere unexpected, or not at all.

##### Share on other sites
smitty1276    560
What the other guys said...

Out of curiosity... Why would you not want to do any transformations in the incredibly fast hardware that is designed specifically for that sort of thing?

##### Share on other sites
Thanks for that, it explains why nothing is being displayed, yet my fragment shaders are working fine.

The reason I want to do the matrix transformations in the FFP is because I am just starting out with shaders, and my engine is currently 100% FFP. I wanted, for now, to just start playing around with shaders without changing the base code to much, and move over to programmable pipeline gradually.

Again, thanks for the info, and hopefully I can get round it without to much trouble :)

Daisy

##### Share on other sites
superpig    1825
Quote:
 Original post by PrincessDaisyThe reason I want to do the matrix transformations in the FFP is because I am just starting out with shaders, and my engine is currently 100% FFP. I wanted, for now, to just start playing around with shaders without changing the base code to much, and move over to programmable pipeline gradually.

Something I'd recommend is to keep both FFP and shader pipelines knocking around, and a hotkey for toggling between the two. That way you can quickly compare the results you're getting from each to see that your shader does what you expect.

## Create an account

Register a new account