mirror of
https://github.com/FMS-Cat/condition.git
synced 2025-08-17 19:06:42 +02:00
feature: add boundingbox, improve neuro section
This commit is contained in:
File diff suppressed because one or more lines are too long
119
src/entities/BoundingBox.ts
Normal file
119
src/entities/BoundingBox.ts
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
import { Entity } from '../heck/Entity';
|
||||||
|
import { InstancedGeometry } from '../heck/InstancedGeometry';
|
||||||
|
import { Material } from '../heck/Material';
|
||||||
|
import { Mesh } from '../heck/components/Mesh';
|
||||||
|
import { Vector3 } from '@fms-cat/experimental';
|
||||||
|
import { auto } from '../globals/automaton';
|
||||||
|
import { createSVGTableTexture } from '../utils/createSVGTableTexture';
|
||||||
|
import { dummyRenderTarget, dummyRenderTargetFourDrawBuffers } from '../globals/dummyRenderTarget';
|
||||||
|
import { gl, glCat } from '../globals/canvas';
|
||||||
|
import { objectValuesMap } from '../utils/objectEntriesMap';
|
||||||
|
import boundingBoxFrag from '../shaders/bounding-box.frag';
|
||||||
|
import boundingBoxVert from '../shaders/bounding-box.vert';
|
||||||
|
import { Geometry } from '../heck/Geometry';
|
||||||
|
|
||||||
|
export class BoundingBox extends Entity {
|
||||||
|
public constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
// -- create buffers ---------------------------------------------------------------------------
|
||||||
|
const arrayPos = [
|
||||||
|
-1, -1, -1,
|
||||||
|
1, -1, -1,
|
||||||
|
-1, 1, -1,
|
||||||
|
1, 1, -1,
|
||||||
|
-1, -1, 1,
|
||||||
|
1, -1, 1,
|
||||||
|
-1, 1, 1,
|
||||||
|
1, 1, 1,
|
||||||
|
];
|
||||||
|
const arrayInd = [
|
||||||
|
0, 1,
|
||||||
|
0, 2,
|
||||||
|
0, 4,
|
||||||
|
1, 3,
|
||||||
|
1, 5,
|
||||||
|
2, 3,
|
||||||
|
2, 6,
|
||||||
|
3, 7,
|
||||||
|
4, 5,
|
||||||
|
4, 6,
|
||||||
|
5, 7,
|
||||||
|
6, 7,
|
||||||
|
];
|
||||||
|
|
||||||
|
const bufferPos = glCat.createBuffer();
|
||||||
|
bufferPos.setVertexbuffer( new Float32Array( arrayPos ) );
|
||||||
|
|
||||||
|
const bufferInd = glCat.createBuffer();
|
||||||
|
bufferInd.setIndexbuffer( new Uint16Array( arrayInd ) );
|
||||||
|
|
||||||
|
// -- create geometry --------------------------------------------------------------------------
|
||||||
|
const geometry = new Geometry();
|
||||||
|
|
||||||
|
geometry.vao.bindVertexbuffer( bufferPos, 0, 3 );
|
||||||
|
geometry.vao.bindIndexbuffer( bufferInd );
|
||||||
|
|
||||||
|
geometry.count = 24;
|
||||||
|
geometry.mode = gl.LINES;
|
||||||
|
geometry.indexType = gl.UNSIGNED_SHORT;
|
||||||
|
|
||||||
|
// -- create materials -------------------------------------------------------------------------
|
||||||
|
const forward = new Material(
|
||||||
|
boundingBoxVert,
|
||||||
|
boundingBoxFrag,
|
||||||
|
{
|
||||||
|
defines: [ 'FORWARD 1' ],
|
||||||
|
initOptions: { geometry, target: dummyRenderTarget },
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const depth = new Material(
|
||||||
|
boundingBoxVert,
|
||||||
|
boundingBoxFrag,
|
||||||
|
{
|
||||||
|
defines: [ 'SHADOW 1' ],
|
||||||
|
initOptions: { geometry, target: dummyRenderTarget },
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const materials = { forward, cubemap: forward, depth };
|
||||||
|
|
||||||
|
objectValuesMap( materials, ( material ) => {
|
||||||
|
// auto( 'BoundingBox/phaseWidth', ( { value } ) => {
|
||||||
|
// material.addUniform( 'phaseWidth', '1f', value );
|
||||||
|
// } );
|
||||||
|
|
||||||
|
// auto( 'Sync/first/clap', ( { value } ) => {
|
||||||
|
// material.addUniform( 'phaseOffset', '1f', value );
|
||||||
|
// } );
|
||||||
|
|
||||||
|
// auto( 'BoundingBox/hahaRatio', ( { value } ) => {
|
||||||
|
// material.addUniform( 'hahaRatio', '1f', value );
|
||||||
|
// } );
|
||||||
|
} );
|
||||||
|
|
||||||
|
if ( process.env.DEV ) {
|
||||||
|
if ( module.hot ) {
|
||||||
|
module.hot.accept(
|
||||||
|
[
|
||||||
|
'../shaders/bounding-box.vert',
|
||||||
|
'../shaders/bounding-box.frag',
|
||||||
|
],
|
||||||
|
() => {
|
||||||
|
forward.replaceShader( boundingBoxVert, boundingBoxFrag );
|
||||||
|
depth.replaceShader( boundingBoxVert, boundingBoxFrag );
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// -- create meshes ----------------------------------------------------------------------------
|
||||||
|
const mesh = new Mesh( {
|
||||||
|
geometry,
|
||||||
|
materials,
|
||||||
|
name: process.env.DEV && 'BoundingBox/mesh',
|
||||||
|
} );
|
||||||
|
this.components.push( mesh );
|
||||||
|
}
|
||||||
|
}
|
@@ -22,7 +22,7 @@ export class LightsPink extends Entity {
|
|||||||
this.lights = ( [
|
this.lights = ( [
|
||||||
[ [ 6000.0, 10.0, 200.0 ], [ 8.0, 4.0, -8.0 ], true ],
|
[ [ 6000.0, 10.0, 200.0 ], [ 8.0, 4.0, -8.0 ], true ],
|
||||||
[ [ 6000.0, 10.0, 200.0 ], [ -8.0, 4.0, -8.0 ], true ],
|
[ [ 6000.0, 10.0, 200.0 ], [ -8.0, 4.0, -8.0 ], true ],
|
||||||
[ [ 30.0, 30.0, 30.0 ], [ 0.0, 4.0, 4.0 ], false ],
|
[ [ 10.0, 14.0, 20.0 ], [ 0.0, -4.0, 4.0 ], false ],
|
||||||
] as TypeScriptSucks ).map( ( [ color, pos, isSpot ], i ) => {
|
] as TypeScriptSucks ).map( ( [ color, pos, isSpot ], i ) => {
|
||||||
const light = new LightEntity( {
|
const light = new LightEntity( {
|
||||||
scenes,
|
scenes,
|
||||||
|
@@ -1,9 +1,10 @@
|
|||||||
|
import { BoundingBox } from './BoundingBox';
|
||||||
import { Entity } from '../heck/Entity';
|
import { Entity } from '../heck/Entity';
|
||||||
import { Geometry } from '../heck/Geometry';
|
import { Geometry } from '../heck/Geometry';
|
||||||
import { Lambda } from '../heck/components/Lambda';
|
import { Lambda } from '../heck/components/Lambda';
|
||||||
import { Material } from '../heck/Material';
|
import { Material } from '../heck/Material';
|
||||||
import { Mesh, MeshCull } from '../heck/components/Mesh';
|
import { Mesh, MeshCull } from '../heck/components/Mesh';
|
||||||
import { Vector3 } from '@fms-cat/experimental';
|
import { Quaternion, Vector3 } from '@fms-cat/experimental';
|
||||||
import { auto } from '../globals/automaton';
|
import { auto } from '../globals/automaton';
|
||||||
import { dummyRenderTarget, dummyRenderTargetFourDrawBuffers } from '../globals/dummyRenderTarget';
|
import { dummyRenderTarget, dummyRenderTargetFourDrawBuffers } from '../globals/dummyRenderTarget';
|
||||||
import { genOctahedron } from '../geometries/genOctahedron';
|
import { genOctahedron } from '../geometries/genOctahedron';
|
||||||
@@ -105,5 +106,16 @@ export class Wobbleball extends Entity {
|
|||||||
} );
|
} );
|
||||||
mesh.cull = MeshCull.None;
|
mesh.cull = MeshCull.None;
|
||||||
this.components.push( mesh );
|
this.components.push( mesh );
|
||||||
|
|
||||||
|
// -- bounding box -----------------------------------------------------------------------------
|
||||||
|
const boundingBox = new BoundingBox();
|
||||||
|
|
||||||
|
boundingBox.transform.rotation = Quaternion.fromAxisAngle(
|
||||||
|
new Vector3( [ 0.0, 0.0, 1.0 ] ),
|
||||||
|
0.25 * Math.PI,
|
||||||
|
);
|
||||||
|
boundingBox.transform.scale = new Vector3( [ 1.2, 1.2, 1.2 ] );
|
||||||
|
|
||||||
|
this.children.push( boundingBox );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
44
src/shaders/bounding-box.frag
Normal file
44
src/shaders/bounding-box.frag
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
#version 300 es
|
||||||
|
|
||||||
|
precision highp float;
|
||||||
|
|
||||||
|
#define saturate(i) clamp(i,0.,1.)
|
||||||
|
#define linearstep(a,b,x) saturate(((x)-(a))/((b)-(a)))
|
||||||
|
|
||||||
|
in vec4 vPositionWithoutModel;
|
||||||
|
in vec4 vPosition;
|
||||||
|
|
||||||
|
#ifdef FORWARD
|
||||||
|
out vec4 fragColor;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef SHADOW
|
||||||
|
out vec4 fragColor;
|
||||||
|
|
||||||
|
uniform vec2 cameraNearFar;
|
||||||
|
uniform vec3 cameraPos;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
uniform float time;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
float phase = vPositionWithoutModel.x + vPositionWithoutModel.y + vPositionWithoutModel.z;
|
||||||
|
float pattern = sin( phase * 40.0 + 10.0 * time );
|
||||||
|
|
||||||
|
if ( pattern < 0.0 ) {
|
||||||
|
discard;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef FORWARD
|
||||||
|
fragColor = vec4( 1.0 );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef SHADOW
|
||||||
|
float depth = linearstep(
|
||||||
|
cameraNearFar.x,
|
||||||
|
cameraNearFar.y,
|
||||||
|
length( cameraPos - vPosition.xyz )
|
||||||
|
);
|
||||||
|
fragColor = vec4( depth, depth * depth, depth, 1.0 );
|
||||||
|
#endif
|
||||||
|
}
|
22
src/shaders/bounding-box.vert
Normal file
22
src/shaders/bounding-box.vert
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#version 300 es
|
||||||
|
|
||||||
|
layout (location = 0) in vec3 position;
|
||||||
|
|
||||||
|
out vec4 vPositionWithoutModel;
|
||||||
|
out vec4 vPosition;
|
||||||
|
|
||||||
|
uniform vec2 resolution;
|
||||||
|
uniform mat4 projectionMatrix;
|
||||||
|
uniform mat4 viewMatrix;
|
||||||
|
uniform mat4 modelMatrix;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
vPositionWithoutModel = vec4( position, 1.0 );
|
||||||
|
vPosition = modelMatrix * vPositionWithoutModel;
|
||||||
|
|
||||||
|
vec4 outPos = projectionMatrix * viewMatrix * vPosition;
|
||||||
|
outPos.x *= resolution.y / resolution.x;
|
||||||
|
gl_Position = outPos;
|
||||||
|
|
||||||
|
vPosition.w = outPos.z / outPos.w;
|
||||||
|
}
|
@@ -55,7 +55,7 @@ vec3 ifs( vec3 p, vec3 r, vec3 t ) {
|
|||||||
mat3 bas = orthBasis( r );
|
mat3 bas = orthBasis( r );
|
||||||
|
|
||||||
for ( int i = 0; i < 6; i ++ ) {
|
for ( int i = 0; i < 6; i ++ ) {
|
||||||
p = abs( p ) - abs( s ) * pow( 1.7, -float( i ) );
|
p = abs( p ) - abs( s ) * pow( 1.8, -float( i ) );
|
||||||
|
|
||||||
s = bas * s;
|
s = bas * s;
|
||||||
|
|
||||||
@@ -72,32 +72,34 @@ float box( vec3 p, vec3 s ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
vec4 map( vec3 p ) {
|
vec4 map( vec3 p ) {
|
||||||
p.y += 10.0;
|
vec4 isect;
|
||||||
|
|
||||||
float d1, d2;
|
|
||||||
|
|
||||||
{
|
{
|
||||||
vec3 pt = p;
|
vec3 pt = p;
|
||||||
|
|
||||||
float clampbox = box( pt - vec3( 0.0, 10.0, 0.0 ), vec3( 1.0, 10.0, 1.0 ) - 0.1 );
|
float clampbox = box( pt, vec3( 1.0, 10.0, 1.0 ) );
|
||||||
|
|
||||||
|
pt.y += 10.0;
|
||||||
|
|
||||||
vec3 r = mix(
|
vec3 r = mix(
|
||||||
fs( vec3( 4.7, 2.2, 8.3 ) + floor( ifsSeed ) ),
|
fs( vec3( 4.7, 2.2, 8.3 ) + floor( ifsSeed ) ),
|
||||||
fs( vec3( 4.7, 2.2, 8.3 ) + floor( ifsSeed + 1.0 ) ),
|
fs( vec3( 4.7, 2.2, 8.3 ) + floor( ifsSeed + 1.0 ) ),
|
||||||
fract( ifsSeed )
|
fract( ifsSeed )
|
||||||
);
|
);
|
||||||
vec3 t = 0.1 * vec3( 3.0, 2.3, 3.5 );
|
vec3 t = 0.1 * vec3( 4.2, 3.5, 2.2 );
|
||||||
pt = ifs( pt, r, t );
|
pt = ifs( pt, r, t );
|
||||||
|
|
||||||
pt = mod( pt - 0.1, 0.2 ) - 0.1;
|
pt = mod( pt - 0.1, 0.2 ) - 0.1;
|
||||||
|
|
||||||
d1 = max( box( pt, vec3( 0.02 ) ), clampbox );
|
isect = vec4( max( box( pt, vec3( 0.04 ) ), clampbox ), 2, 0, 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
vec3 pt = p;
|
vec3 pt = p;
|
||||||
|
|
||||||
float clampbox = box( pt - vec3( 0.0, 10.0, 0.0 ), vec3( 1.0, 10.0, 1.0 ) );
|
float clampbox = box( pt, vec3( 1.0, 10.0, 1.0 ) - 0.1 );
|
||||||
|
|
||||||
|
pt.y += 10.0;
|
||||||
|
|
||||||
vec3 r = mix(
|
vec3 r = mix(
|
||||||
fs( vec3( 5.3, 1.1, 2.9 ) + floor( ifsSeed ) ),
|
fs( vec3( 5.3, 1.1, 2.9 ) + floor( ifsSeed ) ),
|
||||||
@@ -109,10 +111,20 @@ vec4 map( vec3 p ) {
|
|||||||
|
|
||||||
pt = mod( pt - 0.1, 0.2 ) - 0.1;
|
pt = mod( pt - 0.1, 0.2 ) - 0.1;
|
||||||
|
|
||||||
d2 = max( box( pt, vec3( 0.07 ) ), clampbox );
|
vec4 isectb = vec4( clampbox, 2, 0, 0 );
|
||||||
|
isect = isectb.x < isect.x ? isectb : isect;
|
||||||
}
|
}
|
||||||
|
|
||||||
return d1 < d2 ? vec4( d1, 1, 0, 0 ) : vec4( d2, 2, 0, 0 );
|
{
|
||||||
|
vec3 pt = abs( p );
|
||||||
|
|
||||||
|
float d = box( pt - vec3( 1.0, 0.0, 1.0 ), vec3( 0.02, 9.9, 0.02 ) );
|
||||||
|
|
||||||
|
vec4 isectb = vec4( d, 3, 0, 0 );
|
||||||
|
isect = isectb.x < isect.x ? isectb : isect;
|
||||||
|
}
|
||||||
|
|
||||||
|
return isect;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 normalFunc( vec3 p, float dd ) {
|
vec3 normalFunc( vec3 p, float dd ) {
|
||||||
@@ -159,7 +171,7 @@ void main() {
|
|||||||
fragNormal = vec4( modelNormal, 1.0 );
|
fragNormal = vec4( modelNormal, 1.0 );
|
||||||
|
|
||||||
if ( isect.y == 2.0 ) {
|
if ( isect.y == 2.0 ) {
|
||||||
vec3 noise = cyclicNoise( 6.0 * rayPos );
|
vec3 noise = cyclicNoise( 3.0 * rayPos );
|
||||||
vec3 noiseDetail = cyclicNoise( vec3( 38.0, 1.0, 1.0 ) * ( orthBasis( vec3( 1 ) ) * rayPos ) );
|
vec3 noiseDetail = cyclicNoise( vec3( 38.0, 1.0, 1.0 ) * ( orthBasis( vec3( 1 ) ) * rayPos ) );
|
||||||
float roughness = (
|
float roughness = (
|
||||||
0.6 +
|
0.6 +
|
||||||
@@ -167,11 +179,14 @@ void main() {
|
|||||||
0.2 * smoothstep( -0.2, 0.4, noise.y ) * ( 0.8 + 0.2 * sin( 17.0 * noiseDetail.x ) )
|
0.2 * smoothstep( -0.2, 0.4, noise.y ) * ( 0.8 + 0.2 * sin( 17.0 * noiseDetail.x ) )
|
||||||
);
|
);
|
||||||
|
|
||||||
fragColor = vec4( vec3( 0.04 ), 1.0 );
|
fragColor = vec4( vec3( 0.4 ), 1.0 );
|
||||||
fragWTF = vec4( vec3( roughness, 0.9, 0.0 ), 2 );
|
fragWTF = vec4( vec3( roughness, 0.9, 0.0 ), 2 );
|
||||||
} else if ( isect.y == 1.0 ) {
|
} else if ( isect.y == 1.0 ) {
|
||||||
fragColor = vec4( vec3( 1.0 ), 1.0 );
|
fragColor = vec4( vec3( 1.0 ), 1.0 );
|
||||||
fragWTF = vec4( vec3( 0.3, 0.1, 0.0 ), 2 );
|
fragWTF = vec4( vec3( 0.3, 0.1, 0.0 ), 2 );
|
||||||
|
} else if ( isect.y == 3.0 ) {
|
||||||
|
fragColor = vec4( vec3( 1.0, 0.001, 0.03 ), 1.0 );
|
||||||
|
fragWTF = vec4( vec3( 0.1, 0.1, 1.0 ), 2 );
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -132,7 +132,7 @@ void main() {
|
|||||||
discard;
|
discard;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 modelNormal = ( normalMatrix * vec4( normalFunc( rayPos, 1E-3 ), 1.0 ) ).xyz;
|
vec3 modelNormal = ( normalMatrix * vec4( normalFunc( rayPos, 1E-2 ), 1.0 ) ).xyz;
|
||||||
|
|
||||||
vec4 modelPos = modelMatrix * vec4( rayPos, 1.0 );
|
vec4 modelPos = modelMatrix * vec4( rayPos, 1.0 );
|
||||||
vec4 projPos = projectionMatrix * viewMatrix * modelPos; // terrible
|
vec4 projPos = projectionMatrix * viewMatrix * modelPos; // terrible
|
||||||
|
Reference in New Issue
Block a user