Josh Posted February 16, 2010 Share Posted February 16, 2010 Replace ssao.frag with this. You can adjust the raycasts, raysegments, aoscatter, and raylength values to tweak the appearance and performance: uniform sampler2D texture0; //color uniform sampler2D texture1; //depth uniform sampler2D texture2; //normal uniform sampler2D texture10; //noise texture for effects uniform vec2 buffersize; uniform vec2 camerarange; uniform float aosizereduce; uniform float camerazoom; uniform float bufferaspect; uniform float apptime; uniform mat4 cameramat4; include "depthtozposition.frag" #define aointensity 4.0 // between 1 and 5 is good #define aointensitydiv 2.5 #define aofalloff .35 #define aosamples 8 // dont change #define aopass 4 // 4 * aopass = samples #define aocut 0.6 #define aosize 0.5 #define aoscreenlocked 0 // enable this for screen locked AO float readZPosition(in vec2 texcoord) { return DepthToZPosition( texture2D( texture1, texcoord + 0.25 / buffersize ).x ); } mat3 vec3tomat3( in vec3 z ) { mat3 mat; mat[2]=z; vec3 v=vec3(z.z,z.x,-z.y);//make a random vector that isn't the same as vector z mat[0]=cross(z,v);//cross product is the x axis mat[1]=cross(mat[0],z);//cross product is the y axis return mat; } float compareDepths( in float depth1, in float depth2, in float m ) { //#define mindiff 0.1 //#define middiff 0.6 //#define maxdiff 1.6 //#define enddiff 2.1 float mindiff=0.05*m; float middiff=0.25*m; float maxdiff=1.30*m; float enddiff=1.50*m; float diff = (depth1-depth2); if (diff<mindiff) { return 1.0; } if (diff<middiff) { diff -= mindiff; return 1.0-diff/(middiff-mindiff); } if (diff<maxdiff) { return 0.0; } if (diff<enddiff) { diff -= maxdiff; return diff/(enddiff-maxdiff); } return 1.0; } // Calculates the screen-space position of a pixel // Make sure the depth lookup is using the right texture!!! vec3 GetPixelPosition( in vec2 coord ) { vec3 pos; vec2 hbuffersize=buffersize/2.0; pos.z = DepthToZPosition(texture2D(texture1,coord).x); pos = vec3((((coord.x+0.5)/hbuffersize.x)-0.5) * 2.0,(((-coord.y+0.5)/hbuffersize.y)+0.5) * 2.0 / (hbuffersize.x/hbuffersize.y),pos.z); pos.x *= pos.z / camerazoom; pos.y *= -pos.z / camerazoom; return pos; } vec3 ScreenCoordToPosition( in vec2 coord ) { vec3 pos; vec2 hbuffersize=buffersize/2.0; pos.z = DepthToZPosition(texture2D(texture1,coord).x); pos.x = ((((coord.x+0.5)/hbuffersize.x)-0.5) * 2.0)*(pos.z / camerazoom); pos.y = ((((-coord.y+0.5)/hbuffersize.y)+0.5) * 2.0 / (hbuffersize.x/hbuffersize.y))*(-pos.z / camerazoom); return pos; } vec3 ScreenCoordToPosition2( in vec2 coord, in float z ) { vec3 pos; vec2 hbuffersize=buffersize/2.0; pos.z = z;//DepthToZPosition(texture2D(texture1,coord).x); pos.x = ((((coord.x+0.5)/hbuffersize.x)-0.5) * 2.0)*(pos.z / camerazoom); pos.y = ((((-coord.y+0.5)/hbuffersize.y)+0.5) * 2.0 / (hbuffersize.x/hbuffersize.y))*(-pos.z / camerazoom); return pos; } //Converts a screen position to texture coordinate vec2 ScreenPositionToCoord( in vec3 pos ) { vec2 coord; vec2 hbuffersize=buffersize/2.0; pos.x /= (pos.z / camerazoom); coord.x = (pos.x / 2.0 + 0.5); pos.y /= (-pos.z / camerazoom) / (hbuffersize.x/hbuffersize.y); coord.y = -(pos.y / 2.0 - 0.5); return coord;// + 0.5/(buffersize/2.0); } vec4 PlaneFromPointNormal( in vec3 point, in vec3 normal ) { vec4 plane; plane.x = normal.x; plane.y = normal.y; plane.z = normal.z; plane.w = -dot(point,normal); return plane; } vec3 GetPixelNormal( in vec2 coord ) { return texture2D( texture2, coord ).xyz * 2.0 - 1.0; } vec4 GetPixelPlane( in vec2 coord ) { vec3 point = GetPixelPosition( coord ); vec3 normal = GetPixelNormal( coord ); return PlaneFromPointNormal( point, normal); } float PointPlaneDistance( in vec4 plane, in vec3 point ) { return plane.x*point.x+plane.y*point.y+plane.z*point.z+plane.w; } float rand(vec2 co) { return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); } void main( void ) { float ao=0.0; float dn; float zd; float newdepth; float angletest; float lineardepth; float depth; vec3 newnormal; vec3 newdiffuse; vec3 normal; vec2 texcoord2; vec2 texcoord = gl_FragCoord.xy/buffersize + 0.5/(buffersize*0.5); depth=texture2D( texture1, texcoord ).x; vec3 screencoord; vec4 outcolor; if (depth<1.0) { lineardepth = DepthToZPosition(depth); normal = texture2D( texture2, texcoord ).rgb * 2.0 - 1.0; normal=normalize(normal); normal.z=-normal.z; vec3 p0=ScreenCoordToPosition2(vec2(0.0,0.5),lineardepth); vec3 p1=ScreenCoordToPosition2(vec2(1.0,0.5),lineardepth); float dist = abs(p1.x-p0.x); screencoord = vec3((((gl_FragCoord.x+0.5)/buffersize.x)-0.5) * 2.0,(((-gl_FragCoord.y+0.5)/buffersize.y)+0.5) * 2.0 / (buffersize.x/buffersize.y),lineardepth); screencoord.x *= screencoord.z / camerazoom; screencoord.y *= -screencoord.z / camerazoom; vec3 newpoint; vec2 coord; vec3 raynormal; vec3 offsetvector; float diff; vec2 randcoord; float randsum = cameramat4[0][0]+cameramat4[0][1]+cameramat4[0][2]; randsum+=cameramat4[1][0]+cameramat4[1][1]+cameramat4[1][2]; randsum+=cameramat4[2][0]+cameramat4[2][1]+cameramat4[2][2]; randsum+=cameramat4[3][0]+cameramat4[3][1]+cameramat4[3][2]; #define raycasts 4//Increase for better quality #define raysegments 6//Increase for better quality #define aoscatter 1.0 float raylength = 0.5;//*dist*1.0*50.0; float cdm = 1.0;// * dist * 50.0; ao=0.0; vec4 gicolor; float gisamples; mat3 mat=vec3tomat3(normal); float a; float wheredepthshouldbe; float mix=(1.0-(clamp(lineardepth-50.0,0.0,50.0)/50.0)); //Get a random number a=rand( randsum+texcoord);// + float(53.0*m*raysegments + i*13.0) ); if (mix>0.0) { for ( int i=0;i<(raycasts);i++ ) { for ( int m=0;m<(raysegments);m++ ) { offsetvector.x=cos(a+float(i)/float(raycasts)*3.14*4.0)*aoscatter; offsetvector.y=sin(a+float(i)/float(raycasts)*3.14*4.0)*aoscatter; offsetvector.z=1.0; offsetvector=normalize(offsetvector); //Create the ray vector raynormal=mat*offsetvector; //Add the ray vector to the screen position newpoint = screencoord + raynormal * (raylength/raysegments) * float(m+1); wheredepthshouldbe=newpoint.z; //Turn the point back into a screen coord: coord = ScreenPositionToCoord( newpoint ); //Look up the depth value at that rays position newdepth = readZPosition( coord ); //If new depth is closer to camera darken ao value //rayao = max(rayao,compareDepths( lineardepth, newdepth )); //ao = min(ao,compareDepths( lineardepth, newdepth )); ao += compareDepths( wheredepthshouldbe,newdepth, cdm ); //ao+=compareDepths( lineardepth, newdepth ); } } } ao /= (raycasts*raysegments); //ao = max(ao * ao,0.5); ao = ao * mix + (1.0-mix); gl_FragColor=vec4(ao); } else { gl_FragColor=vec4(1.0); } } Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Niosop Posted February 16, 2010 Share Posted February 16, 2010 Seems like it adds a shine or glow around the edges of objects. I hadn't tried tweaking the values yet. Quote Windows 7 x64 - Q6700 @ 2.66GHz - 4GB RAM - 8800 GTX ZBrush - Blender Link to comment Share on other sites More sharing options...
Michael Betke Posted February 16, 2010 Share Posted February 16, 2010 Hmm I see mto make something wrong and its hard to see a difference. The effect looks a bit grainy and even if I change to rediculous settings it doesn't change like this #define aointensity 8.0 // between 1 and 5 is good #define aointensitydiv 5 #define aofalloff .1 #define aosamples 8 // dont change #define aopass 8 // 4 * aopass = samples #define aocut 2 #define aosize 5 #define aoscreenlocked 0 // enable this for screen locked AO (dont use) I opened the ssao.frag in shaders.pak and replaced the content (after doing a backup). then i updated the .pak....dont know Quote Pure3d Visualizations Germany - digital essences AAA 3D Model Shop specialized on nature and environments Link to comment Share on other sites More sharing options...
Josh Posted February 16, 2010 Author Share Posted February 16, 2010 The code does not need to be fixed in any way. It works the way it is supposed to. This is what it looks like. It's very similar to the SSDO effect in STALKER: Call of Pripyat: Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Marcus Posted February 16, 2010 Share Posted February 16, 2010 Small improvement maybe, but still looks very flat in shadows. Quote Link to comment Share on other sites More sharing options...
Niosop Posted February 16, 2010 Share Posted February 16, 2010 I have some animated models moving around. The SSDO induced darkening doesn't update when they move, effectively baking the SSDO effect onto other objects/terrain. Hmm, might be something else, just returned to the original shader and it's still doing it. Quote Windows 7 x64 - Q6700 @ 2.66GHz - 4GB RAM - 8800 GTX ZBrush - Blender Link to comment Share on other sites More sharing options...
L B Posted February 17, 2010 Share Posted February 17, 2010 On-object darkening seems to only work when they're selected in the editor. Else, it's just around it. I don't know if that's intentional, but I think it would be 10 times better with on-object darkening. Quote Link to comment Share on other sites More sharing options...
Josh Posted February 17, 2010 Author Share Posted February 17, 2010 Turn down the ambient light level so the effect shows up more. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Jordan Posted February 17, 2010 Share Posted February 17, 2010 Just tried this out and it looks great. Although sometimes there appears to be a white line around part of an object. You'll have to view the image full size to see it, it's on the left side of the oil drum. Quote Link to comment Share on other sites More sharing options...
Niosop Posted February 17, 2010 Share Posted February 17, 2010 Yeah, I get the same effect. I think it's the background showing through, so it appears white in that scene. I think it's that the different raycasts miss that little area so it doesn't draw any occlusion information right along the edge so the unshaded background shows through. Quote Windows 7 x64 - Q6700 @ 2.66GHz - 4GB RAM - 8800 GTX ZBrush - Blender Link to comment Share on other sites More sharing options...
BrokenPillar Posted February 17, 2010 Share Posted February 17, 2010 I tried it out too and think it is a huge improvement over the previous SSAO. Hmm I see mto make something wrong and its hard to see a difference. The effect looks a bit grainy and even if I change to rediculous settings it doesn't change like this #define aointensity 4.0 // between 1 and 5 is good #define aointensitydiv 2.5 #define aofalloff .35 #define aosamples 8 // dont change #define aopass 4 // 4 * aopass = samples #define aocut 0.6 #define aosize 0.5 #define aoscreenlocked 0 // enable this for screen locked AO Michael, it looks to me like you are making adjustments in the wrong section of code. I think the section to change settings to get better quality is this section: #define raycasts 4//Increase for better quality #define raysegments 6//Increase for better quality #define aoscatter 1.0 float raylength = 0.5;//*dist*1.0*50.0; float cdm = 1.0;// * dist * 50.0; Is that right Josh? I can get better results by changing those values, although it is really easy to get beyond the capabilities of my computer (which I would expect when playing with things like number of ray casts). Base on my initial testing, it seemed that reducing the aoscatter value seemed to help with the graininess with the least amount of impact on performance. I do see the slim white line around objects sometimes. It appears to be where the edge of an object meets the SSAO shadows. I am guessing this is where the shader is trying to figure out where to start occluding the effect so that it doesn't lay on top of the object, right? So basically you are seeing SSAO shadow being cast on the ground/wall, then a pixel width of no SSAO shadow where it starts occluding the effect to not lay on top of the barrel. I think this would give the appearance of a glow or white line. Quote Vista | AMD Dual Core 2.49 GHz | 4GB RAM | nVidia GeForce 8800GTX 768MB Online Portfolio | www.brianmcnett.com Link to comment Share on other sites More sharing options...
Josh Posted February 17, 2010 Author Share Posted February 17, 2010 These are the values to edit: #define raycasts 4//Increase for better quality #define raysegments 6//Increase for better quality #define aoscatter 1.0 float raylength = 0.5;//*dist*1.0*50.0; The edge artifact is probably due to the half-size buffer that is used for rendering the effect. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Marleys Ghost Posted February 20, 2010 Share Posted February 20, 2010 It seems kind of "fizzy"? not sure if its supposed to be lol or just me, possibly from the curve on the camera look values.. Not sure I'd use it in an FPS though.. Will SSAO and SSDO be available eventually individually in Framework (i.e SetSSAO() and SetSSDO() ) or will it be a case of re-writing the ssao.frag ? Quote AMD Bulldozer FX-4 Quad Core 4100 Black Edition 2 x 4GB DDR3 1333Mhz Memory Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5 Windows 7 Home 64 bit BlitzMax 1.50 • Lua 5.1 • MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro 3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET LE 2.5/3.4 • Skyline • UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0 Marleys Ghost's YouTube Channel • Marleys Ghost's Blog "I used to be alive like you .... then I took an arrow to the head" Link to comment Share on other sites More sharing options...
Michael Betke Posted February 20, 2010 Share Posted February 20, 2010 I have no idea why you guys have such a spreading effect. Mine fades off after 2 centimeters... I had no time to look into this but it seems to be different hehe. Quote Pure3d Visualizations Germany - digital essences AAA 3D Model Shop specialized on nature and environments Link to comment Share on other sites More sharing options...
Marleys Ghost Posted February 20, 2010 Share Posted February 20, 2010 maybe its a movement thing? Quote AMD Bulldozer FX-4 Quad Core 4100 Black Edition 2 x 4GB DDR3 1333Mhz Memory Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5 Windows 7 Home 64 bit BlitzMax 1.50 • Lua 5.1 • MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro 3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET LE 2.5/3.4 • Skyline • UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0 Marleys Ghost's YouTube Channel • Marleys Ghost's Blog "I used to be alive like you .... then I took an arrow to the head" Link to comment Share on other sites More sharing options...
Michael Betke Posted February 21, 2010 Share Posted February 21, 2010 It diesnt matter how I move around the object. Effects stays teh same. I'll take alook at the .frag later. Quote Pure3d Visualizations Germany - digital essences AAA 3D Model Shop specialized on nature and environments Link to comment Share on other sites More sharing options...
Marleys Ghost Posted February 21, 2010 Share Posted February 21, 2010 What surfaces have you tried it on? other than dirty/mossy/speckled rocks and things? Quote AMD Bulldozer FX-4 Quad Core 4100 Black Edition 2 x 4GB DDR3 1333Mhz Memory Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5 Windows 7 Home 64 bit BlitzMax 1.50 • Lua 5.1 • MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro 3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET LE 2.5/3.4 • Skyline • UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0 Marleys Ghost's YouTube Channel • Marleys Ghost's Blog "I used to be alive like you .... then I took an arrow to the head" Link to comment Share on other sites More sharing options...
Michael Betke Posted February 21, 2010 Share Posted February 21, 2010 An untextured building for example too. Only the edges are visible. Looks a bit like a dirt-shader from finalrender stage 1. Well it's not on top of my to-do list at the moment since I have a to finish some stuff. Quote Pure3d Visualizations Germany - digital essences AAA 3D Model Shop specialized on nature and environments Link to comment Share on other sites More sharing options...
Marleys Ghost Posted February 21, 2010 Share Posted February 21, 2010 Well it's not on top of my to-do list at the moment since I have a to finish some stuff. Was not expecting you to do anythng Michael was only wondering if you had used Josh's shader on anything other than organic objects/scenes and rocks? Quote AMD Bulldozer FX-4 Quad Core 4100 Black Edition 2 x 4GB DDR3 1333Mhz Memory Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5 Windows 7 Home 64 bit BlitzMax 1.50 • Lua 5.1 • MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro 3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET LE 2.5/3.4 • Skyline • UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0 Marleys Ghost's YouTube Channel • Marleys Ghost's Blog "I used to be alive like you .... then I took an arrow to the head" Link to comment Share on other sites More sharing options...
L B Posted February 23, 2010 Share Posted February 23, 2010 @Michael Betke: You seem to be on the old SSAO. Quote Link to comment Share on other sites More sharing options...
Michael Betke Posted February 23, 2010 Share Posted February 23, 2010 Lol you were right Ubu. Thanks a lot. Pasted the shader into the file and it works. I also get the "nice" white halo around me models. I also wonder about that...maybe Josh forgot to update the shader.pak - I after he told us to and even the shader.pak was updated but the ssdo.frag was the old one.... Quote Pure3d Visualizations Germany - digital essences AAA 3D Model Shop specialized on nature and environments Link to comment Share on other sites More sharing options...
Pancakes Posted March 31, 2010 Share Posted March 31, 2010 Does anyone have any tips on how to get the SSDO filter to look better? Right now it looks very harsh and could use some softening or an increase in resolution (sorry I don't understand how it works). But I do know that it has a similiar look to the artifacts that occur when you set the resolution of a light source's shadow map too low. Quote Core I5 2.67 / 16GB RAM / GTX 670 Zbrush/ Blender / Photoshop CS6 / Renoise / Genetica / Leadwerks 3 Link to comment Share on other sites More sharing options...
macklebee Posted March 31, 2010 Share Posted March 31, 2010 http://leadwerks.com/werkspace/index.php?/topic/1228-ssdo-filter/page__view__findpost__p__11438 Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Michael Betke Posted March 31, 2010 Share Posted March 31, 2010 In the comments of Joshs Blog we came to the conclusion that a slight blur filter over the SSDO effect would soften the effect in a good performance way. I adjusted the Quality settings and fps get down noticeable. So doing a blur would be better but I dont know how to do this. Quote Pure3d Visualizations Germany - digital essences AAA 3D Model Shop specialized on nature and environments Link to comment Share on other sites More sharing options...
Pancakes Posted April 1, 2010 Share Posted April 1, 2010 In the comments of Joshs Blog we came to the conclusion that a slight blur filter over the SSDO effect would soften the effect in a good performance way. I adjusted the Quality settings and fps get down noticeable. So doing a blur would be better but I dont know how to do this. I was playing around with it tonight. Hopefully he'll add blur in there for us =) But I do have to say that SSDO is amazing. It changes everything about lighting a scene. For instance I remember with no SSAO or with the previous implementation that having the directional light at 90 degrees, shining down on the surface could make vegetation look plasticy or at least my vegetation But now the dlight looks GREAT from any angle and it's all because of how SSDO shades the vegetation, grass and shrubs in particular. There is no longer any need to give grass shadows, because the SSDO handles that. It's really great. But yes, a blur would be nice so that I could relax the quality settings just a little bit. Because right now, it looks really good my frame rate has dropped about 10 from about 35 in my scene to about 25. But the effect is really nice. Blur could have it even better i think. Quote Core I5 2.67 / 16GB RAM / GTX 670 Zbrush/ Blender / Photoshop CS6 / Renoise / Genetica / Leadwerks 3 Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.