www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: AeroShark333 on November 21, 2023, 05:52:46 pm

Title: Obtain normals to adjust vertex controller normals
Post by: AeroShark333 on November 21, 2023, 05:52:46 pm
Hello,

Currently I have an Object3D with a vertexcontroller attached to it. (Modify = false mode)
The vertexcontroller only changes the vertices positions of the mesh and doesn't touch the normals.
In the draw method I currently do the following three operations:
1. Apply vertexcontroller
2. Object3D#touch
3. Object3D#calcNormals

Is it possible to obtain the calculated normals so they could be fed into the vertexcontroller immediately? I wish to save calculation costs by not having to calculate the normals every frame.
In a sense I imagine I could pre-compute the normals with Object3D#calcNormals and then save the normals to be reused in the vertexcontroller. I looked at polygonmanager but no luck there...

Thanks in advance!
Title: Re: Obtain normals to adjust vertex controller normals
Post by: EgonOlsen on November 24, 2023, 07:51:31 am
I'm not sure what you mean exactly...the vertex controller can access the normals already, so you can modify them there. The issue with that is, as the docs state, that this calculation isn't trivial, because vertex normals depend on adjacent polygons as well.

 What do mean by

Quote
Is it possible to obtain the calculated normals so they could be fed into the vertexcontroller immediately?

Which calculated normals?
Title: Re: Obtain normals to adjust vertex controller normals
Post by: AeroShark333 on November 24, 2023, 02:56:35 pm
Hmmm, I'll try to explain better:

Currently, I have an animation where I deform the mesh (through its vertices).
I can't calculate the normals in the vertexcontroller because they depend on neighboring vertices.
However, if I use Object3D.calcNormals() after applying the vertexcontroller, then I suppose I will have the normals for the deformed mesh.
Is it possible to obtain these normals for future use, so in that case I could feed them into the vertexcontroller instead of having to call calcNormals() again.
Essentially, I am trying to create a cache of normals to avoid having to call calcNormals() during runtime.

I hope this makes sense...
Title: Re: Obtain normals to adjust vertex controller normals
Post by: EgonOlsen on November 27, 2023, 10:57:32 am
I see. If you call refreshMeshData() on the controller, the newly calculated normals should be updated in the controller and you can obtain them from there.
Title: Re: Obtain normals to adjust vertex controller normals
Post by: AeroShark333 on November 27, 2023, 07:58:18 pm
I see. If you call refreshMeshData() on the controller, the newly calculated normals should be updated in the controller and you can obtain them from there.
Thank you, works perfectly! :D

Also, this might be a minor bug: I think the 'shininess' value is not seem to be passed to the fragment shader (while the other uniform variables from the default vertex shader seem accessible though in the fragment shader). I don't need this as I can put custom shader code anyway... But I thought it would be nice to know.
Title: Re: Obtain normals to adjust vertex controller normals
Post by: EgonOlsen on November 28, 2023, 07:35:36 am
If that's the case, I guess that there must have been a reason for it... ;)

...I just can't remember it...