Emulating the GLSL flat qualifier in GLSL 120

I want to emulate flat shading in GLSL shader. I usually do this by passing normal with a flat

classifier to prevent interpolation in the fragment shader. However, flat

not available in GLSL 120.

How can I emulate it without duplicating vertex data? (This is not a premature optimization, but rather a posthumous one.)

+3


source to share


2 answers


You cannot accurately emulate flat

without direct hardware support (presumably as stated in GLSL 1.30+ support). Previous versions only offer "nothing or nothing": either all attributes are interpolated or not. This means glShadeModel

.



+2


source


Go to the same normal for each vertex of the triangle.



Or see if glShadeModel(GL_FLAT)

the inline attribute is affected gl_Normal

.

+1


source







All Articles