- Home /
Shader problems! GLSL Questions!
Hey everyone! So I have yet another question about shaders. Go figure! -__-
Anyways, this time, I was able to find a pretty slick looking shader online, which I was going to edit. The shader and page can be found here. Its pretty AWESOME! If someone can get this shader working in Unity (pro OR free.. I doubt it will work in free. Lol), OH MAN!
SO! I have the shader, but when I put it into Unity it doesn't work. Am I missing something? I don't need someone to rewrite it for me or anything, I just need some help. I do want to learn how to do these things as well. I also wanted to know if GLSL works in Unity. I have the shader below.
uniform sampler2D ColorPass;
uniform sampler2D BrushPass;
uniform sampler2D DepthPass;
varying vec2 vTexCoord;
uniform float mode;
void main (void)
{
vec3 brushValue;
vec3 bTex = texture2D(BrushPass, vTexCoord).rgb;
//Depth Values for current pixel and distored pixel
//---------------------------------------------------------------------------------------------------
float d_mag = 0.005; //Magnitude of distortion
//Apply 1.0 - smoothstep to depth values to map them to the visible 0-1 range
//this is a fast and simple way to remap the depth buffer values
//Get the depth value of the current pixel we're shading
float depthVal = 1.0 - smoothstep( 0.998, 1.0, texture2D(DepthPass, vTexCoord).x);
//Get the depth values of the neighbouring pixels in an x
float depthVal_offset1 = 1.0 - smoothstep( 0.998, 1.0, texture2D(DepthPass, vTexCoord + vec2( -d_mag, -d_mag)).x);
float depthVal_offset2 = 1.0 - smoothstep( 0.998, 1.0, texture2D(DepthPass, vTexCoord + vec2( d_mag, -d_mag)).x);
float depthVal_offset3 = 1.0 - smoothstep( 0.998, 1.0, texture2D(DepthPass, vTexCoord + vec2( -d_mag, d_mag)).x);
float depthVal_offset4 = 1.0 - smoothstep( 0.998, 1.0, texture2D(DepthPass, vTexCoord + vec2( d_mag, d_mag)).x);
//Find the difference between the neighbours' depth and our current pixel's depth
float d_diff1 = depthVal_offset1 - depthVal;
float d_diff2 = depthVal_offset2 - depthVal;
float d_diff3 = depthVal_offset3 - depthVal;
float d_diff4 = depthVal_offset4 - depthVal;
//Find the maximum difference
float depthMax = max( max( max( depthVal_offset4, depthVal_offset3 ), depthVal_offset2 ), depthVal_offset1 );
vec3 color_offset;
//Smudge more if object is distant, like DOF but painterly
d_mag = 0.008*(1.0-1.5*depthVal);
//Which neighbour has the maximum depth difference,
//get the color value from the opposite direction , and smudge
//multiply the distort vector by the brush texture to get the paint bands.
if ( depthVal_offset4 == depthMax )
{
brushValue = texture2D(BrushPass, vTexCoord - vec2(-d_mag,-d_mag) ).rgb;
color_offset = texture2D(ColorPass, vTexCoord + (-0.5+brushValue.r)*vec2( -d_mag, -d_mag)).rgb;
}
else if ( depthVal_offset3 == depthMax )
{
brushValue = texture2D(BrushPass, vTexCoord - vec2( d_mag,-d_mag) ).rgb;
color_offset = texture2D(ColorPass, vTexCoord + (-0.5+brushValue.r)*vec2( d_mag, -d_mag)).rgb;
}
else if ( depthVal_offset2 == depthMax )
{
brushValue = texture2D(BrushPass, vTexCoord - vec2( -d_mag, d_mag) ).rgb;
color_offset = texture2D(ColorPass, vTexCoord + (-0.5+brushValue.r)*vec2( -d_mag, d_mag)).rgb;
}
else if ( depthVal_offset1 == depthMax )
{
brushValue = texture2D(BrushPass, vTexCoord - vec2( d_mag, d_mag) ).rgb;
color_offset = texture2D(ColorPass, vTexCoord + (-0.5+brushValue.r)*vec2( d_mag, d_mag)).rgb;
}
//Bump ----------------------------------------------------------------------
vec3 myLight = vec3(0.35,0.659,0.47);
float bumpValue = 1.8*dot( myLight, vec3( bTex.r, bTex.r, bTex.r ) );
bumpValue = clamp( bumpValue, 0.5, 1.0 );
//------------------------------------------------------------------------------
//Vignette --------------------------------------------------------------------
float dist = distance(vTexCoord.xy, vec2(0.5,0.5));
float a = smoothstep(0.9, 0.1, dist);
float b = 0.4 *a;
//------------------------------------------------------------------------------
// Color Correction--Levelling ----------------------------------------------
float mr = smoothstep( 0.0, (0.95), color_offset.r );
float mg = smoothstep( 0.0, (0.95), color_offset.g );
float mb = smoothstep( 0.0, (0.95), color_offset.b );
//------------------------------------------------------------------------------
vec4 FinalResult = vec4( a*(vec3(mr,mg,mb) - (0.1*bumpValue) + 0.05*vec3(bTex.r,bTex.r,bTex.r) ), (1.0-bTex.g));
if ( mode == 1 ) //Normal Rendering
gl_FragColor = FinalResult;
if ( mode == 2 ) //Dimmed for menus
gl_FragColor = vec4( 0.4*vec3(FinalResult.r , FinalResult.g, FinalResult.b), 1.0);
if ( mode == 3 ) //Red-ish for loosing health
gl_FragColor = vec4( FinalResult.r , FinalResult.g*0.25, FinalResult.b*0.25, 1.0);
}
Your answer
Follow this Question
Related Questions
Cg Language incompatibility Desktop VS GLSL Android 0 Answers
how to make special effects by joint or other ways ???!!!!! 0 Answers
Hatching Shader? 0 Answers
Grabpass refraction masking 0 Answers
How to prevent shader optimizations? 1 Answer