Code: Select all
const float pm15 = gl_ProjectionMatrix[2][3];
const float pm11 = gl_ProjectionMatrix[2][3];
Moderator: Moderators
Code: Select all
const float pm15 = gl_ProjectionMatrix[2][3];
const float pm11 = gl_ProjectionMatrix[2][3];
This widget will go GREAT with Hoi's bloom widget!jK wrote:Okay, I removed it from my webserver ...
I SAID IT IS A CODE EXAMPLE AND NOT A WIDGET
you especially need to take a whole boxclumsy_culhane wrote:lol jK calm the f*** down. That said, everyone i think needs to take a chill pill...
Gnome wrote:This widget will go GREAT with Hoi's bloom widget!jK wrote:Okay, I removed it from my webserver ...
I SAID IT IS A CODE EXAMPLE AND NOT A WIDGET
wow great widgetjK wrote:1. THIS IS NOT A WIDGET!!!
dizekat wrote:lol nubs
jK, can you put your code somewhere on pastebin maybe? I'm curious how it works, and theres no ways nubs will copypaste it into lua widget from pastebin.
Code: Select all
depthcopy = gl.CreateTexture(vsx,vsy, {
border = false,
format = GL_DEPTH_COMPONENT24,
min_filter = GL.NEAREST,
mag_filter = GL.NEAREST,
})
ssaoShader = gl.CreateShader({
vertex = [[
varying vec2 normScreenCoord;
void main()
{
normScreenCoord = gl_Vertex.xy;
gl_Position = vec4( (gl_Vertex.xy-0.5)*2.0 ,1.0,1.0);
}
]],
fragment = [[
uniform sampler2D tex0;
varying vec2 normScreenCoord;
//////////////////////////////////////////////////
// Depth conversion
const float pm15 = gl_ProjectionMatrix[2][3];
const float pm11 = gl_ProjectionMatrix[2][3];
float convertDepthToZ(float d) {
return pm15 / (((d * 2.0) - 1.0) + pm11);
}
vec4 convertDepthToZ(vec4 d) {
return pm15 / (((d * 2.0) - 1.0) + pm11);
}
//////////////////////////////////////////////////
// Main
void main(void)
{
float depth = convertDepthToZ( texture2D(tex0, normScreenCoord ).r );
float texelScale = clamp(1.0-depth*0.002,0.0,1.0);
vec2 texel = vec2(dFdx(normScreenCoord.s),dFdy(normScreenCoord.t))*3.0*texelScale;
float ao = 0.0;
float aoMultiplier = 0.3;
float depthTolerance = 0.01;
vec4 depths,depthsFix;
depths.x = texture2D(tex0, normScreenCoord+vec2(texel.x,0.0) ).r;
depths.y = texture2D(tex0, normScreenCoord+vec2(0.0,texel.y) ).r;
depths.z = texture2D(tex0, normScreenCoord+vec2(-texel.x,0.0) ).r;
depths.w = texture2D(tex0, normScreenCoord+vec2(0.0,-texel.y) ).r;
depths = convertDepthToZ(depths);
depths = (depth-depths-depthTolerance) * aoMultiplier;
bvec4 facb = greaterThan( depths, vec4(0.3) );
vec4 fac = vec4(float(facb.x),float(facb.y),float(facb.z),float(facb.w));
depthsFix = smoothstep(0.3,0.8,depths);
depths = smoothstep(0.0,0.2,depths) - fac*depthsFix;
ao += depths.x + depths.y + depths.z + depths.w;
texel*=2.0;
aoMultiplier*=0.75;
depths.x = texture2D(tex0, normScreenCoord+vec2(texel.x,0.0) ).r;
depths.y = texture2D(tex0, normScreenCoord+vec2(0.0,texel.y) ).r;
depths.z = texture2D(tex0, normScreenCoord+vec2(-texel.x,0.0) ).r;
depths.w = texture2D(tex0, normScreenCoord+vec2(0.0,-texel.y) ).r;
depths = convertDepthToZ(depths);
depths = (depth-depths-depthTolerance) * aoMultiplier;
facb = greaterThan( depths, vec4(0.3) );
fac = vec4(float(facb.x),float(facb.y),float(facb.z),float(facb.w));
depthsFix = smoothstep(0.3,0.8,depths);
depths = smoothstep(0.0,0.2,depths) - fac*depthsFix;
ao += depths.x + depths.y + depths.z + depths.w;
ao/=6.0;
ao=min(ao,0.5);
gl_FragColor = vec4(1.0-ao);
//gl_FragColor = vec4(texelScale);
//gl_FragColor = vec4(max(0.4,1.0-depth*0.002));
//gl_FragColor.rga *= 0.5;
}
]],
uniformInt = {
tex0 = 0,
}
})
function widget:DrawWorld()
gl.CopyToTexture(depthcopy, 0, 0, 0, 0, vsx, vsy)
gl.Blending(GL.ZERO,GL.SRC_COLOR)
--gl.Blending(false)
gl.UseShader(ssaoShader)
gl.Texture(0,depthcopy)
gl.TexRect(0,1,1,0)
gl.Texture(0,false)
gl.UseShader(0)
gl.Blending(GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA)
end