0

I want to give different colors for two sides of plane to mesh in opengl.

Can I use clip_Distance like variables to cut the face in two halfs?

or by writing custom geometry shader to emit vertices at the cut planes.

Can I use the face cutting functionality which is inside opengl driver used for clipping?

2 Answers2

3

You could use gl_FrontFacing in your fragment shader to determine whether the front side or the back side is currently shaded and use two different color based on the value of that boolean.

Just for completeness sake: For this to work, make sure that you render both, the front faces and the back faces of your geometry, i.e. disable culling:

glDisable(GL_CULL_FACE);
Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
j00hi
  • 5,420
  • 3
  • 45
  • 82
  • Culling isn't on by default, so you don't need to disable it unless you enable it in other parts of your code. – Andrea Dec 30 '18 at 14:48
  • will this gl_Front Facing work for custom plane defined by normal and distance from origin ? – saurabh jadhav Dec 30 '18 at 15:37
  • I can't tell whether or not `gl_FrontFacing` works for your custom plane because I don't know how you are submitting it to the GPU. What I've descibed works for OpenGL primitives. – j00hi Jan 02 '19 at 08:18
0

It was simple than I thought

Since fragment shader works after rasterization , calculate the distance of each fragment from custom plane using the dot product of plane normal and interpolated Model coordinates received in fragment shader and assign different colors simply by an if statement.

Thank you all for your efforts!