mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 03:29:51 +02:00
feat: simplified shaders
This commit is contained in:
1 parent
b8f6394d94
commit
7b6e291a0a
8 files changed
+38
-88
No files matched your search
@@ -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);
|
||||
}
|
||||
Reference in new issue
Block a user