#Billboard Sprite3D

1 messages · Page 1 of 1 (latest)

fringe cedar
#

I'm making a roguelike game in 2D, everything is great, but I decided to add a third dimension and I have a problem because the shaders that worked on Sprite2D do not work on Sprite3D. I figured out that to achieve this effect, you need to use albedo_texture. This Sahder works as it should

#
render_mode blend_mix,depth_draw_opaque,cull_disabled,diffuse_burley,specular_schlick_ggx,unshaded;
uniform sampler2D albedo_texture : filter_nearest, source_color;
uniform vec3 scale = vec3(1,1,1);
uniform float wind_strength : hint_range(0.1, 1.0, 0.02);
uniform float wind_speed : hint_range(0.5, 2.0, 0.1);

void vertex(){
    NORMAL = vec3(0.0, 1.0, 0.0);
    VERTEX.x += sin(NODE_POSITION_WORLD.x + TIME * wind_speed + UV.y) * ( 1.0 - UV.y) * wind_strength;
    VERTEX.z += cos(NODE_POSITION_WORLD.z + TIME * wind_speed + UV.y) * ( 1.0 - UV.y) * wind_strength;
    VERTEX = VERTEX * vec3(scale.x, scale.y, scale.z);
    MODELVIEW_MATRIX = VIEW_MATRIX * mat4(vec4(normalize(cross(vec3(0.0, 1.0, 0.0), INV_VIEW_MATRIX[2].xyz)), 0.0), vec4(0.0, 1.0, 0.0, 0.0), vec4(normalize(cross(INV_VIEW_MATRIX[0].xyz, vec3(0.0, 1.0, 0.0))), 0.0), MODEL_MATRIX[3]);
}

void fragment(){
    ALBEDO = texture(albedo_texture, UV).rgb;
    ALPHA = texture(albedo_texture, UV).a;
}
#

I need help to make an outline out of it in a similar way

#
shader_type spatial;
render_mode blend_mix,depth_draw_opaque,cull_disabled,diffuse_burley,specular_schlick_ggx,unshaded;
uniform sampler2D albedo_texture : filter_nearest, source_color;

uniform float OUTLINE_OPACITY: hint_range(0.0, 1.0, 0.01) = 1.;
uniform bool OUTLINE_ACTIVE = false;
uniform float OUTLINE_THOCKNESS: hint_range(0, 30) = 0.5;
uniform vec4  OUTLINE_COLOR: source_color = vec4(1,0,0,1);
uniform float OUTLINE_WIDTH = 2.0;

void vertex(){
    NORMAL = vec3(0.0, 1.0, 0.0);
}

void fragment(){
    ALBEDO = texture(albedo_texture, UV).rgb;
    ALPHA = texture(albedo_texture, UV).a;
}
#

for example, a working 2D shader looks like the one I use

#
shader_type canvas_item;

uniform float OUTLINE_OPACITY: hint_range(0.0, 1.0, 0.01) = 1.;
uniform bool OUTLINE_ACTIVE = false;
uniform float OUTLINE_THOCKNESS: hint_range(0, 30) = 0.5;
uniform vec4  OUTLINE_COLOR: source_color = vec4(1,0,0,1);

void outline(in vec2 uv, in sampler2D tex, in vec2 spriteSize, in vec2 pixelSize, inout vec4 color) {
    vec2 size = vec2(OUTLINE_THOCKNESS) / spriteSize;
    float alpha = color.a;
    alpha += texture(tex, uv + vec2(0.0, -size.y)).a;
    alpha += texture(tex, uv + vec2(size.x, -size.y)).a;
    alpha += texture(tex, uv + vec2(size.x, 0.0)).a;
    alpha += texture(tex, uv + vec2(size.x, size.y)).a;
    alpha += texture(tex, uv + vec2(0.0, size.y)).a;
    alpha += texture(tex, uv + vec2(-size.x, size.y)).a;
    alpha += texture(tex, uv + vec2(-size.x, 0.0)).a;
    alpha += texture(tex, uv + vec2(-size.x, -size.y)).a;
   
    vec3 final_color = mix(OUTLINE_COLOR.rgb, color.rgb, color.a);
    color = vec4(final_color, clamp(alpha, 0.0, 1.0));
}

void fragment() {
    vec4 color = texture(TEXTURE, UV);
    vec2 size = vec2(textureSize(TEXTURE, 0));
    vec2 uv = UV;
    vec2 screen_uv = SCREEN_UV;

    if(OUTLINE_ACTIVE) outline(uv, TEXTURE, size, TEXTURE_PIXEL_SIZE, color);

    color.a*= OUTLINE_OPACITY;
    COLOR=color;
}

void vertex() {
}