Amplifying your potential.

Barycentric coordinates and Geometry shaders

Your feedback is very important to us. We are listening.
4 posts • Page 1 of 1

Barycentric coordinates and Geometry shaders

Postby arctop » Wed Jan 09, 2019 5:52 pm

Hi.

We have a wireframe shader that calculates the barycentric coordinates in the Geometry program, and out puts is into the triangle stream. Looks like this:

Code: Select all
 // inverseW is to counteract the effect of perspective-correct interpolation so that the lines
            // look the same thickness regardless of their depth in the scene.
            struct g2f
            {
                float4 viewPos : SV_POSITION;
                float inverseW : TEXCOORD0;
                float3 dist : TEXCOORD1;
                UNITY_VERTEX_OUTPUT_STEREO
            };

            [maxvertexcount(3)]
            void geom(triangle v2g i[3], inout TriangleStream<g2f> triStream)
            {
                // Calculate the vectors that define the triangle from the input points.
                float2 point0 = i[0].viewPos.xy / i[0].viewPos.w;
                float2 point1 = i[1].viewPos.xy / i[1].viewPos.w;
                float2 point2 = i[2].viewPos.xy / i[2].viewPos.w;

                // Calculate the area of the triangle.
                float2 vector0 = point2 - point1;
                float2 vector1 = point2 - point0;
                float2 vector2 = point1 - point0;
                float area = abs(vector1.x * vector2.y - vector1.y * vector2.x);

                float3 distScale[3];
                distScale[0] = float3(area / length(vector0), 0, 0);
                distScale[1] = float3(0, area / length(vector1), 0);
                distScale[2] = float3(0, 0, area / length(vector2));

                float wireScale = 800 - _WireThickness;

                // Output each original vertex with its distance to the opposing line defined
                // by the other two vertices.
                g2f o;

                [unroll]
                for (uint idx = 0; idx < 3; ++idx)
                {
                   o.viewPos = i[idx].viewPos;
                   o.inverseW = 1.0 / o.viewPos.w;
                   o.dist = distScale[idx] * o.viewPos.w * wireScale;
                   UNITY_TRANSFER_VERTEX_OUTPUT_STEREO(i[idx], o);
                   triStream.Append(o);
                }
            }


Essentially we are creating a wireframe out of the GEO and rendering that via the shader.
I understand that this isn't something that can be done with amplify, based on other threads (?) or I might be wrong?

I also found this thread :http://amplify.pt/forum/viewtopic.php?f=8&t=883&p=3840&hilit=barycentric#p3840 discussing using an expression node for the calculation, but I don't understand how I would get the proper inputs for the node (being A,B,C, And P).

I was wondering what would be the best way to achieve the desired behavior within the context of amplify?

Thank you.
arctop
 
Posts: 2
Joined: Wed Jan 09, 2019 5:39 pm

Re: Barycentric coordinates and Geometry shaders

Postby Amplify_Borba » Thu Jan 10, 2019 11:09 am

Hello, thank you for getting in touch and for your support!

Unfortunately, it's not possible to create geometry shaders in ASE at this time.

Although you may use the Custom Expression nodes to pass shader code into the graph, the code you've shared has some geometry shader data, so I don't think there'll be a way to adapt it to be used in a standard surface shader.

The user in the post you've shared seems to be specifically calculating the barycentric coordinates for the UVs, and even though I'm not sure of whether he was successful or not in the end, the calculations shared in his screenshot seemed to be pretty standard and within the scope of what the node can handle.

Please let me know if you have any further questions.
Customer Relations at Amplify Creations
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!
User avatar
Amplify_Borba
 
Posts: 1188
Joined: Mon Jul 24, 2017 9:50 am

Re: Barycentric coordinates and Geometry shaders

Postby arctop » Sun Jan 13, 2019 8:58 am

Thank you for the help.

I guess for my purposes the best course of action would be to build the surface shader as if the Geo data is available, and then manually edit it and throw in the geo function to populate the data?
arctop
 
Posts: 2
Joined: Wed Jan 09, 2019 5:39 pm

Re: Barycentric coordinates and Geometry shaders

Postby Amplify_Borba » Mon Jan 14, 2019 12:18 pm

I don't think that this can be achieved by any means at this time, the Custom Expression node shouldn't be able to handle any data or functions specific to geometry shaders, apologies if I wasn't clear enough in my last reply.
Customer Relations at Amplify Creations
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!
User avatar
Amplify_Borba
 
Posts: 1188
Joined: Mon Jul 24, 2017 9:50 am


4 posts • Page 1 of 1

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest