Sign in to follow this  

HSLS

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

Is it possable to make a vertex shader that has a condition on the vertex structure being passed to it? For example could i have the one shader that renders one effect on meshes with only a position and normal component and another effect if passed position, normal and texture vertices. I ask as i have 3 vertex shaders at the moment and i dont like switching between them for different mesh's. Regards

Share this post


Link to post
Share on other sites
"HLSL"...

So you don't like to switch between techniques is that basically whats up?

Well, I don't see why in your shaders, you could have a check that sees if the Normal is 0,0,0 (however, you're going to have to have the Normal vector in your VertexDeclaration, so your not saving memory, your wasting it) and if its 0,0,0 then set the lighting factor to 1 and continue on... Not sure why you have an issue with technique switching, I'd say if someone was looking at an fx file that tried to put all techniques into 1 then I'd think that person would have no idea what was going on unless you commented the hell out of it. (Basically I can see this as being bad style)

Share this post


Link to post
Share on other sites
Using vertex declarations you can easily write shaders that accept a subset of vertex attributes. You can't do it with a superset though (the IA can't/won't invent data that doesn't exist).

You will still have to have your application choose which shader you want to execute, even if you can now avoid re-setting/re-declaring the input vertex data.

hth
Jack

Share this post


Link to post
Share on other sites
Old thread new question!

How do i break from the vertex shader WITHOUT rendering the vertex?

For example say i only want to render a point on a certain condition and i find out a point does not meet this condition so how do break out of the shader?

I tried return(0), return(NULL), return(fail) and break.

Regards

Share this post


Link to post
Share on other sites
You can't - 1 in, 1 out. Only D3D10's GS can break this rule.

You could pass in a flag for the pixel shader so that it can emit a clip/texkill instruction and not commit anything to the render target.

hth
Jack

Share this post


Link to post
Share on other sites
In that case what stage of the pipeline is the renderstate(cull,anticlockwise) used?

For example can i not make my own version of this within the vertex shader?

I dont use a pixel shader at present.

I am also curious about how the normal is used. I have a shader that uses it - turn into a colour based on whatever - but i was wondering about it not having an output type.

Does this mean as i can never output the normal that renderstate(cull,anticlockwise) happens before we get to the vertex shader stage?

edit: When i said renderstate(cull,anticlockwise) i meant Device->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW ). I looked it up in case you all thought i was chronically lazy - which I'm not (quite).

Share this post


Link to post
Share on other sites
Quote:
Original post by galapogos22
In that case what stage of the pipeline is the renderstate(cull,anticlockwise) used?


In DX9 (and most going back to around DX6) hardware there's a fixed backface culling stage which happens after the "primitive assembly" stage. Primitive assembly is where the vertices output from your vertex shader are assembled into complete triangles.

For more of an overview of how it fits with the rest of the pipeline take a look at the pipeline poster from Richard's book: http://www.xmission.com/~legalize/book/preview/poster/index.html


Quote:
For example can i not make my own version of this within the vertex shader?


Difficult because the vertex shader only sees a single vertex at a time. You'd have to do something like move the vertex outside of the viewport or (even more difficult) change its winding order relative to the other vertices in the triangle to perform the culling yourself.



Quote:
I am also curious about how the normal is used. I have a shader that uses it - turn into a colour based on whatever - but i was wondering about it not having an output type.

Does this mean as i can never output the normal that renderstate(cull,anticlockwise) happens before we get to the vertex shader stage?


Vertex normals are not used for backface culling. What is effectively a face normal is computed during backface culling (it's actually simpler than computing a full 3d normal because the vertices are already in homogeneous clip space at that point in the pipeline so only the sign of the normal's Z component matters).

Vertex normals are used by the fixed function pipeline for lighting. Vertex normals are used by the shader pipeline for whatever your shader wants. No other use occurs.

Share this post


Link to post
Share on other sites

This topic is 3665 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.

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