Advertisement
Guest User

Untitled

a guest
Feb 2nd, 2019
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #version 300 es
  2. precision highp float;
  3. precision highp sampler3D;
  4. precision lowp usampler2D;
  5. precision lowp usampler3D;
  6.  
  7. uniform sampler2D light;
  8. uniform sampler2D velocity;
  9. uniform usampler2D index2Dto3D;
  10. uniform usampler3D index3Dto2D;
  11. uniform sampler3D voxel;
  12.  
  13. in vec2 v_texCoord;
  14. layout (location = 0) out vec4 outLight;
  15. layout (location = 1) out vec4 outVelocity;
  16.  
  17. uvec3 to3D(uvec2 v) {
  18.     return texelFetch(index2Dto3D, ivec2(v), 0).zyx;
  19. }
  20.  
  21. uvec2 to2D(uvec3 v) {
  22.     return texelFetch(index3Dto2D, ivec3(v), 0).xy;
  23. }
  24.  
  25. vec4 getLight(uvec3 v) {
  26.     return texelFetch(light, ivec2(to2D(v)), 0);
  27. }
  28.  
  29. vec4 getVoxel(uvec3 v) {
  30.     return texelFetch(voxel, ivec3(v), 0);
  31. }
  32.  
  33. vec4 getVelocity(uvec3 v) {
  34.     return texelFetch(velocity, ivec2(to2D(v)), 0);
  35. }
  36.  
  37. void main() {
  38.  
  39.     vec4 lightLast = texelFetch(light, ivec2(gl_FragCoord.xy), 0);
  40.  
  41.     uvec3 iCE = to3D(uvec2(gl_FragCoord.xy));
  42.     vec4 lCE = getLight(iCE);
  43.     vec4 vCE = getVoxel(iCE);
  44.     vec4 veCE = getVelocity(iCE);
  45.     vec3 v = vec3(0.0);
  46.  
  47.     // colision test
  48.     if (vCE.r > 0.0 || vCE.g > 0.0 || vCE.b > 0.0) {
  49.         if (vCE.a == 0.0) {
  50.             outLight = vec4(0);
  51.         } else {
  52.             outLight = vCE;
  53.         }
  54.     } else {
  55.  
  56.         uvec3 iFR = uvec3(iCE);
  57.         uvec3 iBA = uvec3(iCE);
  58.         uvec3 iLE = uvec3(iCE);
  59.         uvec3 iRI = uvec3(iCE);
  60.         uvec3 iTO = uvec3(iCE);
  61.         uvec3 iBO = uvec3(iCE);
  62.  
  63.         iRI.x += 1u;
  64.         iLE.x -= 1u;
  65.         iFR.y += 1u;
  66.         iBA.y -= 1u;
  67.         iTO.z += 1u;
  68.         iBO.z -= 1u;
  69.  
  70.         vec4 lRI = getLight(iRI);
  71.         vec4 lLE = getLight(iLE);
  72.         vec4 lFR = getLight(iFR);
  73.         vec4 lBA = getLight(iBA);
  74.         vec4 lTO = getLight(iTO);
  75.         vec4 lBO = getLight(iBO);
  76.  
  77.         vec4 vRI = getVoxel(iRI);
  78.         vec4 vLE = getVoxel(iLE);
  79.         vec4 vFR = getVoxel(iFR);
  80.         vec4 vBA = getVoxel(iBA);
  81.         vec4 vTO = getVoxel(iTO);
  82.         vec4 vBO = getVoxel(iBO);
  83.  
  84.         vec4 veRI = getVelocity(iRI);
  85.         vec4 veLE = getVelocity(iLE);
  86.         vec4 veFR = getVelocity(iFR);
  87.         vec4 veBA = getVelocity(iBA);
  88.         vec4 veTO = getVelocity(iTO);
  89.         vec4 veBO = getVelocity(iBO);
  90.  
  91.  
  92.         // difference
  93.         float dRI = lCE.a - lRI.a;
  94.         float dLE = lCE.a - lLE.a;
  95.         float dFR = lCE.a - lFR.a;
  96.         float dBA = lCE.a - lBA.a;
  97.         float dTO = lCE.a - lTO.a;
  98.         float dBO = lCE.a - lBO.a;
  99.  
  100.         // vectoring
  101.         v += veRI.xyz + veLE.xyz + veFR.xyz + veBA.xyz + veTO.xyz + veBO.xyz;
  102.  
  103.         v.x -= dRI;
  104.         v.x += dLE;
  105.         v.y -= dFR;
  106.         v.y += dBA;
  107.         v.z -= dTO;
  108.         v.z += dBO;
  109.  
  110.         float intencity = 0.0;
  111.  
  112.         intencity += dot(lRI.xyz, + vec3(1.0, 0.0, 0.0));
  113.         intencity += dot(lLE.xyz, - vec3(1.0, 0.0, 0.0));
  114.         intencity += dot(lFR.xyz, + vec3(0.0, 1.0, 0.0));
  115.         intencity += dot(lBA.xyz, - vec3(0.0, 1.0, 0.0));
  116.         intencity += dot(lTO.xyz, + vec3(0.0, 0.0, 1.0));
  117.         intencity += dot(lBO.xyz, - vec3(0.0, 0.0, 1.0));
  118.  
  119.         outLight.a += clamp(intencity / 6.0, 0.0, vCE.a);
  120.         outVelocity.xyz = v / 6.0;
  121.  
  122.         // outLight = vec4(float(i2.x) / 512.0, 0.01,0.0,1.0);
  123.         outLight.rgb = vec3(outLight.a);
  124.    
  125.     }
  126.  
  127.  
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement