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
0
Question by chrishawkinsnz · Sep 04, 2014 at 11:02 AM · shaderglslhair

Is it Possible to Have an Arbitrary Number of Passes in GLSL shader

I am trying to write a fur shader using GLSL. I'm a total newbie to shaders but it's going pretty well so far.

alt text

I achieve through a multi pass shader where each pass shifts the vertex shader out along the surface normal (also droops with gravity)

Unfortunately the way I have it at the moment is my shader has 20 nearly identical shader passes written (with the only difference being some "extrustion" value increasing for each pass) in one file. This makes my shader pretty frustrating to change as any change to my shader require changing lines in every single pass.

Is there a way to have an arbitrary number of passes.

What I would love is something like

 for(int extrustion=0.0f;extrusion<1.0;extrusion+=0.1){
     Pass{
         shader code...
     }
 }

Is there some kind of equivelant to this or am is this really not how shaders should be used.

Incase it's relevant here is one pass of my shader code

   Pass {
      Cull back 
      ZWrite off 
      Blend SrcAlpha OneMinusSrcAlpha 
 
      GLSLPROGRAM

      uniform sampler2D _MainTex;    
      uniform vec4 _MainTex_ST; 
 

      uniform float _minAlpha;
      uniform float _maxAlpha;

      uniform float _spikiness;
      uniform float _extrusionDist;
      uniform vec4 _Time;
      varying vec4 textureCoordinates; 
      float extrusion=0.05 ;

 
      #ifdef VERTEX
 
      void main()
      {
      
         textureCoordinates = gl_MultiTexCoord0;
         
         vec4 displacedVert = gl_Vertex;
         
         //adjust for gravity (squared based on exstrusion so hair droops)
         displacedVert.y -=extrusion*extrusion*0.04*_spikiness;

         //sway with "wind"
         float breeziness = 0.5;
         float num = sin(_Time.z*2.0+displacedVert.x*2.0)+0.7;
         if(num>1.0){
             num = 1.0;
         }
         displacedVert.x-=num*extrusion*0.02*breeziness;
         
         //move vertex along surface normal
         vec4 norm4 = vec4(gl_Normal,0.0);
         float totalExtrusion = _extrusionDist*extrusion;
         displacedVert+=norm4*totalExtrusion;
         
         gl_Position = gl_ModelViewProjectionMatrix * displacedVert;
      }
 
      #endif
 
      #ifdef FRAGMENT
 
      void main()
      {
                   
          float cutoff = 0.1;
          
          //get color from teture
          vec2 newTexCo = vec2(textureCoordinates);
          vec4 newCol = texture2D(_MainTex, newTexCo);
          newCol=texture2D(_MainTex, 
            _MainTex_ST.xy * textureCoordinates.xy 
            + _MainTex_ST.zw);
         
         //darken if closer to base
          float factor=0.5;
          newCol.r = factor*newCol.r+factor*extrusion*newCol.r;
          newCol.g = factor*newCol.g+factor*extrusion*newCol.g;
          newCol.b = factor*newCol.b+factor*extrusion*newCol.b;
          
         //make more transparent along hair
         float alphaness = extrusion*(_maxAlpha-_minAlpha);
         if(newCol.a>cutoff){
             newCol.a =newCol.a+alphaness;
         }
         gl_FragColor = newCol;
        
      }
 
      #endif
 
      ENDGLSL
   }


Thanks in advance for any advice

furryface.jpg (146.1 kB)
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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Fur, Hair, and Alternative Grass 2 Answers

Curly hair from straight mesh(a long horizontally devided strip). 1 Answer

"Unsupported" shader showing in log, but it still works fine? 0 Answers

Uniform variable fails on the android 0 Answers

Can a GLSL shader fetch GameObject properties? 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