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 wolga2 · Oct 18, 2013 at 08:54 PM · colortransparentvertexshader

Transparent Vertex Shader blend with color?

How could I make this shader to blend with the color i declared in the properties?

 Shader "AShader" {
 Properties {
     _Color ("Main Color", Color) = (1,1,1,1)
     _MainTex ("Base (RGB) Alpha (A)", 2D) = "white" {}
     _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
 }
 
 SubShader {
     Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "LightMode"="ForwardBase"}
     LOD 100
     Cull Off
     ZWrite Off
     Blend SrcAlpha OneMinusSrcAlpha 
     
     
     CGINCLUDE
     #include "UnityCG.cginc"
     sampler2D _MainTex;
     half4 _MainTex_ST;
     
     float4 _GrassWind; //is not defined in terrainengine.cginc
 
     struct v2f {
         float4 pos : SV_POSITION;
         float2 uv : TEXCOORD0;
     };
 
 inline float4 AnimateGrass(float4 pos, float3 normal, float animParams)
 {    
     pos.xyz += animParams * _GrassWind.xyz * _GrassWind.w; // controlled by vertex color blue
     return pos;
 }
     
     v2f vert (appdata_full v)
     {
         v2f o;
         float4    windParams    = float(v.color.b);        
 
         float4 mdlPos = AnimateGrass(v.vertex, v.normal, windParams);
         o.pos = mul(UNITY_MATRIX_MVP,mdlPos);
         o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
         return o;
     }
     ENDCG
 
     Pass {
         CGPROGRAM
         #pragma debug
         #pragma vertex vert
         #pragma fragment frag
         #pragma fragmentoption ARB_precision_hint_fastest        
         fixed4 frag (v2f i) : COLOR
         {
             fixed4 tex = tex2D (_MainTex, i.uv);
             
             fixed4 c;
             c.rgb = tex.rgb;
             c.a = tex.a;
             
             return c;
         }
         ENDCG 
     }    
 }
 }
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by thellama · Oct 18, 2013 at 09:24 PM

Like this?

 Shader "AShader" {
 Properties {
     _Color ("Main Color", Color) = (1,1,1,1)
     _MainTex ("Base (RGB) Alpha (A)", 2D) = "white" {}
     _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
 }
  
 SubShader {
     Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "LightMode"="ForwardBase"}
     LOD 100
     Cull Off
     ZWrite Off
     Blend SrcAlpha OneMinusSrcAlpha 
  
  
     CGINCLUDE
     #include "UnityCG.cginc"
     sampler2D _MainTex;
     half4 _MainTex_ST;
     half4 _Color;
  
     float4 _GrassWind; //is not defined in terrainengine.cginc
  
     struct v2f {
        float4 pos : SV_POSITION;
        float2 uv : TEXCOORD0;
     };
  
 inline float4 AnimateGrass(float4 pos, float3 normal, float animParams)
 {   
     pos.xyz += animParams * _GrassWind.xyz * _GrassWind.w; // controlled by vertex color blue
     return pos;
 }
  
     v2f vert (appdata_full v)
     {
        v2f o;
        float4    windParams = float(v.color.b);     
  
        float4 mdlPos = AnimateGrass(v.vertex, v.normal, windParams);
        o.pos = mul(UNITY_MATRIX_MVP,mdlPos);
        o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
        return o;
     }
     ENDCG
  
     Pass {
        CGPROGRAM
        #pragma debug
        #pragma vertex vert
        #pragma fragment frag
        #pragma fragmentoption ARB_precision_hint_fastest     
        fixed4 frag (v2f i) : COLOR
        {
          fixed4 tex = tex2D (_MainTex, i.uv);
  
          fixed4 c;
          c.rgb = tex.rgb;
          c.a = tex.a;
  
          return c * _Color;
        }
        ENDCG 
     }  
 }
 }

You have to declare the color like this:

     sampler2D _MainTex;
     half4 _MainTex_ST;
     half4 _Color; // see the color added to these lines.

Then you can just multiply the output color with the color you want it blended with:

 return c * _Color;
Comment
Add comment · Show 1 · Share
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
avatar image wolga2 · Oct 18, 2013 at 09:45 PM 1
Share

that was exactly, what i was looking for. thank you so much!! :)

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

15 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

How to make a gameObject's color fade to transparency (picture) 3 Answers

Key out / Remove a color in a specific area 0 Answers

Transparent Shader changing color after Ambient Light 0 Answers

How do I make a grey cube transparent? 1 Answer

Why Shuriken "Color Over Lifetime" doesn't affect transparent materials? 2 Answers


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