-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New SSAO Algorithm #62
base: rend2
Are you sure you want to change the base?
Changes from 1 commit
2744651
38dbbca
6ad9c1f
5e725ac
26b6c4e
f81afaa
64fcc23
fc0091e
b86d4b4
3cba753
41c7243
d12fa4c
4c44001
addfdbd
e78dec8
f08a371
b3936d0
d888306
3d04b09
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ void main() | |
/*[Fragment]*/ | ||
uniform sampler2D u_ScreenDepthMap; | ||
uniform sampler2D u_ScreenImageMap; | ||
uniform vec4 u_ViewInfo; // zfar / znear, zfar, 0, 0 | ||
uniform vec4 u_ViewInfo; // znear, zfar, 0, 0 | ||
uniform vec2 u_ScreenInfo; // width, height | ||
|
||
in vec2 var_ScreenTex; | ||
|
@@ -24,25 +24,19 @@ out vec4 out_Color; | |
// AO Shader by Monsterovich :D | ||
// | ||
|
||
float zNear = 1.0 / (u_ViewInfo.x / u_ViewInfo.y); | ||
float zFar = u_ViewInfo.y; | ||
vec2 camerarange = vec2(u_ViewInfo.x, u_ViewInfo.y); | ||
|
||
vec2 camerarange = vec2(zNear, zFar); | ||
vec2 screensize = u_ScreenInfo; | ||
vec2 texCoord = var_ScreenTex; | ||
|
||
|
||
float readDepth( in vec2 coord ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can znear and zfar values be passed in as function parameters? I'd like to avoid using global variables unless it's necessary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
return (2.0 * camerarange.x) / (camerarange.y + camerarange.x - texture2D( u_ScreenDepthMap, coord ).x * (camerarange.y - camerarange.x)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All the GLSL shaders in rend2 are compiled with version "GLSL 1.50 Core". This means the
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
} | ||
|
||
void main(void) | ||
{ | ||
float depth = readDepth( texCoord ); | ||
float depth = readDepth( var_ScreenTex ); | ||
float d; | ||
|
||
float pw = 1.0 / screensize.x; | ||
float ph = 1.0 / screensize.y; | ||
float pw = 1.0 / u_ScreenInfo.x; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can avoid having There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think you need
If you really want to continue using |
||
float ph = 1.0 / u_ScreenInfo.y; | ||
|
||
float aoCap = 1.0; | ||
float ao = 0.0; | ||
|
@@ -52,16 +46,16 @@ void main(void) | |
int i; | ||
for (i = 0; i < 4; i++) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only sampling depths sideways and up/down doesn't look very good - it almost looks kind of pixelated. I think this needs to be changed to sampling in directions all around the currently pixel, not just left/up/down/right. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an awful lot of samples now... you're doing 64 samples now. Can you reduce this down to 16 again (like you had before)? |
||
{ | ||
d = readDepth( vec2(texCoord.x+pw,texCoord.y+ph)); | ||
d = readDepth( vec2(var_ScreenTex.x+pw,var_ScreenTex.y+ph)); | ||
ao += min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier); | ||
|
||
d = readDepth( vec2(texCoord.x-pw,texCoord.y+ph)); | ||
d = readDepth( vec2(var_ScreenTex.x-pw,var_ScreenTex.y+ph)); | ||
ao += min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier); | ||
|
||
d = readDepth( vec2(texCoord.x+pw,texCoord.y-ph)); | ||
d = readDepth( vec2(var_ScreenTex.x+pw,var_ScreenTex.y-ph)); | ||
ao += min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier); | ||
|
||
d = readDepth( vec2(texCoord.x-pw,texCoord.y-ph)); | ||
d = readDepth( vec2(var_ScreenTex.x-pw,var_ScreenTex.y-ph)); | ||
ao += min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier); | ||
|
||
pw *= 2.0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By multiplying by 2 you're skipping depth samples in later loops... is that intentional? i.e. you read left/right/up/down going from ±1, ±2, ±4, ±8... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are you multiplying |
||
|
@@ -71,7 +65,7 @@ void main(void) | |
|
||
ao /= 16.0; | ||
|
||
float orig = texture2D(u_ScreenImageMap,texCoord).x; | ||
float orig = texture2D(u_ScreenImageMap,var_ScreenTex).x; | ||
float done = (1.0 - ao) * orig; | ||
out_Color = vec4(done, done, done, 0.0); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems unnecessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.