Normal vectors for an eight vertex cube

后端 未结 2 1823
天涯浪人
天涯浪人 2021-01-20 10:44

I was playing around with WEBGL and today and a encountered a problem with my cube\'s vertex normals .

I checked my code with a cube mesh from internet and it works

2条回答
  •  梦谈多话
    2021-01-20 11:33

    You could use a pass through Geometry shader to get around this.

    A geometry shader takes in a shape and outputs another one (which can be of the same type). In your case it should just output the same triangle it takes as input. It should also calcualte the normal and send it over to the FS

    Find code for the VS, GS and FS here: https://community.khronos.org/t/calculate-normals-in-vertex-shader/71573/4

    For more info on geometry shaders check: "Visualizing normal vectors" here: https://learnopengl.com/Advanced-OpenGL/Geometry-Shader

提交回复
热议问题