Page 1 of 1

Vertex Normal Recalculation Issues

PostPosted: Wed Mar 06, 2019 5:26 pm
by andrewtaylorjohnson
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 14372 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 14372 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 14372 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!

Re: Vertex Normal Recalculation Issues

PostPosted: Wed Mar 06, 2019 11:14 pm
by andrewtaylorjohnson
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 14368 times


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


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


I'm at a real loss on this one :(

Re: Vertex Normal Recalculation Issues

PostPosted: Tue Mar 12, 2019 11:08 am
by Amplify_Borba
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?

Re: Vertex Normal Recalculation Issues

PostPosted: Tue Mar 12, 2019 2:32 pm
by andrewtaylorjohnson
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 1262 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 14327 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 14327 times


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

Thanks again! Any help would be very much appreciated!

Re: Vertex Normal Recalculation Issues

PostPosted: Fri Mar 15, 2019 2:40 pm
by Amplify_Borba
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.

Re: Vertex Normal Recalculation Issues

PostPosted: Fri Mar 15, 2019 6:08 pm
by andrewtaylorjohnson
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.

Re: Vertex Normal Recalculation Issues

PostPosted: Wed Mar 20, 2019 9:51 am
by Amplify_Borba
Hey! Apologies but I haven't received anything through PM, could you please send it through [email protected]?

Re: Vertex Normal Recalculation Issues

PostPosted: Fri Apr 05, 2019 9:17 am
by Amplify_Borba
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!

Re: Vertex Normal Recalculation Issues

PostPosted: Fri Apr 05, 2019 3:00 pm
by andrewtaylorjohnson
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.