Skip to content

Commit

Permalink
Fix errors with environmental lighting on all shaders
Browse files Browse the repository at this point in the history
  • Loading branch information
Melioli committed Sep 12, 2024
1 parent 70117cd commit 5b745de
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ float4 ps_model(vs_out i, bool vface : SV_ISFRONTFACE) : SV_TARGET
float3 shadow_area = (float3)1.0f;
shadow_area = shadow_area_transition(lightmap.y, i.v_col.x, ndotl, material_id);
// metalshadow = shadow_area_transition(lightmapao, vertexao, ndotl, material_id);
if(_UseFaceMapNew) shadow_area = shadow_area_face(uv_a.xy, light).xxx;
if(_UseFaceMapNew) shadow_area = ndotl;
// shadow = outshadow;

float bright = lightmap.y > 0.9f && !_UseFaceMapNew;
Expand Down
11 changes: 7 additions & 4 deletions Shaders/Honkai Impact/Includes/HoyoToonHonkaiImpact-Program.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -158,26 +158,29 @@ float4 ps_model (vs_out i, bool vface : SV_ISFRONTFACE) : SV_Target
float4 lightmap = _LightMapTex.Sample(sampler_linear_repeat, uv);

float s = 1.0f;

float light_shadow = 0.0f;
#if defined(use_shadow)
#if defined(faceishadow)
// shadow stuff
float shadow_right = (_FaceMapTex.Sample(sampler_linear_repeat, float2( uv.x, uv.y)).a);
float shadow_left = (_FaceMapTex.Sample(sampler_linear_repeat, float2(1.0 - uv.x, uv.y)).a);
#endif

#endif

light_shadow = hi3_shadow(lightmap.y, ndotl, vertex.x);

float4 shadow_col = shadow_cols(lightmap.a);
if(variant_selector == 1 || variant_selector == 3) shadow_col = _ShadowColor;
if(variant_selector == 1)
{
light_shadow = saturate(dot(float3(0.5f, 0.5f, 1.0f), light_dir));
#if defined(faceishadow)
s = shadow_rate_face(shadow_right, shadow_left, lightmap.y, i.ws_pos);
#endif
}
else
{
s = hi3_shadow(lightmap.y, ndotl, vertex.x);
// light_shadow = s;
}
float4 _shadow = min(s + (shadow_col), 1.0);
#else
Expand Down Expand Up @@ -322,7 +325,7 @@ float4 ps_model (vs_out i, bool vface : SV_ISFRONTFACE) : SV_Target
#endif
#ifdef _IS_PASS_LIGHT
float light_intesnity = max(0.001f, (0.299f * _LightColor0.r + 0.587f * _LightColor0.g + 0.114f * _LightColor0.b));
float3 light_pass_color = ((diffuse.xyz * 5.0f) * _LightColor0.xyz) * atten * s * 0.5f;
float3 light_pass_color = ((diffuse.xyz * 5.0f) * _LightColor0.xyz) * atten * light_shadow * 0.5f;
float3 light_color = lerp(light_pass_color.xyz, lerp(0.0f, min(light_pass_color, light_pass_color / light_intesnity), _WorldSpaceLightPos0.w), _FilterLight); // prevents lights from becoming too intense
#if defined(POINT) || defined(SPOT)
out_col.xyz = (light_color) * 0.5f;
Expand Down
5 changes: 5 additions & 0 deletions Shaders/Honkai Impact/Includes/Part2-program.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ float4 ps_model(vs_out i, bool vface : SV_ISFRONTFACE) : SV_TARGET
float3 light = _WorldSpaceLightPos0;
#if defined(POINT) || defined(SPOT)
light = normalize(_WorldSpaceLightPos0.xyz - i.ws_pos.xyz);

#endif

// half vector
Expand Down Expand Up @@ -246,6 +247,10 @@ float4 ps_model(vs_out i, bool vface : SV_ISFRONTFACE) : SV_TARGET
#endif

#ifdef _IS_PASS_LIGHT
if(variant_selector == 1 && _EnableFaceMap)
{
shaded_area.x = dot(float3(0.5f, 0.5f, 1.0f), light);
}
float light_intesnity = max(0.001f, (0.299f * _LightColor0.r + 0.587f * _LightColor0.g + 0.114f * _LightColor0.b));
shaded_area.x = smoothstep(0.0f, 0.5f, shaded_area.x) * 0.8f + 0.1f;
float3 light_pass_color = ((diffuse.xyz * 5.0f) * _LightColor0.xyz) * atten * shaded_area.x * 0.5f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -741,17 +741,18 @@ float4 ps_base(vs_out i, bool vface : SV_IsFrontFace) : SV_Target
ndotl = dot(normal, light);

float3 shadow_area = (float3)1.0f;
shadow_area = shadow_rate(ndotl, lightmap.y, i.v_col.x, 2.0f);
shadow_area = shadow_rate(ndotl, lightmap.y, i.v_col.x, 1.0f);
// metalshadow = shadow_area_transition(lightmapao, vertexao, ndotl, material_id);
#if defined(faceishadow)
if(_FaceMaterial) shadow_area = dot((float3)0.5f, light);
ndotl = dot(float3(0.5f, 0.5f, 1.0f), light);
if(_FaceMaterial) shadow_area = ndotl;
#endif

float light_intesnity = max(0.001f, (0.299f * _LightColor0.r + 0.587f * _LightColor0.g + 0.114f * _LightColor0.b));
float3 light_pass_color = ((diffuse.xyz * 1.0f) * _LightColor0.xyz) * atten * shadow_area * 0.5f;
float3 light_pass_color = ((diffuse.xyz * 1.0f) * _LightColor0.xyz) * atten * shadow_area;
float3 light_color = lerp(light_pass_color.xyz, lerp(0.0f, min(light_pass_color, light_pass_color / light_intesnity), _WorldSpaceLightPos0.w), _FilterLight); // prevents lights from becoming too intense
#if defined(POINT) || defined(SPOT)
out_color.xyz = (light_color) * 0.5f;
out_color.xyz = (light_color);
#elif defined(DIRECTIONAL)
out_color.xyz = 0.0f; // dont let extra directional lights add onto the model, this will fuck a lot of shit up
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ fixed4 ps_model (vertex_out i) : SV_Target
float light_intesnity = max(0.001f, (0.299f * _LightColor0.r + 0.587f * _LightColor0.g + 0.114f * _LightColor0.b));
float3 light_pass_color = ((diffuse.xyz * 5.0f) * _LightColor0.xyz) * atten * shadow_area * 0.5f;
float3 light_pass_a_color = lerp(light_pass_color.xyz, lerp(0.0f, min(light_pass_color, light_pass_color / light_intesnity), _WorldSpaceLightPos0.w), _FilterLight); // prevents lights from becoming too intense
if(_MaterialType == 6) light_pass_a_color = float3(0.0f, 0.0f, 0.0f);
#if defined(POINT) || defined(SPOT)
output.xyz = (light_pass_a_color) * 0.5f;
#elif defined(DIRECTIONAL)
Expand Down

0 comments on commit 5b745de

Please sign in to comment.