Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 kilian277 · Jul 13, 2016 at 03:34 PM · shaderunity5blending

Weird shader thing

Hi,

I'm making a terrain blending shader that uses 2 blendmaps , for now i'm just testing one. But when i just use:

 o.Albedo = b1;

b1 being the first blendmap it only gives me a solid red like ii only takes the first pixel of the blendmap.

Here's the full shader:

 Shader "Terrain/6lyr_2tex_terrain" {
     Properties
     {
         _blend1 ("Blendmap 1", 2D) = "white" {}
         _blend2 ("Blendmap 2", 2D) = "white" {}
         _Layer1 ("Layer1", 2D) = "white" {}
         _Layer1n ("Layer 1 normal", 2D) = "white" {}
         _Layer2 ("Layer2", 2D) = "white" {}
         _Layer2n ("Layer 2 normal", 2D) = "white" {}
         _Layer3 ("Layer3", 2D) = "white" {}
         _Layer3n ("Layer 3 normal", 2D) = "white" {}
         _Layer4 ("Layer4", 2D) = "white" {}
         _Layer4n ("Layer 4 normal", 2D) = "white" {}
         _Layer5 ("Layer5", 2D) = "white" {}
         _Layer5n ("Layer 5 normal", 2D) = "white" {}
         _Layer6 ("Layer6", 2D) = "white" {}
         _Layer6n ("Layer 6 normal", 2D) = "white" {}
     }
     SubShader
     {
             Tags { "Queue"="Geometry" "RenderType" = "Opaque"}
             
             Cull Back
             CGPROGRAM
             
             #include "UnityCG.cginc"
             #pragma surface surf Standard
             #pragma target 3.0
  
             sampler2D   _blend1;
             sampler2D   _blend2;
             sampler2D   _Layer1;
             sampler2D   _Layer1n;
             sampler2D   _Layer2;
             sampler2D   _Layer2n;
             sampler2D   _Layer3;
             sampler2D   _Layer3n;
             sampler2D   _Layer4;
             sampler2D   _Layer4n;
             sampler2D   _Layer5;
             sampler2D   _Layer5n;
             sampler2D   _Layer6;
             sampler2D   _Layer6n;
 
             struct Input {
                 float2 uv_Blend : TEXCOORD0;
                 float2 uv_Layer1 : TEXCOORD1;
                 float2 uv_Layer2 : TEXCOORD2;
                 float2 uv_Layer3 : TEXCOORD3;
                 float2 uv_Layer4 : TEXCOORD4;
                 float2 uv_Layer5 : TEXCOORD5;
                 float2 uv_Layer6 : TEXCOORD6;
             };
 
             void surf (Input IN, inout SurfaceOutputStandard o) 
             {
                 float4 b1 = tex2D (_blend1, IN.uv_Blend);
                 float4 b2 = tex2D (_blend2, IN.uv_Blend);
                 
                 float4 l1 = tex2D (_Layer1, IN.uv_Layer1);
                 float4 l2 = tex2D (_Layer2, IN.uv_Layer2);
                 float4 l3 = tex2D (_Layer3, IN.uv_Layer3);
                 float3 l1n = UnpackNormal(tex2D (_Layer1n, IN.uv_Layer1));
                 float3 l2n = UnpackNormal(tex2D (_Layer2n, IN.uv_Layer2));
                 float3 l3n = UnpackNormal(tex2D (_Layer3n, IN.uv_Layer3));
                 
                 float4 l4 = tex2D (_Layer4, IN.uv_Layer4);
                 float4 l5 = tex2D (_Layer5, IN.uv_Layer5);
                 float4 l6 = tex2D (_Layer6, IN.uv_Layer6);
                 float3 l4n = UnpackNormal(tex2D (_Layer4n, IN.uv_Layer4));
                 float3 l5n = UnpackNormal(tex2D (_Layer5n, IN.uv_Layer5));
                 float3 l6n = UnpackNormal(tex2D (_Layer6n, IN.uv_Layer6));
                 
                 o.Albedo = l1.rgb * b1.r;
                 o.Albedo += l2.rgb * b1.g;
                 o.Albedo += l3.rgb * b1.b;
                 o.Alpha = 1;
                 
                 o.Normal = (l1n.rgb * b1.r) + (l2n.rgb * b1.g) + (l3n.rgb * b1.b);
                 //o.Albedo = b1;
             }
         ENDCG
     }
     FallBack "Diffuse"
 }

And when trying to blend it only shows the first layer fully, nothing else. Since Unity5 i find that some simple shader things don't work anymore.

Comment
Add comment · Show 4
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 Bunny83 · Jul 13, 2016 at 03:59 PM 0
Share

You use 7 different texture coordinates? Unity's $$anonymous$$esh class only supports 4. How you you set the texture coordinates? Are you sure that you provide the correct UV data in each channel? Usually one channel is enough so your code is a bit confusing.

avatar image kilian277 Bunny83 · Jul 13, 2016 at 04:03 PM 0
Share

Still when removing all the Texcoords it's not working , i only use one UV0 channel so that's not the problem , uv's are also correctly unwrapped in max but stil the terrain gives me only the first texture and nothing else.

avatar image Bunny83 kilian277 · Jul 14, 2016 at 06:05 AM 0
Share

Well, try this ins$$anonymous$$d:

 o.Albedo = IN.uv_Blend;

or whatever UV channel you use now. This should give you a gradient. If it still is all red your UVs aren't right. $$anonymous$$ake sure your UVs are either inside the range 0.0 and 1.0 or set the textures wrapmode to "wrap" if you use values outside that range.

edit
If you're still not sure if the UV is setup correctly, you can put my UVViewer into an editor folder inside your project. You can open the viewer via the menu "Tools / B83 / UVViewer". Note when you open it the first time the script generates two shader and two materials inside the resources folder which are then reused each time you use it. If you don't need / want the viewer anymore just remove those as well.

If the UVViewer window is open you just have to select your object in the scene. You can pan with any mouse button and zoom with the scroll wheel. Holding CTRL while moving the mouse will display information of the closest vertex. It will also highlight the vertex in the scene view.

Show more comments

1 Reply

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

Answer by kilian277 · Jul 15, 2016 at 09:15 PM

Okay so i found the problem , really stupid one.

Turns out the uv variable i used was wrong i named the sampler2D _blend1 so in theory it should have been

 float2 uv_blend1;
 
 //and not
 
 float uv_Blend;



Comment
Add comment · 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

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

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

Related Questions

Sprite texture incorrect 0 Answers

NavMeshAgent dont find the right way on runtime build NavMesh ,Agents didn´t walk right on a runtime generated NavMesh 0 Answers

[Shader] How to use Blend SrcFactor DstFactor, SrcFactorA DstFactorA 1 Answer

Logical BlendOp not working 0 Answers

Writing a shader for a terrain? 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