0

I am using WebGL, porting some of my older programs written in OpenGL. There is a cone with Archimedean Spiral basis. It goes from 0 to Math.PI and symmetrically to axis X in the opposite direction. The problem is about lighting transition at the tip of the cone, it is not smooth. But it is smooth at the basis of pyramid.

On the left it is divided into ten sectors, and on the right is divided in forty sectors. The problem is visible on the both. The normal is calculated as the gradient of the Archimedean Spiral in each point.

enter image description here

I understand why it happens, and geometrically it should happen for any shape. But just in case, there are the equations upper part of this hearth cone:
The spiral is described as F(φ) = [φ * cos(φ), φ * sin(φ)]
The calculated normal ∇F(φ) = [sin(φ) + φ * cos(φ), -cos(φ) + φ * sin(φ)]
And the Z coordinate which is really not important in our case.

Particularly I tried different suggestions, for instance as described here: Low polygon cone - smooth shading at the tip
But it worked somehow similarly to gl.TRIANGLE_FAN, which acts differently, the tip faded in a single colour, and then interpolated to the other normals of each triangle.

Solved: Thanks to all. Solution worked as expected, see following set screenshots. On the left is a cone divided in ten sectors, and on the right is the cone divided in forty sectors. Cone fixed

armagedescu
  • 1,758
  • 2
  • 20
  • 31
  • 1
    I'm not sure what you're expecting. One of the solutions you linked to suggests making the tip have a normal of [0, 0, 0] which seems to make sense. If your shader is normalizing the result then the tip will have no influence and except for the exact tip (which isn't actually rendered) the interpolation from the other 2 vertices will give you the result you want. No? https://jsfiddle.net/greggman/cuo8nkmz/ – gman Dec 08 '19 at 05:35
  • @gman I know I do it the wrong way. But I am puzzled anyway. What colour do you pass to the fragment shader to the tip of the cone? How the colour is calculated in the place where the normal is [0,0,0]? I am now analysing your example, thanks for it. – armagedescu Dec 09 '19 at 11:51
  • 1
    The thing is the normal passed to the pixel shader is never 0,0,0. Pixels what are drawn, no pixel is at 0,0,0, a pixel is at some fractional place down the triangle. So your 3 normals [0,0,0] and the other 2 at the other end of the triangle get interpolated and then normalized. 0,0,0 doesn't contribute so you really get an interpolation of just the other 2 vertices – gman Dec 09 '19 at 14:52
  • It might be helpful to look at a visualization of the normal vectors that you're assigning to the vertex; e.g. hack your fragment shader to output: gl_FragColor = vec4(0.5 * (normal + vec3(1.0)), 1.0) – prideout Dec 11 '19 at 17:30
  • @gman Finally, I've spent this morning some time, and all suggestions work, see the second screenshot. – armagedescu Dec 16 '19 at 11:52

0 Answers0