Last active
April 24, 2025 01:40
-
-
Save partybusiness/2511ffb195e886b3b36650914122d386 to your computer and use it in GitHub Desktop.
fake chrome using cubemap for reflection, with a black blob shadow superimposed over the viewer's position
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shader_type spatial; | |
uniform samplerCube sky_cube:source_color; | |
uniform sampler2D shadow_texture:source_color, repeat_disable, hint_default_white; | |
uniform vec2 shadow_scale = vec2(2.0, 1.0); | |
uniform vec2 shadow_offset = vec2(0.5,0.2); | |
uniform vec3 base_colour:source_color; | |
// multiplier for how strong the reflection should be | |
uniform float reflection_multiplier = 1.0; | |
varying vec3 world_position; | |
void vertex() | |
{ | |
world_position = (MODEL_MATRIX * vec4(VERTEX, 1.0)).xyz; | |
} | |
void fragment() { | |
vec3 view_dir = normalize(world_position - CAMERA_POSITION_WORLD); | |
vec3 world_normal = (INV_VIEW_MATRIX * vec4(NORMAL, 0.0)).xyz; | |
// get viewer shadow | |
vec3 reflected_view = reflect(VIEW, NORMAL); | |
reflected_view = reflected_view / -abs(reflected_view.z); | |
vec2 reflected_back_pos = clamp(-(VERTEX + reflected_view * length(VERTEX)).xy * shadow_scale + shadow_offset, 0.0, 1.0); | |
float shadow = texture(shadow_texture, reflected_back_pos).r; | |
// get cubemap reflection with shadow superimposed | |
vec3 reflection = texture(sky_cube, reflect(view_dir, world_normal)).rgb * reflection_multiplier * shadow; | |
ALBEDO = base_colour; | |
EMISSION = reflection; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment