Can ObjectDither be locked in a state?

DetonatressDetonatress Posts: 54Member

So I've made these things out of 2 meshes for each so they can be seen through each other:

The interior mesh uses distance fade min 0, max 30 but with PixelDither while the exterior mesh uses refractive shader. I would like to lock the dither state to what would happen at let's say distance 10 or so in ObjectDither mode. Is it possible?

Answers

  • DschoonmakerDschoonmaker Posts: 266Member

    It's not possible with spatial material. You could convert the spatial material to a shader material and do it in a shader.

  • DetonatressDetonatress Posts: 54Member
    edited June 4

    @Dschoonmaker said:
    It's not possible with spatial material. You could convert the spatial material to a shader material and do it in a shader.

    I've converted it and it gives me this with ObjectDither on:

    shader_type spatial;
    render_mode blend_mix,depth_draw_opaque,cull_disabled,diffuse_burley,specular_schlick_ggx;
    uniform vec4 albedo : hint_color;
    uniform sampler2D texture_albedo : hint_albedo;
    uniform float specular;
    uniform float metallic;
    uniform float distance_fade_min;
    uniform float distance_fade_max;
    uniform float roughness : hint_range(0,1);
    uniform float point_size : hint_range(0,128);
    uniform float rim : hint_range(0,1);
    uniform float rim_tint : hint_range(0,1);
    uniform sampler2D texture_rim : hint_white;
    uniform vec3 uv1_scale;
    uniform vec3 uv1_offset;
    uniform vec3 uv2_scale;
    uniform vec3 uv2_offset;
    
    
    void vertex() {
        UV=UV*uv1_scale.xy+uv1_offset.xy;
    }
    
    
    
    
    void fragment() {
        vec2 base_uv = UV;
        vec4 albedo_tex = texture(texture_albedo,base_uv);
        ALBEDO = albedo.rgb * albedo_tex.rgb;
        METALLIC = metallic;
        ROUGHNESS = roughness;
        SPECULAR = specular;
        {
            float fade_distance = abs((INV_CAMERA_MATRIX * WORLD_MATRIX[3]).z);
            float fade=clamp(smoothstep(distance_fade_min,distance_fade_max,fade_distance),0.0,1.0);
            int x = int(FRAGCOORD.x) % 4;
            int y = int(FRAGCOORD.y) % 4;
            int index = x + y * 4;
            float limit = 0.0;
    
            if (x < 8) {
                if (index == 0) limit = 0.0625;
                if (index == 1) limit = 0.5625;
                if (index == 2) limit = 0.1875;
                if (index == 3) limit = 0.6875;
                if (index == 4) limit = 0.8125;
                if (index == 5) limit = 0.3125;
                if (index == 6) limit = 0.9375;
                if (index == 7) limit = 0.4375;
                if (index == 8) limit = 0.25;
                if (index == 9) limit = 0.75;
                if (index == 10) limit = 0.125;
                if (index == 11) limit = 0.625;
                if (index == 12) limit = 1.0;
                if (index == 13) limit = 0.5;
                if (index == 14) limit = 0.875;
                if (index == 15) limit = 0.375;
            }
    
        if (fade < limit)
            discard;
        }
    
        vec2 rim_tex = texture(texture_rim,base_uv).xy;
        RIM = rim*rim_tex.x;    RIM_TINT = rim_tint*rim_tex.y;
    }
    

    What am I supposed to edit here to lock it to how it looks when I'm at this distance?
    https://imgur.com/PyTnpGx.jpg
    I know I have to get rid of or modify these:
    float fade_distance = abs((INV_CAMERA_MATRIX * WORLD_MATRIX[3]).z);
    float fade=clamp(smoothstep(distance_fade_min,distance_fade_max,fade_distance),0.0,1.0);
    Probably need to trick it into thinking I'm always at the same distance but not sure what controls it.

    I tried to replace fade_distance, and while it does control the transparency, it also makes the object truly transparent, and I'm trying to avoid true transparency because then the objects do not see each other anymore.

    EDIT: I think I got it.
    float fade=clamp(smoothstep(-15,40,fade_distance),0.0,0.3);
    -15 so player never reaches full 0 alpha for the 2nd object while looking through the first. It's the difference between distances and the last 2 values in those brackets (0.0, 0.3) that allows visibility through refractive objects. 0.3 ensures the object never reaches full opacity even in distance.

  • DschoonmakerDschoonmaker Posts: 266Member

    You can get rid of fade_distance, and set fade to a value between 0 and 1 depending on how transparent it should be.

  • DetonatressDetonatress Posts: 54Member
    edited June 4

    @Dschoonmaker said:
    You can get rid of fade_distance, and set fade to a value between 0 and 1 depending on how transparent it should be.

    I tried that but seems like it would need different values or 2 separate objects for that to allow two objects to be seen through each other. Though I can just make each shader unique for each crystal if I'll have two of the same color.

    EDIT: also, the one with lower value cannot be seen by the one with higher value. So it seems like it always depends on the distance dynamic to allow both objects to see each other. I'll just have to keep messing with the other two values until they'll look good enough. It's pretty close to what I want at the moment.
    Also, seems like PixelDither's the best option, as it also shows the interior of the object.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file