Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #version 300 es
- precision highp float;
- precision highp sampler3D;
- precision lowp usampler2D;
- precision lowp usampler3D;
- uniform sampler2D light;
- uniform sampler2D velocity;
- uniform usampler2D index2Dto3D;
- uniform usampler3D index3Dto2D;
- uniform sampler3D voxel;
- in vec2 v_texCoord;
- layout (location = 0) out vec4 outLight;
- layout (location = 1) out vec4 outVelocity;
- uvec3 to3D(uvec2 v) {
- return texelFetch(index2Dto3D, ivec2(v), 0).zyx;
- }
- uvec2 to2D(uvec3 v) {
- return texelFetch(index3Dto2D, ivec3(v), 0).xy;
- }
- vec4 getLight(uvec3 v) {
- return texelFetch(light, ivec2(to2D(v)), 0);
- }
- vec4 getVoxel(uvec3 v) {
- return texelFetch(voxel, ivec3(v), 0);
- }
- vec4 getVelocity(uvec3 v) {
- return texelFetch(velocity, ivec2(to2D(v)), 0);
- }
- void main() {
- vec4 lightLast = texelFetch(light, ivec2(gl_FragCoord.xy), 0);
- uvec3 iCE = to3D(uvec2(gl_FragCoord.xy));
- vec4 lCE = getLight(iCE);
- vec4 vCE = getVoxel(iCE);
- vec4 veCE = getVelocity(iCE);
- vec3 v = vec3(0.0);
- // colision test
- if (vCE.r > 0.0 || vCE.g > 0.0 || vCE.b > 0.0) {
- if (vCE.a == 0.0) {
- outLight = vec4(0);
- } else {
- outLight = vCE;
- }
- } else {
- uvec3 iFR = uvec3(iCE);
- uvec3 iBA = uvec3(iCE);
- uvec3 iLE = uvec3(iCE);
- uvec3 iRI = uvec3(iCE);
- uvec3 iTO = uvec3(iCE);
- uvec3 iBO = uvec3(iCE);
- iRI.x += 1u;
- iLE.x -= 1u;
- iFR.y += 1u;
- iBA.y -= 1u;
- iTO.z += 1u;
- iBO.z -= 1u;
- vec4 lRI = getLight(iRI);
- vec4 lLE = getLight(iLE);
- vec4 lFR = getLight(iFR);
- vec4 lBA = getLight(iBA);
- vec4 lTO = getLight(iTO);
- vec4 lBO = getLight(iBO);
- vec4 vRI = getVoxel(iRI);
- vec4 vLE = getVoxel(iLE);
- vec4 vFR = getVoxel(iFR);
- vec4 vBA = getVoxel(iBA);
- vec4 vTO = getVoxel(iTO);
- vec4 vBO = getVoxel(iBO);
- vec4 veRI = getVelocity(iRI);
- vec4 veLE = getVelocity(iLE);
- vec4 veFR = getVelocity(iFR);
- vec4 veBA = getVelocity(iBA);
- vec4 veTO = getVelocity(iTO);
- vec4 veBO = getVelocity(iBO);
- // difference
- float dRI = lCE.a - lRI.a;
- float dLE = lCE.a - lLE.a;
- float dFR = lCE.a - lFR.a;
- float dBA = lCE.a - lBA.a;
- float dTO = lCE.a - lTO.a;
- float dBO = lCE.a - lBO.a;
- // vectoring
- v += veRI.xyz + veLE.xyz + veFR.xyz + veBA.xyz + veTO.xyz + veBO.xyz;
- v.x -= dRI;
- v.x += dLE;
- v.y -= dFR;
- v.y += dBA;
- v.z -= dTO;
- v.z += dBO;
- float intencity = 0.0;
- intencity += dot(lRI.xyz, + vec3(1.0, 0.0, 0.0));
- intencity += dot(lLE.xyz, - vec3(1.0, 0.0, 0.0));
- intencity += dot(lFR.xyz, + vec3(0.0, 1.0, 0.0));
- intencity += dot(lBA.xyz, - vec3(0.0, 1.0, 0.0));
- intencity += dot(lTO.xyz, + vec3(0.0, 0.0, 1.0));
- intencity += dot(lBO.xyz, - vec3(0.0, 0.0, 1.0));
- outLight.a += clamp(intencity / 6.0, 0.0, vCE.a);
- outVelocity.xyz = v / 6.0;
- // outLight = vec4(float(i2.x) / 512.0, 0.01,0.0,1.0);
- outLight.rgb = vec3(outLight.a);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement