You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

voxelfrag.frag.glsl 703B

1234567891011121314151617181920212223242526272829303132
  1. #version 430
  2. #extension GL_EXT_texture_array : enable
  3. in vec3 texCoordInterp;
  4. in vec3 lightDataInterp;
  5. in vec4 eyeSpacePos;
  6. out vec4 outColor;
  7. uniform sampler2DArray texture;
  8. const vec4 fogColor = vec4(0.46f, 0.8f, 0.99f, 1.0f);
  9. const float fogDensity = 0.005f;
  10. float getFogFactor(float fogCoord) {
  11. //get factor
  12. float fResult = 0.0f;
  13. fResult = exp(-fogDensity*fogCoord);
  14. fResult = 1.0-clamp(fResult, 0.0, 1.0);
  15. return fResult;
  16. }
  17. void main() {
  18. //fog calculations
  19. vec4 texel = texture2DArray(texture, texCoordInterp);
  20. outColor = texel * vec4(lightDataInterp, 1.0f);
  21. float fogCoord = abs(eyeSpacePos.z/eyeSpacePos.w);
  22. outColor = mix(outColor, fogColor, getFogFactor(fogCoord));
  23. }