Created
February 26, 2016 00:03
-
-
Save Shell64/800d7822440bea417401 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This software is in the public domain. Where that dedication is not recognized, | |
you are granted a perpetual, irrevokable license to copy and modify this file | |
as you see fit. | |
*/ | |
float GetDepth(sampler2D tex_heightmap, vec2 UV ) { | |
return texture2D(tex_heightmap, UV).r; | |
} | |
vec4 effect(vec4 colour, sampler2D tex_heightmap, vec2 UV, vec2 pixel_UVs) { | |
float Depth = GetDepth(tex_heightmap, UV); | |
float WidthOffset = 1.0 / (love_ScreenSize.x / love_ScreenSize.y * 640.0); | |
float HeightOffset = 1.0 / 640.0; | |
float OcclusionCapacity = 1.0; | |
float Occlusion = 0.0; | |
float Multiplier = 6.0; | |
float DepthTolerance = 0.1; | |
float Steps = 4.0 * 8.0; | |
float CurrentDepth; | |
for(int I = 0; I < Steps / 4.0; I++) | |
{ | |
CurrentDepth = GetDepth(tex_heightmap, vec2(UV.x + WidthOffset,UV.y + HeightOffset)); | |
Occlusion += min(OcclusionCapacity, max(0.0,Depth - CurrentDepth - DepthTolerance) * Multiplier); | |
CurrentDepth = GetDepth(tex_heightmap, vec2(UV.x - WidthOffset,UV.y + HeightOffset)); | |
Occlusion += min(OcclusionCapacity, max(0.0,Depth - CurrentDepth - DepthTolerance) * Multiplier); | |
CurrentDepth = GetDepth(tex_heightmap, vec2(UV.x + WidthOffset,UV.y - HeightOffset)); | |
Occlusion += min(OcclusionCapacity, max(0.0,Depth - CurrentDepth - DepthTolerance) * Multiplier); | |
CurrentDepth = GetDepth(tex_heightmap, vec2(UV.x - WidthOffset,UV.y - HeightOffset)); | |
Occlusion += min(OcclusionCapacity, max(0.0,Depth - CurrentDepth - DepthTolerance) * Multiplier); | |
WidthOffset *= 1.5; | |
HeightOffset *= 1.5; | |
Multiplier = Multiplier / 1.5; | |
} | |
Occlusion /= Steps; | |
Occlusion = 1.0 - Occlusion; | |
//return Albedo - Occlusion; | |
return vec4(Occlusion, Occlusion, Occlusion, 1.0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment