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 UnusedNickname · Nov 10, 2015 at 09:31 AM · shadersplatmap

SplatMaps and packing variables

Hello folks,

I am currently trying to wrap my head around terrain texturing using splatmaps. As a base I a use this shader which I found on reddit :

 Shader "Custom/Splatmap" {

 Properties {
 _MainTex ("Splat Map", 2D) = "white" {}
 _Texture1 ("Texture 1", 2D) = "white" {}
 _Texture2 ("Texture 2", 2D) = "white" {}
 _Texture3 ("Texture 3", 2D) = "white" {}
 _Texture4 ("Texture 4", 2D) = "white" {}
 }

 SubShader {

 Tags {"RenderType" = "Opaque"}


 CGPROGRAM
 #pragma surface surf Lambert


 struct Input {
         float2 uv_MainTex;
         float2 uv_Texture1;
         float2 uv_Texture2;
         float2 uv_Texture3;
         float2 uv_Texture4;
 };


 sampler2D _MainTex;
 sampler2D _Texture1;
 sampler2D _Texture2;
 sampler2D _Texture3;
 sampler2D _Texture4;


 void surf (Input i, inout SurfaceOutput o) {        
         half4 splatmapMask = tex2D (_MainTex, i.uv_MainTex);
         half4 combinedColor = tex2D (_Texture1, i.uv_Texture1) * splatmapMask.r;
         combinedColor += tex2D (_Texture2, i.uv_Texture2) * splatmapMask.g;
         combinedColor += tex2D (_Texture3, i.uv_Texture3) * splatmapMask.b;
         combinedColor += tex2D (_Texture4, i.uv_Texture4) * splatmapMask.a;

         o.Albedo = combinedColor;
         }
 ENDCG
  }



  FallBack "Diffuse"
  }


The first problem is, this shader doesn't work as it is, I have to remove one of the textures, else I get " Too many texture interpolators would be used for ForwardBase pass (11 out of max 10)"

So I read and read and found I have to add

  #pragma target 3.0

but still I have to remove a texture to make it work.

So I read further and they said I have to pack together my input variables, so 2 float2 become one float4, but here my lack of shader programming skill comes into play... I am not sure how to do that.

I'd imagine to do it like this :

    struct Input {
      float2 uv_MainTex;
      float4 uv_Texture1and2;
      float4 uv_Texture3and4;
    };

but how do I get them apart again in the surf function? And I am not even sure where this input comes from and how it knows it contains 2 texture coords in 1 variable.

Please, if somebody could enlighten me... Bonus question, how are the 11 interpolators calculated, where do they come from?

Thanks

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

change terrain built in shaders 1 Answer

BumpMap on terrain splatmap shader 0 Answers

Can you change terrain material? 4 Answers

Shader - Texture Array with Blendmap Neighbour textures bleeding 1 Answer

How to modify output color of built-in Terrain Shader with more than 4 Splat Textures? 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