ies.glsl 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. uniform sampler2D texIES;
  2. float iesAttenuation(vec3 l) {
  3. const float PI = 3.1415926535;
  4. // https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  5. // Sample direction into light space
  6. // vec3 iesSampleDirection = mul(light.worldToLight , -L);
  7. // Cartesian to spherical
  8. // Texture encoded with cos( phi ), scale from -1 - >1 to 0 - >1
  9. // float phiCoord = (iesSampleDirection.z * 0.5f) + 0.5f;
  10. // float theta = atan2 (iesSampleDirection.y , iesSampleDirection .x);
  11. // float thetaCoord = theta * (1.0 / (PI * 2.0));
  12. // float iesProfileScale = texture(texIES, vec2(thetaCoord, phiCoord)).r;
  13. // return iesProfileScale;
  14. // 1D texture
  15. // vec3 pl = normalize(p - lightPos);
  16. // float f = asin(dot(pl, l)) / PI + 0.5;
  17. // return texture(texIES, vec2(f, 0.0)).r;
  18. // 1D texture
  19. // float cosTheta = dot(lightToPos, lightDir);
  20. // float angle = acos(cosTheta) * (1.0 / PI);
  21. // return texture(texIES, vec2(angle, 0.0), 0.0).r;
  22. // Based on https://github.com/tobspr/RenderPipeline
  23. float hor = acos(l.z) / PI;
  24. float vert = atan(l.x, l.y) * (1.0 / (PI * 2.0)) + 0.5;
  25. return texture(texIES, vec2(hor, vert)).r;
  26. }