Custom Splatmap shader does not work correctly in 3.0 (SOLVED)

coindropcoindrop Posts: 7Member
edited March 2018 in Shaders

Hi, I found the shader below on youtube in the comment section:

What I actually want is a "script/shader" that can use a Splat map and mix between 4 full materials (not just the diffuse textures)
but this would be a nice temporary way of doing it, until the other solution becomes available at some point.

The problem with this shader is that the material gets very bright (left side), it should look like the grass on the right side.
Hope someone has an idea why this happens.

Left side: Splatmap shader
Right side: Default Spatial material

shader_type spatial;

uniform float grassres = 1;
uniform float rockres = 1;
uniform float dirtres = 1;

uniform sampler2D grass;
uniform sampler2D rock;
uniform sampler2D dirt;
uniform sampler2D splatmap;

void fragment(){
 float grassval = texture(splatmap, UV).g;
 float rockval = texture(splatmap, UV).b;
 float dirtval = texture(splatmap, UV).r;

 vec3 grasstex = texture(grass, UV*grassres).rgb * grassval;
 vec3 rocktex = texture(rock, UV*rockres).rgb * rockval;
 vec3 dirttex = texture(dirt, UV*dirtres).rgb * dirtval;
 vec3 result = grasstex+rocktex+dirttex;

 ALBEDO = result;


  • MegalomaniakMegalomaniak Posts: 1,086Admin
    edited February 2018

    @coindrop said:

    The problem with this shader is that the material gets very bright (left side), it should look like the grass on the right side.

    Look at your albedos, the grass is rather dark where your dirt in comparison is really quite bright. are you sure your textures have all been created in linear workflow? Might they need to be imported as sRGB?

    And yes this example shader has been kept fairly simple by the author since it just shows how to implement the splat map based mixing.

    edit: here is an explanation of linear workflow from a offline renderers perspective, but I recon applicable enough:

  • NightAvailNightAvail Posts: 2Member

    Hmm..., almost seems like you need to clamp the values so they don't go beyond 1.0.

  • MegalomaniakMegalomaniak Posts: 1,086Admin

    In a HDR renderer light reflected by PBR material must be able to reflect values greater than 1 per pixel for the sake of energy conservation, though that would involve some extreme lighting I suppose, but then that's why we have tone-mapping.

  • coindropcoindrop Posts: 7Member

    Here is the exact same texture on both models. Right side is the default spatial material with the texture applied for diffuse and left side is still the splat map shader. I doubt this is a linear workflow thing, I think it has something to do with the shader. The default spatial material does something that this splat map shader doesn't.

    *dirt is actually a sand texture I just didn't rename it :)

  • MegalomaniakMegalomaniak Posts: 1,086Admin

    Care to upload the scene for debugging?

  • coindropcoindrop Posts: 7Member

    Ok, I have attached a small example project.

  • MegalomaniakMegalomaniak Posts: 1,086Admin

    Yeah, this definitely seems like a bug. I tried to do the mixing in another way using mix() instead of adding the values together and it still remained an issue, very bizarre. I had totally not noticed the issue before, which shows I suppose how easy it is to overlook.

  • coindropcoindrop Posts: 7Member
    edited May 2018 Answer ✓

    From youtube user: Muumihobitti (This worked and the shader now looks correct)

    Textures require hints for some reason.

    uniform sampler2D grass : hint_albedo;
    uniform sampler2D rock : hint_albedo;
    uniform sampler2D dirt : hint_albedo;
  • MegalomaniakMegalomaniak Posts: 1,086Admin
    edited May 2018

    Huh, thats a bit strange alright, but then again I guess the hints exist for a reason.

    TL;DR for the thread: Indeed one has to make sure the color-spaces are handled correctly, for this one has to make use of the hints in appropriate places.

Sign In or Register to comment.