Advertisement

Geometry shader doesn't show anything

Started by March 06, 2018 01:44 PM
6 comments, last by MehdiUBP 6 years, 10 months ago

Hello,

 

I wrote a geometry shader in order to render (in the future, grass) some planes. I get a strange error that I do not understand.

It says: The given primitive topology does not match with the topology expected by the geometry shader

I do not have the magenta error color, but nothing appears in the scene. Could anyone point me my error ?

 

 

struct v2g
        {
            float4 pos: POSITION;
            // float3 norm : NORMAL;
        };

        struct g2f
        {
            float4 pos : POSITION;
            // float3 norm : NORMAL ;
        };


        v2g vert(appdata_full v)
        {
            // float3 v0 = v.vertex.xyz;
            v2g o;

            o.pos = UnityObjectToClipPos(v.vertex);
            // o.norm = v.normal;

            return o;
        }

[maxvertexcount(3)]
        void geom(point v2g v[1], inout TriangleStream <g2f> triStream)
        {
            float3 lightPosition = _WorldSpaceLightPos0;
            float3 perpAngle = float3(1,0,0);
            float3 up_normal = float3(0,1,0);
            float3 faceNormal = cross(perpAngle, up_normal);
            float4 v0 = v[0].pos;
            float4 v1 = v0;
            v1.xyz +=   _GrassWidth*perpAngle;
            float4 v2 =  v1;
            v2.xyz += (0,1,0)*_GrassHeight;


            g2f o ;
            o.pos = UnityObjectToClipPos(v0);
            triStream.Append(o);

            o.pos = UnityObjectToClipPos(v1);
            triStream.Append(o);

            o.pos = UnityObjectToClipPos(v2);
            triStream.Append(o);

 

}

 

Thanks a lot !

Edit:nevermind, read the error incorrectly.

Niko Suni

Advertisement

Maybe you are still rendering triangles? The GS expects points, so you should render points, by calling IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_POINTLIST ) on your device context.

edit: just spotted the unity tag. I'm not familiar with unity, but probably you don't have access to the direct3d device context. I guess instead you'll have to tell unity to treat your vertex buffers/geometry/mesh as points, and not triangles...

Hey,

Thanks to the both of you for your answers.

Well, I've tried taking in other geometries: If I start with a triangle, the error disappears, but still no visual triangles/quad.

Hello,

Made some changes, seems to work now. Far from perfect, but at least, something appears

Here's the link

https://github.com/Mehd6384/Shaders/blob/master/GeometryGrassShaders.shader

I think to do what I mean with point topology, you'd have to change this propery of your mesh

Advertisement

Oh ! I get it ! I'll try this very soon ! Thanks a lot !

 

EDIT: I'll let you know when I have results

This topic is closed to new replies.

Advertisement