Skip to content

Instantly share code, notes, and snippets.

@jcm2606
Created February 15, 2017 12:32
Show Gist options
  • Save jcm2606/d61c063194ab038b8c5c81640e0dbd2f to your computer and use it in GitHub Desktop.
Save jcm2606/d61c063194ab038b8c5c81640e0dbd2f to your computer and use it in GitHub Desktop.
float getVolumetricRays(out vec4 sampledColour) {
///////////////////////Setting up functions///////////////////////
mat3x4 matrix0;
#define rSD matrix0[0]
#define worldposition matrix0[1]
#define colour matrix0[2]
rSD.x;
rSD.y = 6.0 / VL_QUALITY;
rSD.z = find_closest(texcoord.st);
rSD.z *= rSD.y;
mat2 matrix1;
#define minDist matrix1[0].x
#define weight matrix1[0].y
const float maxDist = (VL_DISTANCE);
minDist = (0.001);
minDist += rSD.z;
weight = (maxDist / rSD.y);
colour = vec4(vec3(VL_BASE_STRENGTH), 0.0);
int colourSample = 0;
#define solidShadow matrix1[1].x
#define transparentShadow matrix1[1].y
for (minDist; minDist < maxDist;) {
if (linearDepth(position.depthTransparent) < minDist) break; // VL wall fix
worldposition = getShadowWorldPos(distx(minDist),texcoord.st);
distortShadowSpace(worldposition.st);
solidShadow = shadow2D(watershadow, worldposition.rgb).x;
#ifdef VL_TRANSPARENCY
transparentShadow = shadow2D(shadow, worldposition.rgb).x - solidShadow;
#ifdef VL_ADVANCED
#if 0
vec3 newColour = shadow2D(shadowcolor, worldposition.rgb).rgb;
if(transparentShadow > 0.0 && any(lessThan(abs(colour.rgb - newColour), vec3(0.15)))) {
colour.rgb += newColour;
if(isEyeInWater == 1) transparentShadow *= colour.a;
if(any(greaterThan(newColour, vec3(0.0001)))) colourSample++;
}
#else
vec4 newColour = shadow2D(shadowcolor, vec3(worldposition.xy, 1.0));
colour.rgb = newColour.rgb;
#endif
#endif
solidShadow += transparentShadow;
#endif
rSD.x += solidShadow;
minDist = minDist + rSD.y;
}
//colour.rgb /= colourSample;
#undef solidShadow
#undef transparentShadow
rSD.x /= weight;
rSD.x *= 0.15 * maxDist / 32;
#undef minDist
#undef weight
rSD.x = mix(rSD.x, clamp(rSD.x, 0.0, 0.1), dynamicExposure());
sampledColour = colour;
return rSD.x;
#undef rSD
#undef worldposition
#undef colour
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment