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 chilunliu · Feb 22, 2014 at 03:50 PM · shadercgblending

shader blending 2 texture script

Hi all;

I have a shader that allows me to blend two textures together. As a shader newbie, I'm struggling to try to word this carefully without too much confusion. I want to be able to blend between one texture to another on a plane asset, at one end of the plane is a snow texture and the other is a rock texture. I want to blending the middle of the plane so that if gives the effect of the first texture at 0.5 (snow) blending with the second texture (rock) - a snowy rocky blend. Here is a a picture to explain what I want to achieve:

alt text

The plane just blends the whole of the plane from one texture to another (not what I want). Any help is appreciated.

CODE:

 Shader "Custom/something" {
     Properties {
         // define texture, default white
         _MainTex ("Base (RGB)", 2D) = "white" {}
         // define 2nd texture default white
         _Texture2 ("Blend Texture 1", 2D) = "white" {}
         
         //http://answers.unity3d.com/questions/232106/shader-blending-multiple-textures-in-cg-code.html
         _Blend1 ("Blend between _MainTex and Texture2", Range (0, 1) ) = 0 //- Blend1 is the slider to go from snow (0) to rock (1)
         //_Blend1 (for (float i = 0.0; i < 1.0; i++;) = i // - test
     }
     SubShader {
         Tags { "RenderType"="Opaque" } // render opaque geometry
         LOD 400
         
         CGPROGRAM
         
         // surface shader, get output by calling surf function, use diffuse (lambert) lighting model
         #pragma surface surf Lambert
         
         #pragma target 3.0
         //#pragma surface surf BlinnPhong
 
         sampler2D _MainTex;
         sampler2D _Texture2;
         float _Blend1;
 
         struct Input {
             // get uv coordinates of _MainTex
             float2 uv_MainTex;
             // get uv coordinates of _Texture2
             float2 uv_Texture2;
         };
 
         void surf (Input IN, inout SurfaceOutput o) {
             //half4 c = tex2D (_MainTex, IN.uv_MainTex);
             
             // how to specify uv,
             // http://unitygems.com/noobshader1/
             // blend 0.5
             
             fixed4 mainCol = tex2D(_MainTex, IN.uv_MainTex);
             fixed4 texTwoCol = tex2D(_Texture2, IN.uv_MainTex);
             //fixed4 texTwoCol = tex2D(_Texture2, IN.uv_Texture2);
             fixed4 output = lerp(mainCol, texTwoCol, _Blend1);
             o.Albedo = output.rgb;
             o.Alpha = output.a;
         }
         ENDCG
     } 
     FallBack "Diffuse"


capture.png (4.4 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

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

Related Questions

shader cg blending two textures 1 Answer

Alpha Blending Problem 0 Answers

cg shader blend textures in between two planes/tiles 0 Answers

How to force the compilation of a shader in Unity? 5 Answers

Is it possible to make a global cginclude inside of the asset directory? 0 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