How to get flat normals on a cube

后端 未结 3 1214
北海茫月
北海茫月 2021-01-05 22:12

I am using OpenGL without the deprecated features and my light calculation is done on fragment shader. So, I am doing smooth shading.

My problem, is that when I am d

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-05 23:08

    Another option would be to pass MV-matrix and the unrotated AxisAligned coordinate to the fragment shader:

     attribute aCoord;
     varying vCoord;
     void main() {
        vCoord = aCoord;
        glPosition = aCoord * MVP;
     }
    

    At Fragment shader one can then identify the normal by calculating the dominating axis of vCoord, setting that to 1.0 (or -1.0) and the other coordinates to zero -- that is the normal, which has to be rotated by the MV -matrix.

提交回复
热议问题