feat: no splash zones

This commit is contained in:
TrèsAbhi committed 2024-01-11 21:30:34 -06:00
1 parent 7fe35243db
commit c9eee14b21
5 files changed
+9 -82

No files matched your search

+1 -5
View File
@@ -1,9 +1,7 @@
import { MeshProps } from '@react-three/fiber';
import { MeshStandardMaterial } from 'three';
import CustomShaderMaterial from 'three-custom-shader-material';
import { useTankopedia } from '../../stores/tankopedia';
import fragment from './shaders/fragment.glsl';
import fragmentOpaque from './shaders/fragmentOpaque.glsl';
import vertex from './shaders/vertex.glsl';
interface ArmorMeshProps extends MeshProps {
@@ -32,8 +30,6 @@ export function ArmorMesh({
spaced = false,
...props
}: ArmorMeshProps) {
const opaqueArmor = useTankopedia((state) => state.model.opaqueArmor);
return (
<>
{!spaced && (
@@ -67,7 +63,7 @@ export function ArmorMesh({
isAffectedBySpaced: { value: isAffectedBySpaced },
}}
vertexShader={vertex}
fragmentShader={opaqueArmor && !spaced ? fragmentOpaque : fragment}
fragmentShader={fragment}
/>
</mesh>
</>
@@ -49,7 +49,14 @@ void main() {
if (spaced) {
csm_FragColor = vec4(1.0, 0.0, 1.0, 0.5);
} else {
csm_FragColor = vec4(1.0, 0.392, 0.0, alpha);
float angledThickness = thickness / cos(angle);
if (angledThickness * (5.0 / 11.0) > penetration) {
csm_FragColor = vec4(1.0, 0.0, 0.0, alpha);
} else {
csm_FragColor = vec4(1.0, 0.392, 0.0, alpha);
}
}
} else {
if (spaced) {
@@ -1,62 +0,0 @@
// split shaders due to https://github.com/FarazzShaikh/THREE-CustomShaderMaterial/issues/48
varying vec3 vCSMViewPosition;
uniform float thickness;
uniform float penetration;
uniform float ricochet;
uniform float caliber;
uniform float normalization;
uniform bool canRichochet;
uniform bool canSplash;
void main() {
vec3 normalizedNormal = normalize(vNormal);
vec3 normalizedViewPosition = normalize(vCSMViewPosition);
float dotProduct = dot(normalizedNormal, -normalizedViewPosition);
float angle = acos(dotProduct);
float penetrationChance = -1.0;
bool threeCaliberRule = caliber > 3.0 * thickness;
if (canRichochet && !threeCaliberRule && angle >= ricochet) {
// auto ricochet angle and three caliber rule not met
penetrationChance = 0.0;
} else {
bool twoCaliberRule = caliber > 2.0 * thickness;
float finalNormalization = twoCaliberRule ? (normalization * 1.4 * caliber) / (2.0 * thickness) : normalization;
float effectiveArmor = thickness / cos(angle - finalNormalization);
float penetrationRandomRadius = penetration * 0.05;
float penetrationDifference = effectiveArmor - penetration;
if (penetrationDifference > penetrationRandomRadius) {
// even with a +5% buff, can't penetrate
penetrationChance = 0.0;
} else if (penetrationDifference < -penetrationRandomRadius) {
// event with a -5% nerf, can penetrate
penetrationChance = 1.0;
} else {
// penetration gradiant
penetrationChance = 1.0 - (penetrationDifference + penetrationRandomRadius) / (2.0 * penetrationRandomRadius);
}
}
if (canSplash) {
float h = mix(20.0 / 360.0, 1.0 / PI, penetrationChance);
float s = 1.0;
float v = 1.0;
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p = abs(fract(h + K.xyz) * 6.0 - K.www);
vec3 rgb = v * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), s);
csm_DiffuseColor = vec4(rgb, 1.0);
} else {
float h = mix(0.0, 1.0 / PI, penetrationChance);
float s = 1.0;
float v = 1.0;
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p = abs(fract(h + K.xyz) * 6.0 - K.www);
vec3 rgb = v * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), s);
csm_DiffuseColor = vec4(rgb, 1.0);
}
}