Discard Wire 2-Sided

Gezielter Einsatz der discard() Funktion in Kombination mit der Special Input Variabel gl_FrontFacing. Sie liefert bei Blick auf die Rückseite einer fläche den Bool-Wert false.

Screenshot:

Vertex Shader:

vec3  Normal;
vec3  EyeDir;
vec4  EyePos;
varying float LightIntensity;
varying vec3  OBposition;
uniform vec3  LightPosition;

void main(void) {
  //light
  gl_Position    = ftransform();
  Normal         = normalize(gl_NormalMatrix * gl_Normal);
  vec4 pos       = gl_ModelViewMatrix * gl_Vertex;
  EyeDir         = pos.xyz;
  EyePos         = gl_ModelViewProjectionMatrix * gl_Vertex;
  LightIntensity = max(dot(normalize(LightPosition - EyeDir), Normal), 0.0);
  //end light

  OBposition     = gl_Vertex.xyz;
}

Fragment Shader:

varying float LightIntensity;
varying vec3  OBposition;
uniform vec3  Color;
uniform float cellSize;
uniform float border;
const float   thresh = 0.4;

void main(){
  vec3 position  = mod(OBposition,cellSize);
  vec3 tmpVal    = step(border,position);
  
  float mixVal   = max(tmpVal.x * tmpVal.y * tmpVal.z,0.0);
  
  if (mixVal > thresh) discard;
  vec3 newColor = Color * LightIntensity;
  if (!gl_FrontFacing) newColor = vec3(0.0,0.6,0.0);
  gl_FragColor = vec4(newColor, 1.0);
}