Sign in to follow this  

HLSL - cut vertex

This topic is 3312 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! I'm new to HLSL, and I'm trying to write shader, which will do the following: If variable > 0 (here variable has nothing to do with HLSL), all model vertexes on the right side of X axis will HIDE, else, all model vertexes on the right side of X axis will HIDE. Later, I'll make it more complex, but currently... Is there some way to hide specific vertex from being rendered? And how to determine, which are on the right side of X (or Y, Z) axis? Or something like that? Regards, Konstantin.

Share this post


Link to post
Share on other sites
Which version of Direct3D are you using? Prior to D3D 10.0 you can't modify the number of vertices/primitives via HLSL - the Geometry Shader is required to add or remove actual geometry.

That said, if you're using D3D9 you can output the threshold value to a TEXCOORD (so its interpolated correctly) and then use clip() in the pixel shader. It's not necessarily the most efficient operation but it should do what you want.

Alternatively, if you're using D3D 10.0, 10.1 or 11.0 you can move your computation to the GS unit and simply control the emit() statements. You can bypass the VS if you're using this to eliminate extra processing, but be careful as this may not speed things up.

Quote:
And how to determine, which are on the right side of X (or Y, Z) axis? Or something like that?
At a syntax level you'll often go off the sign of the input so a simple inequality will do the trick. If you want to deal with planes (D3DPLANE in your app) you can pack all the coefficients into a single HLSL register and do a dot() (with w=1) to evaluate which side a point is...

hth
Jack

Share this post


Link to post
Share on other sites
If your requirements are actually as simple as you described, I would advocate splitting your model into two models at the x-axis, and then render each one or not as required. This is pretty much guaranteed to offer better performance than a shader based solution, but of course, if you criteria are sufficiently complicated it won't work.

Share this post


Link to post
Share on other sites

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