From 7b6e291a0a29ee6d1517d1ac34b5bf37b8eccc71 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com>
Date: Mon, 22 Jan 2024 19:14:24 -0600
Subject: [PATCH] feat: simplified shaders
---
package.json | 1 -
.../ArmorMesh/components/Armor/index.tsx | 16 +++--
.../components/Armor/shaders/fragment.glsl | 11 ++--
.../components/Armor/shaders/vertex.glsl | 10 +--
.../components/SpacedArmorDepth/index.tsx | 7 +-
.../SpacedArmorDepth/shaders/fragment.glsl | 9 ++-
.../SpacedArmorDepth/shaders/vertex.glsl | 8 ++-
yarn.lock | 64 +------------------
8 files changed, 38 insertions(+), 88 deletions(-)
diff --git a/package.json b/package.json
index 2d5b2474b..bb2db5e75 100644
--- a/package.json
+++ b/package.json
@@ -64,7 +64,6 @@
"satori": "^0.10.8",
"sharp": "0.33.1",
"three": "^0.160.0",
- "three-custom-shader-material": "^5.4.0",
"three-stdlib": "^2.29.1",
"vite-node": "^0.34.5",
"vitepress": "^1.0.0-rc.20",
diff --git a/src/components/ArmorMesh/components/Armor/index.tsx b/src/components/ArmorMesh/components/Armor/index.tsx
index 4217dd208..1600e0e45 100644
--- a/src/components/ArmorMesh/components/Armor/index.tsx
+++ b/src/components/ArmorMesh/components/Armor/index.tsx
@@ -1,7 +1,6 @@
import { MeshProps, useFrame, useThree } from '@react-three/fiber';
import { useEffect, useRef } from 'react';
-import { MeshStandardMaterial, ShaderMaterial, Vector2 } from 'three';
-import ThreeCustomShaderMaterial from 'three-custom-shader-material';
+import { ShaderMaterial, Vector2 } from 'three';
import { degToRad } from 'three/src/math/MathUtils';
import { canSplash } from '../../../../core/blitz/canSplash';
import { isExplosive } from '../../../../core/blitz/isExplosive';
@@ -105,14 +104,12 @@ export function ArmorMesh({
-
+
>
);
diff --git a/src/components/ArmorMesh/components/Armor/shaders/fragment.glsl b/src/components/ArmorMesh/components/Armor/shaders/fragment.glsl
index 0cdc71240..76c09ddd4 100644
--- a/src/components/ArmorMesh/components/Armor/shaders/fragment.glsl
+++ b/src/components/ArmorMesh/components/Armor/shaders/fragment.glsl
@@ -1,4 +1,7 @@
-varying vec3 vCSMViewPosition;
+#define PI 3.1415926535897932384626433832795
+
+varying vec3 vViewPosition;
+varying vec3 vNormal;
uniform bool isExplosive;
uniform bool canSplash;
uniform float thickness;
@@ -30,7 +33,7 @@ void main() {
float penetrationChance = -1.0;
float splashChance = -1.0;
- vec3 normalizedViewPosition = normalize(vCSMViewPosition);
+ vec3 normalizedViewPosition = normalize(vViewPosition);
float dotProduct = dot(vNormal, -normalizedViewPosition);
float coreArmorangle = acos(dotProduct);
@@ -105,8 +108,8 @@ void main() {
vec3 color = vec3(1.0, splashChance * 0.392, 0.0);
if (greenPenetration) {
- csm_FragColor = vec4(mix(color, vec3(0.0, 1.0, 0.0), penetrationChance), 0.5);
+ gl_FragColor = vec4(mix(color, vec3(0.0, 1.0, 0.0), penetrationChance), 0.5);
} else {
- csm_FragColor = vec4(color, (1.0 - penetrationChance) * 0.5);
+ gl_FragColor = vec4(color, (1.0 - penetrationChance) * 0.5);
}
}
\ No newline at end of file
diff --git a/src/components/ArmorMesh/components/Armor/shaders/vertex.glsl b/src/components/ArmorMesh/components/Armor/shaders/vertex.glsl
index f86d379c4..a55abd2c0 100644
--- a/src/components/ArmorMesh/components/Armor/shaders/vertex.glsl
+++ b/src/components/ArmorMesh/components/Armor/shaders/vertex.glsl
@@ -1,12 +1,14 @@
-varying vec3 vCSMViewPosition;
+varying vec3 vNormal;
+varying vec3 vViewPosition;
varying float vZ;
varying mat4 vProjectionMatrix;
void main() {
vec4 vViewPosition4 = modelViewMatrix * vec4(position, 1.0);
- vCSMViewPosition = vViewPosition4.xyz;
-
+ vViewPosition = vViewPosition4.xyz;
vZ = -(modelViewMatrix * vec4(position, 1.0)).z;
-
vProjectionMatrix = projectionMatrix;
+ vNormal = normalMatrix * normal;
+
+ gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
\ No newline at end of file
diff --git a/src/components/ArmorMesh/components/SpacedArmorDepth/index.tsx b/src/components/ArmorMesh/components/SpacedArmorDepth/index.tsx
index 1fe67c4b6..9ed611384 100644
--- a/src/components/ArmorMesh/components/SpacedArmorDepth/index.tsx
+++ b/src/components/ArmorMesh/components/SpacedArmorDepth/index.tsx
@@ -1,6 +1,5 @@
import { MeshProps } from '@react-three/fiber';
-import { MeshStandardMaterial, WebGLRenderTarget } from 'three';
-import ThreeCustomShaderMaterial from 'three-custom-shader-material';
+import { WebGLRenderTarget } from 'three';
import fragmentShader from './shaders/fragment.glsl';
import vertexShader from './shaders/vertex.glsl';
@@ -32,9 +31,7 @@ export function ArmorMeshSpacedArmorDepth(
{props.include && (
- =1.0.33-1 <1.1.0-0":
- version "1.0.34"
- resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-1.0.34.tgz#125820e34bc842d2f2aaafafe4c2916ee32c157c"
- integrity sha512-ok1qVCJuRkNmvebYikljxJA/UEsKwLl2nI1OmaqAu4/UE+h0wKCHok4XkL/gvi39OacXvw59RJUOFUkDib2rHg==
- dependencies:
- core-util-is "~1.0.0"
- inherits "~2.0.1"
- isarray "0.0.1"
- string_decoder "~0.10.x"
-
readable-stream@^2.3.0, readable-stream@^2.3.5:
version "2.3.8"
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.8.tgz#91125e8042bba1b9887f49345f6277027ce8be9b"
@@ -5533,11 +5496,6 @@ string_decoder@^1.1.1:
dependencies:
safe-buffer "~5.2.0"
-string_decoder@~0.10.x:
- version "0.10.31"
- resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-0.10.31.tgz#62e203bc41766c6c28c9fc84301dab1c5310fa94"
- integrity sha512-ev2QzSzWPYmy9GuqfIVildA4OdcGLeFZQrq5ys6RtiuF+RQQiZWr8TZNyAcuVXyQRYfEO+MsoB/1BuQVhOJuoQ==
-
string_decoder@~1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.1.1.tgz#9cf1611ba62685d7030ae9e4ba34149c3af03fc8"
@@ -5631,16 +5589,6 @@ tar-stream@^1.5.2:
to-buffer "^1.1.1"
xtend "^4.0.0"
-three-custom-shader-material@^5.4.0:
- version "5.4.0"
- resolved "https://registry.yarnpkg.com/three-custom-shader-material/-/three-custom-shader-material-5.4.0.tgz#ee571c335a028a9b75c703b2ba83199176000847"
- integrity sha512-Yn1lFlKOk3Vul3npEGAmbbFUZ5S2+yjPgM2XqJEZEYRSUUH2vk+WVYrtTB6Bcq15wa7hLUXAKoctAvbRmBmbYA==
- dependencies:
- glsl-token-functions "^1.0.1"
- glsl-token-string "^1.0.1"
- glsl-tokenizer "^2.1.5"
- object-hash "^3.0.0"
-
three-mesh-bvh@^0.6.7:
version "0.6.8"
resolved "https://registry.yarnpkg.com/three-mesh-bvh/-/three-mesh-bvh-0.6.8.tgz#f27d18ca75bdc59316dff0f561af8fb316621a54"
@@ -5663,14 +5611,6 @@ three@^0.160.0:
resolved "https://registry.yarnpkg.com/three/-/three-0.160.0.tgz#cd1e4dbd01aee0719280a9086d75545db52b7a8f"
integrity sha512-DLU8lc0zNIPkM7rH5/e1Ks1Z8tWCGRq6g8mPowdDJpw1CFBJMU7UoJjC6PefXW7z//SSl0b2+GCw14LB+uDhng==
-through2@^0.6.3:
- version "0.6.5"
- resolved "https://registry.yarnpkg.com/through2/-/through2-0.6.5.tgz#41ab9c67b29d57209071410e1d7a7a968cd3ad48"
- integrity sha512-RkK/CCESdTKQZHdmKICijdKKsCRVHs5KsLZ6pACAmF/1GPUQhonHSXWNERctxEp7RmvjdNbZTL5z9V7nSCXKcg==
- dependencies:
- readable-stream ">=1.0.33-1 <1.1.0-0"
- xtend ">=4.0.0 <4.1.0-0"
-
through2@^4.0.0:
version "4.0.2"
resolved "https://registry.yarnpkg.com/through2/-/through2-4.0.2.tgz#a7ce3ac2a7a8b0b966c80e7c49f0484c3b239764"
@@ -6100,7 +6040,7 @@ ws@^8.14.2:
resolved "https://registry.yarnpkg.com/ws/-/ws-8.16.0.tgz#d1cd774f36fbc07165066a60e40323eab6446fd4"
integrity sha512-HS0c//TP7Ina87TfiPUz1rQzMhHrl/SG2guqRcTOIUYD2q8uhUdNHZYJUaQ8aTGPzCh+c6oawMKW35nFl1dxyQ==
-"xtend@>=4.0.0 <4.1.0-0", xtend@^4.0.0:
+xtend@^4.0.0:
version "4.0.2"
resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.2.tgz#bb72779f5fa465186b1f438f674fa347fdb5db54"
integrity sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==