Geen omschrijving

sparseresidency.frag 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #version 450
  2. #extension GL_ARB_sparse_texture2 : enable
  3. #extension GL_ARB_sparse_texture_clamp : enable
  4. layout (binding = 1) uniform sampler2D samplerColor;
  5. layout (location = 0) in vec2 inUV;
  6. layout (location = 1) in float inLodBias;
  7. layout (location = 2) in vec3 inNormal;
  8. layout (location = 3) in vec3 inViewVec;
  9. layout (location = 4) in vec3 inLightVec;
  10. layout (location = 0) out vec4 outFragColor;
  11. void main()
  12. {
  13. vec4 color = vec4(0.0);
  14. // Get residency code for current texel
  15. int residencyCode = sparseTextureARB(samplerColor, inUV, color, inLodBias);
  16. // Fetch sparse until we get a valid texel
  17. float minLod = 1.0;
  18. while (!sparseTexelsResidentARB(residencyCode))
  19. {
  20. residencyCode = sparseTextureClampARB(samplerColor, inUV, minLod, color);
  21. minLod += 1.0f;
  22. }
  23. // Check if texel is resident
  24. bool texelResident = sparseTexelsResidentARB(residencyCode);
  25. if (!texelResident)
  26. {
  27. color = vec4(1.0, 0.0, 0.0, 0.0);
  28. }
  29. vec3 N = normalize(inNormal);
  30. N = normalize((inNormal - 0.5) * 2.0);
  31. vec3 L = normalize(inLightVec);
  32. vec3 R = reflect(-L, N);
  33. vec3 diffuse = max(dot(N, L), 0.25) * color.rgb;
  34. outFragColor = vec4(diffuse, 1.0);
  35. }