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 Hovu96 · Apr 09, 2013 at 08:29 PM · shaderterrainsplatmapsurfaceshaderfog-of-war

How to modify output color of built-in Terrain Shader with more than 4 Splat Textures?

I changed the Built-in Sureface Shader to modify the output color in certain circumstances. In fact I implemented Fog of War for parts of the terrain that isn't visible by the player.

That works great as long as the terrain is using 4 splat textures. In case it's using more than 4 textures, the color modification is only applied to the first 4 textures. The other textures are rendered normally, as though nothing had happened.

I tried to modify the color using the actual surface function (SurfaceOutput.Albedo) and tried modify it using the (finalcolor) function. Both worked for the first 4 textures. But for the other textures it doesn't work.

Any Ideas?

Let me show you an example. This is a Unity terrain using a custom shader: alt text

I added to the built-in terrain shader a finalcolor:grid function to render the hexes:

 void grid (Input IN, SurfaceOutput o, inout fixed4 col) {
     fixed4 grid=tex2D (_TerrainGrid, _TerrainGridOffset+IN.uv_TerrainGrid*_TerrainGridScale) * _GridVisibility;
     col += grid * col * 2.0f; 
 }

When I use the terrain inspector to paint another texture to the terrain. For now, the terrain only contains 3 splat textures: alt text

The result looks like this: alt text

As you can see, the grid is still visible at the changed parts.

Then I added some other splat textures and selected the last one (in this case a water texture): alt text

As you can see, the grid is no more visible at the parts with the water texture: alt text

That only happens if the texture is not one of the first 4 textures.

Comment
Add comment · Show 3
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 Hovu96 · Apr 10, 2013 at 05:55 AM 0
Share

I added some screenshots and sample code to demonstrate the behavior.

avatar image fffMalzbier · Apr 15, 2013 at 09:39 AM 0
Share

It looks like Unity is using 2 different shader for the terrain. FirstPass.shader and AddPass.shader.

You need to modify both of thous shader if you like to use more then 1 Splat-map / more then 4 textures.

avatar image Hovu96 · Apr 16, 2013 at 05:09 PM 0
Share

Thanks fffmalzbier, modifying the add pass shader solved the problem.

2 Replies

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

Answer by Hovu96 · Apr 16, 2013 at 06:03 PM

fffmalzbier solved the problem, his answer is:

It looks like Unity is using 2 different shader for the terrain. FirstPass.shader and AddPass.shader.

You need to modify both of thous shader if you like to use more then 1 Splat-map / more then 4 textures.

Thanks!

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

Answer by solid_state · Apr 14, 2013 at 10:29 AM

As far as i know you can only have 4 textures per splatmap, you may however have more than one splatmap. see this thread

i don't know however if having more splatmaps affects your shader, but maybe this info helps you to figure it out

Comment
Add comment · Show 2 · 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 Hovu96 · Apr 15, 2013 at 07:46 AM 0
Share

Yes, I think Unity splits the list of terrain textures into groups of four textures (called splatmaps) and then invokes the terrain shader multiple times. But this is only an assumption. But I don't understand why my modification to the shader is only applied to the first splatmap.

Is it correct that the shader is invoked multiple times?

avatar image fffMalzbier · Apr 15, 2013 at 09:34 AM 0
Share

The problem is that the splatmap is a normal texture with the channels R G B A -> four channels. For more used textures on the terrain you need at least another splatmap.

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

12 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

Related Questions

change terrain built in shaders 1 Answer

Can you change terrain material? 4 Answers

Splat Map with transition texture? 0 Answers

Can't use material with shaders which need tangent geometry on terrain. 1 Answer

Noob Question - Custom trees and aliasing 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