Skip to content

Commit

Permalink
impostor shader fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
nem0 committed Sep 19, 2023
1 parent 67db8cd commit e2dc410
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions data/pipelines/impostor.shd
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,14 @@ uniform("Radius", "float")
vertex_shader [[
layout(location = 0) in vec3 a_position;
layout(location = 1) in vec2 a_uv;
layout(location = 4) in vec4 i_rot_lod;
layout(location = 5) in vec4 i_pos_scale;
#if defined INSTANCED
layout(location = INSTANCE0_ATTR) in vec4 i_rot_lod;
layout(location = INSTANCE1_ATTR) in vec4 i_pos_scale;
#else
layout(location = INSTANCE0_ATTR) in vec4 i_rot;
layout(location = INSTANCE1_ATTR) in vec4 i_pos_lod;
layout(location = INSTANCE2_ATTR) in vec4 i_scale;
#endif
layout (location = 0) out vec2 v_uv;
layout (location = 1) out vec3 v_normal;
layout (location = 2) out vec3 v_tangent;
Expand All @@ -55,8 +61,22 @@ vertex_shader [[

void main() {
mat3 tangent_space;

#if defined INSTANCED
vec3 instance_pos = i_pos_scale.xyz;
float scale = i_pos_scale.w;
vec4 to_model_space = vec4(-i_rot_lod.xyz, sqrt(1 - dot(i_rot_lod.xyz, i_rot_lod.xyz)));
v_lod = i_rot_lod.w;
#else
vec3 instance_pos = i_pos_lod.xyz;
vec3 scale = i_scale.xyz;
vec4 to_model_space = i_rot;
v_lod = i_pos_lod.w;
#endif


#ifndef DEPTH
vec3 N = normalize(i_pos_scale.xyz);
vec3 N = normalize(instance_pos);
#else
vec3 N = normalize(Global.light_dir.xyz);
#endif
Expand All @@ -65,9 +85,7 @@ vertex_shader [[
tangent_space[2] = cross(tangent_space[0], tangent_space[1]);

vec3 vd = vec3(N.x, N.y, N.z);
vec4 to_model_space = vec4(-i_rot_lod.xyz, sqrt(1 - dot(i_rot_lod.xyz, i_rot_lod.xyz)));
vd = rotateByQuat(to_model_space, vd);
v_lod = i_rot_lod.w;
#if !defined DEPTH && defined HAS_SELFSHADOW
vec3 ld = rotateByQuat(to_model_space, -Global.light_dir.xyz);
v_shadow_coefs = max(vec4(ld.x, -ld.z, -ld.x, ld.z), vec4(0));
Expand All @@ -82,10 +100,10 @@ vertex_shader [[
#else
vec3 p = u_center.xyz + tangent_space * (a_position - u_center.xyz);
#endif
p *= i_pos_scale.w;
p *= scale;
v_tangent = tangent_space[0];
v_normal = tangent_space[2];
v_wpos = vec4(i_pos_scale.xyz + p, 1);
v_wpos = vec4(instance_pos + p, 1);

gl_Position = Pass.view_projection * v_wpos;
}
Expand Down Expand Up @@ -148,6 +166,7 @@ fragment_shader [[
data.emission = u_emission;
data.translucency = u_translucency;
data.ao = 1;
data.motion = computeStaticObjectMotionVector(v_wpos.xyz);

#if !defined DEPTH && defined HAS_SELFSHADOW
vec4 self_shadow = texture(t_selfshadow, v_uv);
Expand Down

0 comments on commit e2dc410

Please sign in to comment.