instanced_objectpass_spheremap.frag 955 B

1234567891011121314151617181920212223242526272829303132333435
  1. // See http://www.ozone3d.net/tutorials/glsl_texturing_p04.php for ref
  2. #ifndef Use_Bindless_Texture
  3. uniform sampler2D tex;
  4. #endif
  5. #ifdef Use_Bindless_Texture
  6. flat in sampler2D handle;
  7. #endif
  8. in vec3 nor;
  9. out vec4 FragColor;
  10. vec4 getPosFromUVDepth(vec3 uvDepth, mat4 InverseProjectionMatrix);
  11. vec3 getLightFactor(vec3 diffuseMatColor, vec3 specularMatColor, float specMapValue, float emitMapValue);
  12. void main() {
  13. vec3 texc = gl_FragCoord.xyz / vec3(screen, 1.);
  14. vec3 u = getPosFromUVDepth(texc, InverseProjectionMatrix).xyz;
  15. vec3 r = reflect(u, nor);
  16. float m = 2.0 * sqrt(r.x * r.x + r.y * r.y + (r.z + 1.0) * (r.z + 1.0));
  17. r.y = - r.y;
  18. #ifdef Use_Bindless_Texture
  19. vec4 detail0 = texture(handle, r.xy / m + .5);
  20. #ifdef SRGBBindlessFix
  21. detail0.xyz = pow(detail0.xyz, vec3(2.2));
  22. #endif
  23. #else
  24. vec4 detail0 = texture(tex, r.xy / m + .5);
  25. #endif
  26. FragColor = vec4(getLightFactor(detail0.xyz, vec3(1.), 0., 0.), 1.);
  27. }