Sign in to follow this  
Bobboau

simple vertex shader that isn't working like I think it should

Recommended Posts

Bobboau    122
I'm trying to make a simple vertex shader that will allow me to draw an outline around stuff with a varying width. I have made a vertex vuffer that has the averaged normals of each polygon atached to each vert, the normal represents the direction in wich the vert should be moved in model space and is unit length, for some odd reason when ever I run the shader, the outline geometry is vastly huge to what it should be, and this is driveing my nuts, I even added in a normaliseation subroteen to make sure it was normalised, I even checked everything else by useing the position insted of the normal, that worked out almost like what I wanted (exept obviusly inward pointing faces don't get scaled right, this works out to basicly be simple scaleing, wich isn't what I want). if I manualy reduce the scaler from a test value of 1.0 to 0.1 it gets a little closer to what I want, but it looks like the whole thing is being scaled (it looks streached) rather than it expanding based on surface normals. does any one see what the hell I might be doing wrong? DWORD outline_vert[] = { D3DVSD_STREAM(0), D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3 ), //D3DVSDE_POSITION, 0 D3DVSD_REG(D3DVSDE_NORMAL, D3DVSDT_FLOAT3 ), //D3DVSDE_NORMAL, 3 D3DVSD_END() }; /* // Simple vertex shader // Constants // reg c0-3 = WorldViewProj matrix // reg c4-7 = World matrix // reg c8 = constant color (0,0,0,1) // reg c9 = constant color (1,1,1,1) // reg c10 = outline width // Stream 0 // reg v0 = position ( 4x1 vector ) // reg v3 = normal ( 4x1 vector ) */ "vs.1.0 //Shader version 1.0\n" "dp3 r3.w, v3, v3//mag squared \n" "rsq r3.w, r3.w //1/mag \n" "mul r3, v3, r3.w//normalise \n" "mul r1, r3, -c10 //get the scaleing vector\n" "add r1, r1, v0 //then add it to the position\n" "m4x4 oPos, r1, c0 // transform vertices by view/projection matrix \n" "mov oD0, c9 //color \n""";

Share this post


Link to post
Share on other sites
neneboricua19    634
Make sure that when you add your normal to your vertex, both of these items are in the same space. For example, your mesh is probably specified in model space (your mesh is centered at 0,0,0) and you use the world matrix to move the mesh around in your scene.

At the end of your vertex shader, you seem to be applying only the view*proj matrix to the mesh position. Make sure you apply the full world*view*proj matrix or you may not get the results you expect.

neneboricua

Share this post


Link to post
Share on other sites
Bobboau    122
that was just a lazy coment, it's the whole thing, the coment block above it has it corectly labled.
// reg c0-3 = WorldViewProj matrix

Share this post


Link to post
Share on other sites
neneboricua19    634
The comments to your shader code state that the normal vector is a 4 element vector. If that's the case, make sure that the 4th component is 0 or else your normalization will be off.

Make sure your outline width (c10 constant) is set up so that it uses the same value along all 4 components of the register.

Share this post


Link to post
Share on other sites

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