Flat Shader according to World Position (Barycentric?)

Node-based Shader Editor

Flat Shader according to World Position (Barycentric?)

Postby AiSard » Wed Mar 20, 2019 8:33 pm

Hi,

I am currently trying to do a flat shader (low poly) for procgen meshes (no UV mapping so far) where the colour changes according to the height in World Space.

So far I've referenced the Low Poly Water example to achieve the low poly effect.

But there doesn't seem to be an easy way to interact with the World on a per-Triangle basis instead of per-Vertex.

I was looking in to Barycentric Co-ordinates, but I'm unsure how to implement it in ASE. Not a good enough coder to interpret the one thread I found that touched upon it either. (If I did, would each vertex on a triangle be able to reference the center?)

Is there a simpler way or a hack for my specific usage? If not, how would I go about implementing Barycentric co-ordinates.

current flat shader 'spilling' over in to other triangles
https://imgur.com/a/nCDFypG
AiSard
 
Posts: 4
Joined: Wed Mar 20, 2019 7:53 pm

Re: Flat Shader according to World Position (Barycentric?)

Postby Amplify_Borba » Thu Mar 21, 2019 10:51 am

Hey there, thank you for getting in touch and your support!

This matter has already been addressed in this post.

In short, I don't think that this is achievable through ASE without us supporting geometry shaders ( no ETA for this ), you'll likely have to research alternative means of achieving the effect you intend.
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: 1239
Joined: Mon Jul 24, 2017 9:50 am

Re: Flat Shader according to World Position (Barycentric?)

Postby AiSard » Thu Mar 21, 2019 3:53 pm

Hmm, that is a shame :(

I shall try to bake the triangle center in to mesh.color instead (unshared vertices, identical value for all 3 corners).
Which I should be able to access via Vertex Color instead.

However, as the height is currently generated by the Noise Generator (Simplex2D) feeding in to Local Vertex Offset, I don't actually know the Z value and am struggling to emulate Amplify's Simplex2D in C#.

Is there a readable Simplex2d code example somewhere who's implementation is similar enough to Amplify's that I could then just tweak to get the same values from?
AiSard
 
Posts: 4
Joined: Wed Mar 20, 2019 7:53 pm

Re: Flat Shader according to World Position (Barycentric?)

Postby Amplify_Borba » Thu Mar 21, 2019 4:34 pm

I believe our implementation is based on this one.

You may also check out our nodes' code by opening their scripts, the SimplexNoiseNode.cs can be found within the Assets\AmplifyShaderEditor\Plugins\Editor\Nodes\ImageEffects folder, for example.
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: 1239
Joined: Mon Jul 24, 2017 9:50 am

Re: Flat Shader according to World Position (Barycentric?)

Postby AiSard » Thu Mar 21, 2019 7:46 pm

Not knowing the first thing about coding shaders, quickly dropped that avenue.

That said, found a way to access triangle centers. Posting for posterity's sake.

Calculated the center of each triangle in world space (made sure to unshare the vertices) and for each triangle corner assigning Mesh.SetUV identical float3 UVs of said triangle center.
Vertex TexCoord pretty much then replaces the need for World Position, returning the triangle center for all points inside a triangle.
AiSard
 
Posts: 4
Joined: Wed Mar 20, 2019 7:53 pm


Return to Amplify Shader Editor

Who is online

Users browsing this forum: Google [Bot] and 8 guests

cron