• Advertisement
Sign in to follow this  

Clockwise test in geometry shader failing

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

Ive coded a shader that projects the vertices in the geometry shader then clockwise culls it there, but the problem is the cross product test isnt working. It does work, but if the camera moves (as aposed to rotates) then the cross product test goes out of whack for some reason and you can see the back of the triangle at some angles. Shouldnt this work? <code> Texture2D nort; Texture2D dift; SamplerState sstate { Filter=MIN_MAG_MIP_POINT;//ANISOTROPIC; AddressU = Wrap; AddressV = Wrap; }; cbuffer cb { matrix wvp; }; struct vs_input { float4 pos : POSITION; float3 nor : NORMAL; float2 uv : TEXCOORD0; }; struct gs_input { float4 pos : POSITION; float3 nor : NORMAL; float2 uv : TEXCOORD0; }; struct ps_input { float4 pos : SV_POSITION; float3 uvw : TEXCOORD0; float3 buvw : TEXCOORD1; }; gs_input vs(vs_input input) { gs_input output = (gs_input)0; output.pos=input.pos; output.nor=input.nor; output.uv =input.uv; return output; } [maxvertexcount(12)] void gs(triangle gs_input input[3], inout TriangleStream<ps_input> TriStream) { ps_input output; float4 pos[3]; pos[0]=input[0].pos; pos[1]=input[1].pos; pos[2]=input[2].pos; pos[0]=mul(pos[0],wvp); pos[1]=mul(pos[1],wvp); pos[2]=mul(pos[2],wvp); float3 crs=cross(float3(pos[1].xy-pos[0].xy,0),float3(pos[2].xy-pos[0].xy,0)); if(crs.z<0) { output.pos=pos[0]; output.uvw=float3(input[0].uv,0); output.buvw=float3(input[0].uv,0); TriStream.Append(output); output.pos=pos[1]; output.uvw=float3(input[1].uv,0); output.buvw=float3(input[1].uv,0); TriStream.Append(output); output.pos=pos[2]; output.uvw=float3(input[2].uv,0); output.buvw=float3(input[2].uv,0); TriStream.Append(output); TriStream.RestartStrip(); } } float4 ps(ps_input input) : SV_Target { return dift.Sample(sstate,float2(input.uvw.x,input.uvw.y)); } technique10 ray { pass P0 { SetVertexShader(CompileShader(vs_4_0,vs())); SetGeometryShader(CompileShader(gs_4_0,gs())); SetPixelShader(CompileShader(ps_4_0,ps())); } } </code>

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement