niv3k Posted January 6, 2012 Share Posted January 6, 2012 okay...well i've been messing around with this shader and for some reason it doesnt allow it to work on everything like a few feet away...and then there is a stupid line that basically i'm guessing is the distance of how far the shader works...so anyone know how to make it fill up the whole screen...? // Variables to play with float fNormalStrengthDivider = 8.0; // The higher the value the less obvious are the normal features int iNormalIterations = 12; // Set this to 4, 6 or 12, higher means higher quality and less performance float fDepthTolerance = 1.0; // Scan radius for outlines -> higher value, thicker lines (very sensitive) float fNormalTolerance = 1.0; // Scan radius for normals -> higher value, less small features (very sensitive) // Don't change these float fEdgeDepth = 0.0; float fEdgeNormal = 0.0; int iNormalIterationsInternal = 12 / iNormalIterations; // Calculate the depth difference between the current pixel and 4 surrounding ones. // You can adjust the radius with fDepthTolerance. Higher value means thicker lines. (Tested between 0.5 and 3.0) float fCurrent = DepthToZPosition(texture2D(texture1, texcoord).x); float fRight = DepthToZPosition(texture2D(texture1, texcoord + vec2(pixelsize.x * fDepthTolerance, 0.0)).x); float fAbove = DepthToZPosition(texture2D(texture1, texcoord + vec2(0.0, -pixelsize.y * fDepthTolerance)).x); float fLeft = DepthToZPosition(texture2D(texture1, texcoord + vec2(-pixelsize.x * fDepthTolerance, 0.0)).x); float fBelow = DepthToZPosition(texture2D(texture1, texcoord + vec2(0.0, pixelsize.y * fDepthTolerance)).x); float fDDX = abs((fRight - fCurrent) - (fCurrent - fLeft)); float fDDY = abs((fAbove - fCurrent) - (fCurrent - fBelow)); if(fCurrent<=0.5){ fEdgeDepth = clamp((fDDX + fDDY - 0.001) * 10.0, 0.0, 1.0); } else if(fCurrent>0.5 && fCurrent<=5.0){ fEdgeDepth = clamp((fDDX + fDDY - 0.02) * 10.0, 0.0, 1.0); } else if(fCurrent>5.0 && fCurrent<=9.0){ fEdgeDepth = clamp((fDDX + fDDY - 5.0) * 10.0, 0.0, 1.0); } else if(fCurrent>12 && fCurrent<=15.0){ fEdgeDepth = clamp((fDDX + fDDY - 7.0) * 10.0, 0.0, 1.0); } else if(fCurrent>25 && fCurrent<=28.0){ fEdgeDepth = clamp((fDDX + fDDY - 12.0) * 10.0, 0.0, 1.0); } else { fEdgeDepth = clamp((fDDX + fDDY - 20.0) * 10.0, 0.0, 1.0); } outputcolor -= vec4(fEdgeDepth, fEdgeDepth, fEdgeDepth, fEdgeDepth); vec2 av2PoissonPoint[12]; av2PoissonPoint[0] = vec2(-0.326212, -0.40581); av2PoissonPoint[1] = vec2(-0.840144, -0.07358); av2PoissonPoint[2] = vec2(-0.695914, 0.457137); av2PoissonPoint[3] = vec2(-0.203345, 0.620716); av2PoissonPoint[4] = vec2( 0.96234, -0.194983); av2PoissonPoint[5] = vec2( 0.473434, -0.480026); av2PoissonPoint[6] = vec2( 0.519456, 0.767022); av2PoissonPoint[7] = vec2( 0.185461, -0.893124); av2PoissonPoint[8] = vec2( 0.507431, 0.064425); av2PoissonPoint[9] = vec2( 0.89642, 0.412458); av2PoissonPoint[10] = vec2(-0.32194, -0.932615); av2PoissonPoint[11] = vec2(-0.791559, -0.59771); // Calculate the "dirt", that means color all areas with normals that point towards the camera. fCurrent = dot(vec3(0.0, 0.0, 1.0), (texture2D(texture2, texcoord).xyz * 2.0) - 1.0); fRight = dot(vec3(0.0, 0.0, 1.0), (texture2D(texture2, texcoord + vec2(pixelsize.x * fNormalTolerance, 0.0)).xyz * 2.0) - 1.0); fAbove = dot(vec3(0.0, 0.0, 1.0), (texture2D(texture2, texcoord + vec2(0.0, -pixelsize.y * fNormalTolerance)).xyz * 2.0) - 1.0); fLeft = dot(vec3(0.0, 0.0, 1.0), (texture2D(texture2, texcoord + vec2(-pixelsize.x * fNormalTolerance, 0.0)).xyz * 2.0) - 1.0); fBelow = dot(vec3(0.0, 0.0, 1.0), (texture2D(texture2, texcoord + vec2(0.0, pixelsize.y * fNormalTolerance)).xyz * 2.0) - 1.0); float fNDX = abs ((fRight - fCurrent) - (fCurrent - fLeft)); float fNDY = abs ((fAbove - fCurrent) - (fCurrent - fBelow)); fEdgeNormal = clamp((fNDX + fNDY - 0.01) * 10.0, 0.0, 1.0); for (int i = 0; i < 12; i += iNormalIterationsInternal) { vec2 v2Offset = (pixelsize * av2PoissonPoint[i] * fNormalTolerance); fCurrent = dot(vec3(0.0, 0.0, 1.0), (texture2D(texture2, texcoord + v2Offset).xyz * 2.0) - 1.0); fRight = dot(vec3(0.0, 0.0, 1.0), (texture2D(texture2, texcoord + v2Offset+ vec2(pixelsize.x * fNormalTolerance, 0.0)).xyz * 2.0) - 1.0); fAbove = dot(vec3(0.0, 0.0, 1.0), (texture2D(texture2, texcoord + v2Offset+ vec2(0.0, -pixelsize.y * fNormalTolerance)).xyz * 2.0) - 1.0); fLeft = dot(vec3(0.0, 0.0, 1.0), (texture2D(texture2, texcoord + v2Offset+ vec2(-pixelsize.x * fNormalTolerance, 0.0)).xyz * 2.0) - 1.0); fBelow = dot(vec3(0.0, 0.0, 1.0), (texture2D(texture2, texcoord + v2Offset+ vec2(0.0, pixelsize.y * fNormalTolerance)).xyz * 2.0) - 1.0); fNDX = abs((fRight - fCurrent) - (fCurrent - fLeft)); fNDY = abs((fAbove - fCurrent) - (fCurrent - fBelow)); fEdgeNormal += clamp((fNDX + fNDY - 0.01) * 10.0, 0.0, 1.0); } fEdgeNormal = clamp(fEdgeNormal / (1 + iNormalIterationsInternal), 0.0, 1.0); fEdgeNormal /= fNormalStrengthDivider; fEdgeNormal *= (1.0 - pixelbrightness); outputcolor -= vec4(fEdgeNormal, fEdgeNormal, fEdgeNormal, fEdgeNormal); Quote Link to comment Share on other sites More sharing options...
Road Kill Kenny Posted January 6, 2012 Share Posted January 6, 2012 Hi Kevin, You need to play around with the distance values (fCurrent) in this section and the negative values following fDDY to get it right for your scene. if(fCurrent<=0.5){ fEdgeDepth = clamp((fDDX + fDDY - 0.001) * 10.0, 0.0, 1.0); } else if(fCurrent>0.5 && fCurrent<=5.0){ fEdgeDepth = clamp((fDDX + fDDY - 0.02) * 10.0, 0.0, 1.0); } else if(fCurrent>5.0 && fCurrent<=9.0){ fEdgeDepth = clamp((fDDX + fDDY - 5.0) * 10.0, 0.0, 1.0); } else if(fCurrent>12 && fCurrent<=15.0){ fEdgeDepth = clamp((fDDX + fDDY - 7.0) * 10.0, 0.0, 1.0); } else if(fCurrent>25 && fCurrent<=28.0){ fEdgeDepth = clamp((fDDX + fDDY - 12.0) * 10.0, 0.0, 1.0); } else { fEdgeDepth = clamp((fDDX + fDDY - 20.0) * 10.0, 0.0, 1.0); } Generally when you use a comic shader you want to use assets that compliment it. Grass is not the best type of thing to use with a comic shader and tree's not so much either. You may notice the lack of trees in games like borderlands. As comic shaders generally simplify the look in an artistic way you sort of have to simplify your scene a bit to suit. Ideally you don't want the comic shader to work on the grass because it is too detailed but this shader applies the comic look to everything. I'd imagine you'd need a material shader for something like mesh_diffuse_bumpmap_specular_comic.frag .... or something like that. However this shader applies the effect to everything. I'm not a shader programmer so I'm not sure how to do that. Concerning the big line in the distance. All you have to do is make your horizon 'non-flat'. I can't imagine that you would make a game with a flat environment anyway. This should avoid the line. playing with the numbers above as I said will help with too. Quote STS - Scarlet Thread Studios AKA: Engineer Ken Fact: Game Development is hard... very bloody hard.. If you are not prepared to accept that.. Please give up now! Link to comment Share on other sites More sharing options...
niv3k Posted January 7, 2012 Author Share Posted January 7, 2012 I wasn't talking about the horizon. Quote Link to comment Share on other sites More sharing options...
DaDonik Posted January 7, 2012 Share Posted January 7, 2012 Ok, so Ken already said most of what i could say, but i can add at least one more thing. Since the shader is highly dependent on the depth buffer, you can increase the near camera range to get a better effect. I really only tested the shader in indoor environments, because it's in the nature of the depth buffer, that it looses detail with distance. So pretty much all you can do is adjust the near camera range in order to get a better effect or try tuning the values like Ken said. Edit: Decreasing the far camera range also has an effect on the shader. I recommend playing around with it =) Quote (Win7 64bit) && (i7 3770K @ 3,5ghz) && (16gb DDR3 @ 1600mhz) && (Geforce660TI) Link to comment Share on other sites More sharing options...
Road Kill Kenny Posted January 7, 2012 Share Posted January 7, 2012 I wasn't talking about the horizon. I say the exact same thing as my last post..... I know thats what you were talking about. I thought you meant the horizon as well. If you want you can add more if statements in that to smooth out that transition. Ultimately it is inevitable but you can smooth it out.. Quote STS - Scarlet Thread Studios AKA: Engineer Ken Fact: Game Development is hard... very bloody hard.. If you are not prepared to accept that.. Please give up now! Link to comment Share on other sites More sharing options...
niv3k Posted January 8, 2012 Author Share Posted January 8, 2012 thanks. Quote 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.