+1 vote

How to apply/mix multiple materials by vertex color mask?

To make it clearer what I want to do... was here is such Shader-material for Year from 2.X:

enter link description here

I am very interested in an analogue for materials from Godot 3. But I do not know how to solve this task

in Engine by (361 points)

1 Answer

+1 vote

You cannot mix two materials at the same time. A pixel can only be calculated using one shader (hence one material).

However if you are talking about textures, that's possible with a shader that uses multiple "weights" to blend different visuals rather than only one set of textures.

A classical approach we can do in Godot is to have one of the vertex attribute being 4 "weights", for example Color with R, G , B and A. Then, in a shader, you sample 4 textures, and blend the colors together using the 4 weights so you can choose how much of each gets rendererd in the final pixel.

This approach can expand for normal maps, roughness maps etc, however it is more expensive than regular materials because there are a lot more textures to fetch.

I am working on a terrain plugin that currently uses the 4-weights approach, but I'm using textures instead of vertices, with many more tweaks: https://github.com/Zylann/godot_heightmap_native_plugin/blob/master/addons/zylann.hterrain/shaders/simple4.shader

Texture arrays could allow more textures to be used but they aren't supported yet in the API...

by (29,120 points)
edited by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.