FragShader.fsh 730 B

123456789101112131415161718192021
  1. uniform sampler2D sThicknessTex;
  2. uniform highp float MinThickness;
  3. uniform highp float MaxVariation;
  4. varying mediump float CosViewAngle;
  5. varying mediump float LightIntensity;
  6. varying mediump vec2 TexCoord;
  7. // We use wave numbers (k) for the iridescence effect, given as
  8. // k = 2 * pi / wavelength in nm.
  9. const highp float PI = 3.141592654;
  10. const highp vec3 cRgbK = 2.0 * PI * vec3(1.0/475.0, 1.0/510.0, 1.0/650.0);
  11. void main()
  12. {
  13. highp float thickness = texture2D(sThicknessTex, TexCoord).r * MaxVariation + MinThickness;
  14. highp float delta = (thickness / LightIntensity) + (thickness / CosViewAngle);
  15. lowp vec3 color = cos(delta * cRgbK) * LightIntensity;
  16. gl_FragColor = vec4(color, 1.0);
  17. }