Author Topic: Obtain normals to adjust vertex controller normals  (Read 2957 times)

Offline AeroShark333

  • float
  • ****
  • Posts: 320
    • View Profile
Obtain normals to adjust vertex controller normals
« 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!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12297
    • View Profile
    • http://www.jpct.net
Re: Obtain normals to adjust vertex controller normals
« Reply #1 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?

Offline AeroShark333

  • float
  • ****
  • Posts: 320
    • View Profile
Re: Obtain normals to adjust vertex controller normals
« Reply #2 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...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12297
    • View Profile
    • http://www.jpct.net
Re: Obtain normals to adjust vertex controller normals
« Reply #3 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.

Offline AeroShark333

  • float
  • ****
  • Posts: 320
    • View Profile
Re: Obtain normals to adjust vertex controller normals
« Reply #4 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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12297
    • View Profile
    • http://www.jpct.net
Re: Obtain normals to adjust vertex controller normals
« Reply #5 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...