Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
-1
Question by ravsters · Mar 05, 2013 at 03:49 PM · shaderglsl

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);
  
 }    


Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges