world.fs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #version 430
  2. layout (location = 0) out vec3 worldPosition;
  3. layout (location = 1) out vec3 worldNormal;
  4. layout (location = 2) out vec4 worldColor;
  5. layout (location = 3) out float worldShadow;
  6. layout (binding = 0) uniform sampler2D samp;
  7. layout (binding = 1) uniform sampler2D shadowSamp;
  8. in vec3 varPosition;
  9. in vec2 varTex;
  10. in vec3 varNormal;
  11. in vec4 varShadow;
  12. uniform bool shadows;
  13. uniform float radius;
  14. uniform float zbias;
  15. const int sampleAmount = 64;
  16. const vec2 samples[64] = {
  17. vec2(-0.000, -0.000), vec2(-0.007, 0.004), vec2(0.016, 0.001), vec2(-0.015, -0.018),
  18. vec2(-0.024, -0.020), vec2(0.036, -0.014), vec2(-0.015, -0.045), vec2(0.037, 0.041),
  19. vec2(-0.036, -0.051), vec2(-0.069, 0.014), vec2(0.068, -0.039), vec2(0.086, -0.001),
  20. vec2(0.062, -0.070), vec2(-0.066, -0.077), vec2(-0.010, 0.109), vec2(-0.013, 0.117),
  21. vec2(-0.086, 0.091), vec2(0.019, 0.131), vec2(-0.051, 0.131), vec2(0.133, 0.067),
  22. vec2(0.154, -0.024), vec2(0.151, -0.063), vec2(0.124, 0.119), vec2(0.133, -0.121),
  23. vec2(0.149, 0.113), vec2(-0.188, -0.054), vec2(0.030, 0.201), vec2(0.002, 0.211),
  24. vec2(-0.063, -0.209), vec2(0.013, 0.226), vec2(-0.052, 0.229), vec2(-0.093, -0.223),
  25. vec2(0.153, 0.198), vec2(0.258, -0.005), vec2(-0.188, -0.188), vec2(0.267, -0.061),
  26. vec2(0.150, -0.238), vec2(0.027, 0.288), vec2(-0.293, 0.049), vec2(-0.044, 0.301),
  27. vec2(-0.018, 0.312), vec2(-0.296, -0.121), vec2(0.026, -0.327), vec2(-0.248, 0.226),
  28. vec2(-0.344, -0.008), vec2(-0.042, 0.349), vec2(-0.357, -0.038), vec2(-0.156, -0.332),
  29. vec2(-0.342, 0.154), vec2(0.031, 0.382), vec2(-0.331, 0.207), vec2(0.209, -0.339),
  30. vec2(-0.068, -0.401), vec2(-0.409, -0.063), vec2(-0.249, 0.340), vec2(-0.041, 0.428),
  31. vec2(0.326, 0.292), vec2(-0.127, -0.427), vec2(0.226, 0.393), vec2(0.424, 0.180),
  32. vec2(-0.063, 0.465), vec2(0.446, -0.167), vec2(-0.477, -0.084), vec2(-0.433, -0.234)
  33. };
  34. const vec3 light = vec3(-0.280166, -0.573576, -0.769751);
  35. void main(void) {
  36. worldPosition = varPosition;
  37. worldNormal = varNormal;
  38. if(shadows) {
  39. vec3 pos = varShadow.xyz / varShadow.w;
  40. //float fbias = zbias * (1.0 - max(dot(worldNormal, -light), 0.0));
  41. float shadow = 0.0;
  42. for(int i = 0; i < sampleAmount; i++) {
  43. shadow += float(texture(shadowSamp, pos.xy + samples[i] * radius).r + zbias > pos.z);
  44. }
  45. shadow /= sampleAmount;
  46. worldShadow = shadow;
  47. } else {
  48. worldShadow = 1.0;
  49. }
  50. //worldColor = vec4(1, 0, 0, 1);
  51. //worldColor = vec4(worldNormal, 1);
  52. worldColor = texture(samp, varTex);
  53. //worldColor = texture(normalSamp, varTex);
  54. }