Skip to content

Instantly share code, notes, and snippets.

@jcm2606
Created November 26, 2016 11:30
Show Gist options
  • Save jcm2606/71ff13a052823883bafc6835a7289933 to your computer and use it in GitHub Desktop.
Save jcm2606/71ff13a052823883bafc6835a7289933 to your computer and use it in GitHub Desktop.
float getVolumetricRays(out vec4 sampledColour) {
///////////////////////Setting up functions///////////////////////
vec3 rSD = vec3(0.0);
rSD.x;
rSD.y = 6.0 / VL_QUALITY;
rSD.z = find_closest(texcoord.st);
rSD.z *= rSD.y;
const float maxDist = (VL_DISTANCE);
float minDist = (0.001);
minDist += rSD.z;
float weight = (maxDist / rSD.y);
vec4 worldposition = vec4(0.0);
const vec4 scol = vec4(vec3(0.25), 0.0);
vec4 colour = scol;
vec4 dcolour = scol;
for (minDist; minDist < maxDist;) {
///////////////////////MAKING VL NOT GO THROUGH WALLS///////////////////////
if (depthExpToLinear(position.depthTransparent) < minDist) break;
///////////////////////Getting worldpositon///////////////////////
worldposition = getShadowWorldPos(distx(minDist),texcoord.st);
///////////////////////Rescaling ShadowMaps///////////////////////
worldposition = biasShadowPosition(worldposition);
///////////////////////Projecting shadowmaps on a linear depth plane///////////////////////
float solid = (shadow2D(watershadow, worldposition.rgb).x);
#ifdef VL_UNDERWATER
float transparent = (shadow2D(shadow, worldposition.rgb).x) - solid;
if(isEyeInWater == 1 || (isEyeInWater == 0 && transparent > 0.1 && dcolour == colour)) colour = (shadow2D(shadowcolor, worldposition.rgb));
if((isEyeInWater == 0 && transparent > 0.1 && dcolour == colour)) dcolour = colour;
float FdotL = clamp(pow(dot(normalize(getFragPosition(texcoord.st, position.depthTransparent, false).xyz), lightVector), 3.0), 0.0, 1.0);
if(isEyeInWater == 1) transparent *= range(0.0, 0.5, 1 - (pow(colour.a, mix(0.25, 1.25, FdotL))));
//transparent *= isEyeInWater == 1 ? (1.0 - pow(colour.a * 2.0 - 0.9, mix(1.0, 4.0, FdotL))) : 1.0;
solid += transparent;
#endif
rSD.x += solid;
minDist = minDist + rSD.y;
}
///////////////////////Returning the program///////////////////////
rSD.x /= weight;
rSD.x *= 0.15 * maxDist / 32;
rSD.x = mix(rSD.x, clamp(rSD.x, 0.0, 0.1), dynamicExposure());
sampledColour = colour;
return rSD.x;
}
// This is a custom VL colour function that is based off of your's. I just found things easier to work with if I wrote them myself.
vec3 getVLColour(vec3 bgcol, vec2 pos, vec3 fpos) {
float vlSample = 0.0;
float vlWeight = 0.0;
float rainx = clamp(rainStrength, 0.0, 1.0) / 1.0;
vec4 colourSample;
for(float f0 = -1.0; f0 < 1.0; f0++) {
for(float f1 = -1.0; f1 < 1.0; f1++) {
vec2 offset = vec2(f0, f1) / vec2(viewWidth, viewHeight);
float weight = pow(1.0 - abs(ld(position.depthTransparent) - ld(texture2D(depthtex1, pos.xy + offset * 8.0 + refract.xy).x)) * 10.0, 32.0);
weight = max(0.1e-8, weight);
colourSample = texture2DLod(gaux3, pos.xy + offset * 4.0 + refract.xy, VL_MIPMAP_LEVEL);
vlSample += colourSample.a * weight;
vlWeight += weight;
}
}
vlSample /= vlWeight;
vlSample *= 20.0;
//colourSample /= vlWeight;
//colourSample.a *= 4.0;
float eBS = min(VL_BRIGHTNESS_LIMIT, mix(1.0, 0.0, pow(eyeBrightnessSmooth.y / 240.0, 3.0)));
float FdotL = clamp(pow(dot(normalize(fpos), lightVector), VL_NEARFAR_DISTANCE), 0.0, 1.0);
float vlStrengthInsideDay = eBS * 12.5 * 0.15 * VL_STRENGTH_INSIDE * (1 - moonVisibility);
float vlStrengthInsideNight = eBS * 12.5 * 0.2 * VL_STRENGTH_INSIDE_NIGHT * (moonVisibility);
float vlStrengthDay = mix(VL_STRENGTH_DAY, VL_STRENGTH_DAY_RAIN, rainx) * Noon;
float vlStrengthNight = mix(VL_STRENGTH_NIGHT, VL_STRENGTH_NIGHT_RAIN, rainx) * Midnight;
float vlStrengthHorizon = mix(VL_STRENGTH_HORIZON, VL_STRENGTH_HORIZON_RAIN, rainx) * Horizon;
vec3 fogColour = isEyeInWater == 0 ? directLight : mix(pow(vec3(WATER_VL_R, WATER_VL_G, WATER_VL_B) * WATER_VL_A * (WATER_VL_HORIZON * Horizon + WATER_VL_DAY * Noon + WATER_VL_NIGHT * Midnight), vec3(2.2)) * 1, directLight * 0.0125, clamp(pow(FdotL, 0.5), 0.0, 1.0));
const vec3 grey = vec3(0.3, 0.59, 0.11);
vec3 greyc = vec3(dot(grey, fogColour));
fogColour = vec3(mix(fogColour, greyc, mix(-VL_SATURATION_FAR, -VL_SATURATION_NEAR, FdotL)));
vec3 vlFinalColour = fogColour * ((vlStrengthDay + vlStrengthNight + vlStrengthHorizon) * mix(vlDistIntensityFar, vlDistIntensityNear * (VL_INTENSITY_NEAR_HORIZON * Horizon + VL_INTENSITY_NEAR_NOON * Noon + VL_INTENSITY_NEAR_MIDNIGHT), FdotL * (1 - rain)));
#ifdef VL_COLOURED
if(isEyeInWater == 0) vlFinalColour *= saturate(colourSample.rgb * 1.0, VL_COLOUR_SATURATION);
#endif
//if(isEyeInWater == 0) vlFinalColour += saturate(ambientLight * (1 - FdotL) * (1 - Midnight), 1.0);
vlFinalColour *= (1.0 + mix((vlStrengthInsideDay + vlStrengthInsideNight), 0.0, rainx));
//vlFinalColour *= FdotL;
vlFinalColour = mix(bgcol, vlFinalColour, vlSample * 0.2 * 0.1 * 0.5 * vlFinalMultiplier * transition_fading);
return vlFinalColour;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment