Low polygon cone - smooth shading at the tip

前端 未结 2 945
醉话见心
醉话见心 2020-12-18 07:51

If you subdivide a cylinder into an 8-sided prism, calculating vertex normals based on their position (\"smooth shading\"), it looks pretty good.

If you subdivide a

2条回答
  •  甜味超标
    2020-12-18 08:46

    Yes, it certainly is a limitation of triangles. I think showing the issue as you approach a cone from a cylinder makes the problem quite clear:

    enter image description here

    Here's some things you could try...

    1. Use quads (as @WhitAngl says). To hell with new OpenGL, there is a use for quads after all.

    2. Tessellate a bit more evenly. Setting the normal at the tip to a common up vector removes any harsh edges, though looks a bit strange against the unlit side. Unfortunately this goes against your question title, low polygon cone.

      enter image description here

    3. Making sure your cone is centred around the object space origin (or procedurally generating it in the vertex shader), use the fragment position to generate the normal...

      in vec2 coneSlope; //normal x/z magnitude and y
      in vec3 objectSpaceFragPos;
      
      uniform mat3 normalMatrix;
      
      void main()
      {
          vec3 osNormal = vec3(normalize(objectSpaceFragPos.xz) * coneSlope.x, coneSlope.y);
          vec3 esNormal = normalMatrix * osNormal;
          ...
      }
      

      Maybe there's some fancy tricks you can do to reduce fragment shader ops too. Then there's the whole balance of tessellating more vs more expensive shaders.

    A cone is a fairly simple object and, while I like the challenge, in practice I can't see this being an issue unless you want lots of cones. In which case you might get into geometry shaders or instancing. Better yet you could draw the cones using quads and raycast implicit cones in the fragment shader. If the cones are all on a plane you could try normal mapping or even parallax mapping.

提交回复
热议问题