Custom Splatmap shader does not work correctly in 3.0

coindropcoindrop Posts: 6Member

Hi, I found the shader below on youtube in the comment section: https://youtube.com/watch?v=RLAG4RbT-5U

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;
 }

Answers

  • MegalomaniakMegalomaniak Posts: 389Member
    edited February 12

    @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:
    https://support.solidangle.com/display/AFMUG/Gamma+Correction+and+Linear+Workflow

  • NightAvailNightAvail Posts: 2Member

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

  • MegalomaniakMegalomaniak Posts: 389Member

    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: 6Member

    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: 389Member

    Care to upload the scene for debugging?

  • coindropcoindrop Posts: 6Member

    Ok, I have attached a small example project.

  • MegalomaniakMegalomaniak Posts: 389Member

    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.

Sign In or Register to comment.