Vertex Normal Recalculation Issues

Node-based Shader Editor

Vertex Normal Recalculation Issues

Postby andrewtaylorjohnson » Wed Mar 06, 2019 5:26 pm

Hello there! I have a question regarding recalculating vertex normals after offsetting vertices. I'm using a heightmap to displace vertices around level geo, but I'd like to then inflate the verts a bit in the direction perpendicular to their tangents after the initial displacement. There is an example in the Amplify asset of recalculating vertices for a waving flag that I've used as a starting point, but when I try to displace the verts along their new normals they don't move in the correct direction.

My current shader calculates a new vertex position using a heightmap which is then added to new normals which are being multiplied by an inflation amount => (newVertexPosition + (newNormals * inflationAmount)).

Here is my system for the initial vertex displacement:
NewVertexPosition.PNG
NewVertexPosition.PNG (211.88 KiB) Viewed 14482 times


Here's a screenshot of the initial vert displacement (the red plane mesh has the shader applied and is conforming to level geo):
InitialDisplacementExample.PNG
InitialDisplacementExample.PNG (150.42 KiB) Viewed 14482 times


Here's a screenshot of the inflated verts being translated along their new normals after the initial displacement using the method in the included flag example:
NormalRecalculationExample01.PNG
NormalRecalculationExample01.PNG (136.1 KiB) Viewed 14482 times


One solution I tried was to use the "newVertexPosition" variable to calculate the Delta-X and Delta-Y rather than the Vertex Position node, but this only scaled them vertically along the y-axis when trying to inflate.

Any help would be greatly appreciated!
Last edited by andrewtaylorjohnson on Thu Mar 07, 2019 12:45 am, edited 1 time in total.
andrewtaylorjohnson
 
Posts: 6
Joined: Wed Mar 06, 2019 5:02 pm

Re: Vertex Normal Recalculation Issues

Postby andrewtaylorjohnson » Wed Mar 06, 2019 11:14 pm

Here is where I got to by the end of my day today. I've essentially copied everything over from the "VertexNormalReconstruction" example and ported it over to my shader. The only significant difference that I can see it the function I'm using to actually displace the verts, but for some reason my normals keep coming up with zero magnitude as far as I can tell and just completely breaks the shader (division by zero error when it passes through the normalize node).

Here are some images showing my network:

Displacement.jpg
Displacement.jpg (203.54 KiB) Viewed 14478 times


HeightmapDisplacementFunction.jpg
HeightmapDisplacementFunction.jpg (100.12 KiB) Viewed 14478 times


NormalRecalculation.jpg
NormalRecalculation.jpg (178.62 KiB) Viewed 14478 times


I'm at a real loss on this one :(
andrewtaylorjohnson
 
Posts: 6
Joined: Wed Mar 06, 2019 5:02 pm

Re: Vertex Normal Recalculation Issues

Postby Amplify_Borba » Tue Mar 12, 2019 11:08 am

Hello and apologies for the delay in our reply! Could you share a simple sample of what you achieved so far and with the error present so that we can look into it?
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: Vertex Normal Recalculation Issues

Postby andrewtaylorjohnson » Tue Mar 12, 2019 2:32 pm

Amplify_Borba wrote:Hello and apologies for the delay in our reply! Could you share a simple sample of what you achieved so far and with the error present so that we can look into it?


Hey Borba! Thanks for the reply. Here's the shader and it's main displacement function, as well as a test heightmap to plug into a material if you make one from the shader:
ShadowDisplacementShader.7z
(166.51 KiB) Downloaded 1267 times


I was unable to upload a test Unity project for you to use, so if you make a material out of the shader, plug-in the heightmap I sent into its corresponding field, set the 'SampleWidth' to 51, the 'MaxHeight' to 15, and give it a color that's not totally transparent.

Here's an image of what the shader does if I bypass adding the recalculated normals to the new vertex position:
InflationReason.PNG
InflationReason.PNG (99.49 KiB) Viewed 14437 times


You can see where I've highlighted in red is the problem I'm trying to solve (along with one other that will use recalculated normals). The mesh conforms to the geo well, but it cuts through the edges of the cube, so I'd like to recalculate the normals and push the vertices out a bit in the direction of those new normals.

Here's an image of the error in engine:
ShadowDisplacementError.PNG
ShadowDisplacementError.PNG (20.58 KiB) Viewed 14437 times


Let me know if you wanted anything else I failed to provide :D

Thanks again! Any help would be very much appreciated!
andrewtaylorjohnson
 
Posts: 6
Joined: Wed Mar 06, 2019 5:02 pm

Re: Vertex Normal Recalculation Issues

Postby Amplify_Borba » Fri Mar 15, 2019 2:40 pm

Hey there, I've been unable to get your shader to work as per your screenshots even with the supplied instructions, could you please share a simple project with the scene set up as shown in your last screenshot?

Apologies for insisting but our time is very limited and its always preferable to use the exact same data as the user when debugging potential issues, thank you for understanding.
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: Vertex Normal Recalculation Issues

Postby andrewtaylorjohnson » Fri Mar 15, 2019 6:08 pm

Hey Borba! Thanks for getting back. Same as before, I'm unable to upload the project files for some reason. Is there an email I can send them too instead?

Thanks!

EDIT:

I just PM'd you with a link to the project .zip on my drive.
andrewtaylorjohnson
 
Posts: 6
Joined: Wed Mar 06, 2019 5:02 pm

Re: Vertex Normal Recalculation Issues

Postby Amplify_Borba » Wed Mar 20, 2019 9:51 am

Hey! Apologies but I haven't received anything through PM, could you please send it through [email protected]?
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: Vertex Normal Recalculation Issues

Postby Amplify_Borba » Fri Apr 05, 2019 9:17 am

Our developer tested the sample and confirmed that this is not an ASE issue.

It is a bit hard to read but one factor that is contributing to these visual artifacts seems to be the shadow's own geometry.

Image

Since the texture fetches for the vertex offset are being made on the vertex shader, for example in a border situation there are vertices that are in an area where the texture has registered a big offset but the vertices that are next to it don't.

What happens is that between the vertex and fragment stages ( rasterizer ) values are interpolated to fill the in-betweens and vertices will be connected. Since they are a bit far apart and have big offset differences, the connected geometry intersects the one below.

Please let us know if you have further questions, we'll be happy to assist!
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: Vertex Normal Recalculation Issues

Postby andrewtaylorjohnson » Fri Apr 05, 2019 3:00 pm

Thanks for checking it out! I must have asked this question in the wrong place though. I never thought this was an Amplify issue; I was just looking for some help to get my vertex normal recalculation working in this shader.

Sorry for the confusion! I'll go ask on the Unity forums instead.
andrewtaylorjohnson
 
Posts: 6
Joined: Wed Mar 06, 2019 5:02 pm


Return to Amplify Shader Editor

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 1 guest