feat: simplified shaders

This commit is contained in:
TrèsAbhi committed 2024-01-22 19:14:24 -06:00
1 parent b8f6394d94
commit 7b6e291a0a
8 files changed
+38 -88

No files matched your search

-1
View File
@@ -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",
@@ -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({
</mesh>
<mesh {...props} renderOrder={1}>
<ThreeCustomShaderMaterial
<shaderMaterial
ref={material}
silent
baseMaterial={MeshStandardMaterial}
transparent
depthWrite={false}
fragmentShader={fragmentShader}
vertexShader={vertexShader}
transparent
depthWrite={false}
uniforms={{
resolution: { value: null },
externalModuleMask: { value: null },
@@ -146,6 +143,11 @@ export function ArmorMesh({
explosionRadius: { value: initialShell.explosionRadius ?? 0 },
}}
/>
<meshBasicMaterial
transparent
color="#ff0000"
opacity={Math.random()}
/>
</mesh>
</>
);
@@ -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);
}
}
@@ -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);
}
@@ -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 && (
<mesh {...props} renderOrder={1}>
<ThreeCustomShaderMaterial
silent
baseMaterial={MeshStandardMaterial}
<shaderMaterial
fragmentShader={fragmentShader}
vertexShader={vertexShader}
uniforms={{
@@ -1,12 +1,15 @@
varying vec3 vCSMViewPosition;
#define PI 3.1415926535897932384626433832795
varying vec3 vViewPosition;
varying vec3 vNormal;
uniform float thickness;
uniform float maxThickness;
void main() {
vec3 normalizedNormal = normalize(vNormal);
vec3 normalizedViewPosition = normalize(vCSMViewPosition);
vec3 normalizedViewPosition = normalize(vViewPosition);
float dotProduct = dot(normalizedNormal, -normalizedViewPosition);
float angle = acos(dotProduct);
csm_FragColor = vec4(angle / (PI / 2.0), thickness / maxThickness, 0.0, 1.0);
gl_FragColor = vec4(angle / (PI / 2.0), thickness / maxThickness, 0.0, 1.0);
}
@@ -1,6 +1,10 @@
varying vec3 vCSMViewPosition;
varying vec3 vViewPosition;
varying vec3 vNormal;
void main() {
vec4 vViewPosition4 = modelViewMatrix * vec4(position, 1.0);
vCSMViewPosition = vViewPosition4.xyz;
vViewPosition = vViewPosition4.xyz;
vNormal = normalMatrix * normal;
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
+2 -62
View File
@@ -3893,23 +3893,6 @@ glsl-noise@^0.0.0:
resolved "https://registry.yarnpkg.com/glsl-noise/-/glsl-noise-0.0.0.tgz#367745f3a33382c0eeec4cb54b7e99cfc1d7670b"
integrity sha512-b/ZCF6amfAUb7dJM/MxRs7AetQEahYzJ8PtgfrmEdtw6uyGOr+ZSGtgjFm6mfsBkxJ4d2W7kg+Nlqzqvn3Bc0w==
glsl-token-functions@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/glsl-token-functions/-/glsl-token-functions-1.0.1.tgz#2f1614746b96e14f059a6d62af79b65457f0c9a0"
integrity sha512-EigGhp1g+aUVeUNY7H1o5tL/bnwIB3/FcRREPr2E7Du+/UDXN24hDkaZ3e4aWHDjHr9lJ6YHXMISkwhUYg9UOg==
glsl-token-string@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/glsl-token-string/-/glsl-token-string-1.0.1.tgz#59441d2f857de7c3449c945666021ece358e48ec"
integrity sha512-1mtQ47Uxd47wrovl+T6RshKGkRRCYWhnELmkEcUAPALWGTFe2XZpH3r45XAwL2B6v+l0KNsCnoaZCSnhzKEksg==
glsl-tokenizer@^2.1.5:
version "2.1.5"
resolved "https://registry.yarnpkg.com/glsl-tokenizer/-/glsl-tokenizer-2.1.5.tgz#1c2e78c16589933c274ba278d0a63b370c5fee1a"
integrity sha512-XSZEJ/i4dmz3Pmbnpsy3cKh7cotvFlBiZnDOwnj/05EwNp2XrhQ4XKJxT7/pDt4kp4YcpRSKz8eTV7S+mwV6MA==
dependencies:
through2 "^0.6.3"
gopd@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/gopd/-/gopd-1.0.1.tgz#29ff76de69dac7489b7c0918a5788e56477c332c"
@@ -4036,7 +4019,7 @@ inflight@^1.0.4:
once "^1.3.0"
wrappy "1"
inherits@2, [email protected], inherits@^2.0.3, inherits@~2.0.1, inherits@~2.0.3:
inherits@2, [email protected], inherits@^2.0.3, inherits@~2.0.3:
version "2.0.4"
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c"
integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==
@@ -4112,11 +4095,6 @@ is-stream@^1.1.0:
resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44"
integrity sha512-uQPm8kcs47jx38atAcWTVxyltQYoPT68y9aWYdV6yWXSyW8mzSat0TL6CiWdZeCdF3KrAvpVtnHbTv4RN+rqdQ==
[email protected]:
version "0.0.1"
resolved "https://registry.yarnpkg.com/isarray/-/isarray-0.0.1.tgz#8a18acfca9a8f4177e09abfc6038939b05d1eedf"
integrity sha512-D2S+3GLxWH+uhrNEcoh/fnmYeP8E8/zHl644d/jdA0g2uyXvy3sb0qxotE+ne0LtccHknQzWwZEzhak7oJ0COQ==
isarray@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11"
@@ -4660,11 +4638,6 @@ object-assign@^4.0.1, object-assign@^4.1.1:
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
integrity sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==
object-hash@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/object-hash/-/object-hash-3.0.0.tgz#73f97f753e7baffc0e2cc9d6e079079744ac82e9"
integrity sha512-RSn9F68PjH9HqtltsSnqYC1XXoWe9Bju5+213R98cNGttag9q9yAOTzdbsqvIa7aNm5WffBZFpWYr2aWrklWAw==
object-inspect@^1.9.0:
version "1.13.1"
resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.13.1.tgz#b96c6109324ccfef6b12216a956ca4dc2ff94bc2"
@@ -5115,16 +5088,6 @@ readable-stream@3, readable-stream@^3.0.0, readable-stream@^3.6.0:
string_decoder "^1.1.1"
util-deprecate "^1.0.1"
"readable-stream@>=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==