This commit is contained in:
FMS-Cat
2021-03-31 03:30:56 +09:00
parent 31b0354f4a
commit 0accfd3b63
28 changed files with 691 additions and 197 deletions

File diff suppressed because one or more lines are too long

View File

@@ -2,6 +2,7 @@ export const
RTINSPECTOR_MULTIPLE = false,
// RTINSPECTOR_MULTIPLE = true,
RTINSPECTOR_CAPTURE_NAME: string | null = null,
// RTINSPECTOR_CAPTURE_NAME: string | null = 'PixelSorter/index',
// RTINSPECTOR_CAPTURE_NAME: string | null = 'Bloom/swap1',
// RTINSPECTOR_CAPTURE_NAME: string | null = 'main/postSwap0',
// RTINSPECTOR_CAPTURE_NAME: string | null = 'DeferredCamera/cameraTarget',

View File

@@ -40,7 +40,7 @@ export class Bloom extends Entity {
this.components.push( new Blit( {
src: options.input,
dst: options.target,
name: 'Glitch/blitDry',
name: 'Bloom/blitDry',
} ) );
// -- down -------------------------------------------------------------------------------------

117
src/entities/Crystal.ts Normal file
View File

@@ -0,0 +1,117 @@
import { Entity } from '../heck/Entity';
import { Geometry } from '../heck/Geometry';
import { Lambda } from '../heck/components/Lambda';
import { Material } from '../heck/Material';
import { Mesh, MeshCull } from '../heck/components/Mesh';
import { Vector3 } from '@fms-cat/experimental';
import { auto } from '../globals/automaton';
import { dummyRenderTarget, dummyRenderTargetFourDrawBuffers } from '../globals/dummyRenderTarget';
import { genCube } from '../geometries/genCube';
import { objectValuesMap } from '../utils/objectEntriesMap';
import { randomTexture, randomTextureStatic } from '../globals/randomTexture';
import crystalFrag from '../shaders/crystal.frag';
import raymarchObjectVert from '../shaders/raymarch-object.vert';
interface CrystalOptions {
width: number;
height: number;
noiseOffset: number;
}
export class Crystal extends Entity {
public constructor( { width, height, noiseOffset }: CrystalOptions ) {
super();
this.transform.position = new Vector3( [ 0.0, 0.0, 0.0 ] );
this.transform.scale = new Vector3( [ 1.0, 1.0, 1.0 ] );
// -- geometry ---------------------------------------------------------------------------------
const cube = genCube( { dimension: [ width, height, width ] } );
const geometry = new Geometry();
geometry.vao.bindVertexbuffer( cube.position, 0, 3 );
geometry.vao.bindIndexbuffer( cube.index );
geometry.count = cube.count;
geometry.mode = cube.mode;
geometry.indexType = cube.indexType;
// -- materials --------------------------------------------------------------------------------
const deferred = new Material(
raymarchObjectVert,
crystalFrag,
{
defines: [ 'DEFERRED 1' ],
initOptions: { geometry, target: dummyRenderTargetFourDrawBuffers },
},
);
const depth = new Material(
raymarchObjectVert,
crystalFrag,
{
defines: [ 'SHADOW 1' ],
initOptions: { geometry, target: dummyRenderTarget }
},
);
const materials = { deferred, depth };
if ( process.env.DEV ) {
if ( module.hot ) {
module.hot.accept( '../shaders/crystal.frag', () => {
deferred.replaceShader( raymarchObjectVert, crystalFrag );
depth.replaceShader( raymarchObjectVert, crystalFrag );
} );
}
}
objectValuesMap( materials, ( material ) => {
material.addUniform( 'range', '4f', -1.0, -1.0, 1.0, 1.0 );
material.addUniform( 'size', '2f', width, height );
material.addUniform( 'noiseOffset', '1f', noiseOffset );
material.addUniformTexture( 'samplerRandom', randomTexture.texture );
material.addUniformTexture( 'samplerRandomStatic', randomTextureStatic.texture );
} );
// -- updater ----------------------------------------------------------------------------------
this.components.push( new Lambda( {
onDraw: ( event ) => {
objectValuesMap( materials, ( material ) => {
material.addUniform(
'cameraNearFar',
'2f',
event.camera.near,
event.camera.far
);
material.addUniformMatrixVector(
'inversePVM',
'Matrix4fv',
event.projectionMatrix
.multiply( event.viewMatrix )
.multiply( event.globalTransform.matrix )
.inverse!
.elements
);
material.addUniform( 'deformAmp', '1f', auto( 'Music/NEURO_WUB_AMP' ) );
material.addUniform( 'deformFreq', '1f', auto( 'Music/NEURO_WUB_FREQ' ) + auto( 'Music/NEURO_DETUNE' ) );
material.addUniform( 'deformTime', '1f', auto( 'Music/NEURO_TIME' ) );
} );
},
name: process.env.DEV && 'Crystal/updater',
} ) );
// -- mesh -------------------------------------------------------------------------------------
const mesh = new Mesh( {
geometry,
materials,
name: process.env.DEV && 'Crystal/mesh',
} );
mesh.cull = MeshCull.None;
this.components.push( mesh );
}
}

65
src/entities/DVi.ts Normal file
View File

@@ -0,0 +1,65 @@
import { Blit } from '../heck/components/Blit';
import { BufferRenderTarget } from '../heck/BufferRenderTarget';
import { Entity } from '../heck/Entity';
import { Material } from '../heck/Material';
import { Quad } from '../heck/components/Quad';
import { RenderTarget } from '../heck/RenderTarget';
import { dummyRenderTarget } from '../globals/dummyRenderTarget';
import { quadGeometry } from '../globals/quadGeometry';
import { randomTexture } from '../globals/randomTexture';
import dviFrag from '../shaders/dvi.frag';
import quadVert from '../shaders/quad.vert';
import { auto } from '../globals/automaton';
export interface DViOptions {
input: BufferRenderTarget;
target: RenderTarget;
}
export class DVi extends Entity {
public constructor( options: DViOptions ) {
super();
// -- bypass -----------------------------------------------------------------------------------
const blitBypass = new Blit( {
src: options.input,
dst: options.target,
name: 'DVi/blitBypass',
} );
// -- dvi --------------------------------------------------------------------------------------
const material = new Material(
quadVert,
dviFrag,
{ initOptions: { geometry: quadGeometry, target: dummyRenderTarget } },
);
material.addUniformTexture( 'sampler0', options.input.texture );
material.addUniformTexture( 'samplerRandom', randomTexture.texture );
if ( process.env.DEV ) {
if ( module.hot ) {
module.hot.accept( '../shaders/dvi.frag', () => {
material.replaceShader( quadVert, dviFrag );
} );
}
}
const quadDVi = new Quad( {
target: options.target,
material,
name: process.env.DEV && 'DVi/quad',
} );
// -- components -------------------------------------------------------------------------------
this.components.push(
blitBypass,
quadDVi,
);
// -- bypass auto ------------------------------------------------------------------------------
auto( 'DVi/active', ( { uninit } ) => {
quadDVi.active = !uninit;
blitBypass.active = !quadDVi.active;
} );
}
}

View File

@@ -15,6 +15,7 @@ import { randomTexture } from '../globals/randomTexture';
import aoFrag from '../shaders/ao.frag';
import quadVert from '../shaders/quad.vert';
import shadingFrag from '../shaders/shading.frag';
import { auto } from '../globals/automaton';
export interface DeferredCameraOptions {
scenes: Entity[];
@@ -26,10 +27,12 @@ export interface DeferredCameraOptions {
export class DeferredCamera extends Entity {
public cameraTarget: BufferRenderTarget;
public camera: PerspectiveCamera;
public constructor( options: DeferredCameraOptions ) {
super();
// -- camera -----------------------------------------------------------------------------------
this.cameraTarget = new BufferRenderTarget( {
width: options.target.width,
height: options.target.height,
@@ -38,7 +41,7 @@ export class DeferredCamera extends Entity {
filter: gl.NEAREST,
} );
const camera = new PerspectiveCamera( {
this.camera = new PerspectiveCamera( {
scenes: options.scenes,
renderTarget: this.cameraTarget,
near: 0.1,
@@ -46,8 +49,9 @@ export class DeferredCamera extends Entity {
name: 'DeferredCamera/camera',
materialTag: 'deferred',
} );
camera.clear = [];
this.camera.clear = [];
// -- ao ---------------------------------------------------------------------------------------
const aoTarget = new BufferRenderTarget( {
width: AO_RESOLUTION_RATIO * options.target.width,
height: AO_RESOLUTION_RATIO * options.target.height,
@@ -67,7 +71,7 @@ export class DeferredCamera extends Entity {
aoMaterial.addUniformMatrixVector(
'cameraPV',
'Matrix4fv',
camera.projectionMatrix.multiply(
this.camera.projectionMatrix.multiply(
cameraView
).elements
);
@@ -90,6 +94,7 @@ export class DeferredCamera extends Entity {
name: process.env.DEV && 'DeferredCamera/ao/quad',
} );
// -- deferred ---------------------------------------------------------------------------------
const shadingMaterial = new Material(
quadVert,
shadingFrag,
@@ -128,7 +133,7 @@ export class DeferredCamera extends Entity {
shadingMaterial.addUniformMatrixVector(
'cameraPV',
'Matrix4fv',
camera.projectionMatrix.multiply(
this.camera.projectionMatrix.multiply(
cameraView
).elements
);
@@ -136,8 +141,8 @@ export class DeferredCamera extends Entity {
shadingMaterial.addUniform(
'cameraNearFar',
'2f',
camera.near,
camera.far
this.camera.near,
this.camera.far
);
shadingMaterial.addUniform(
@@ -201,7 +206,7 @@ export class DeferredCamera extends Entity {
shadingMaterial.addUniformTexture( 'samplerRandom', randomTexture.texture );
this.components.push(
camera,
this.camera,
lambdaAoSetCameraUniforms,
aoQuad,
lambda,

View File

@@ -2,6 +2,7 @@ import { Entity } from '../heck/Entity';
import { GPUParticles } from './GPUParticles';
import { InstancedGeometry } from '../heck/InstancedGeometry';
import { Material } from '../heck/Material';
import { MeshCull } from '../heck/components/Mesh';
import { TRIANGLE_STRIP_QUAD } from '@fms-cat/experimental';
import { dummyRenderTarget } from '../globals/dummyRenderTarget';
import { gl, glCat } from '../globals/canvas';
@@ -118,6 +119,7 @@ export class FlickyParticles extends Entity {
computeNumBuffers: 1,
namePrefix: process.env.DEV && 'FlickyParticles',
} );
gpuParticles.meshRender.cull = MeshCull.None;
this.children.push( gpuParticles );
}
}

View File

@@ -10,10 +10,12 @@ export interface ForwardCameraOptions {
}
export class ForwardCamera extends Entity {
public camera: PerspectiveCamera;
public constructor( options: ForwardCameraOptions ) {
super();
const camera = new PerspectiveCamera( {
this.camera = new PerspectiveCamera( {
scenes: options.scenes,
renderTarget: options.target,
near: 0.1,
@@ -21,8 +23,8 @@ export class ForwardCamera extends Entity {
name: 'ForwardCamera/camera',
materialTag: 'forward',
} );
camera.clear = false;
this.camera.clear = false;
this.components.push( camera );
this.components.push( this.camera );
}
}

View File

@@ -20,6 +20,8 @@ export interface GPUParticlesOptions {
}
export class GPUParticles extends Entity {
public meshRender: Mesh;
public constructor( {
materialCompute,
geometryRender,
@@ -59,7 +61,7 @@ export class GPUParticles extends Entity {
} );
// -- render -----------------------------------------------------------------------------------
const meshRender = new Mesh( {
this.meshRender = new Mesh( {
geometry: geometryRender,
materials: materialsRender,
name: process.env.DEV && `${ namePrefix }/meshRender`,
@@ -101,7 +103,9 @@ export class GPUParticles extends Entity {
} ) );
// -- rest of components -----------------------------------------------------------------------
this.components.push( quadCompute );
this.components.push( meshRender );
this.components.push(
quadCompute,
this.meshRender,
);
}
}

View File

@@ -14,13 +14,14 @@ import lightShaftVert from '../shaders/light-shaft.vert';
interface LightShaftOptions {
light: LightEntity;
intensity?: number;
namePrefix?: string;
}
export class LightShaft extends Entity {
private __forward: Material;
public constructor( { light, namePrefix }: LightShaftOptions ) {
public constructor( { light, intensity, namePrefix }: LightShaftOptions ) {
super();
// -- geometry ---------------------------------------------------------------------------------
@@ -45,6 +46,8 @@ export class LightShaft extends Entity {
},
);
forward.addUniform( 'intensity', '1f', intensity ?? 0.01 );
forward.addUniformTexture( 'samplerRandom', randomTexture.texture );
forward.addUniformTexture( 'samplerShadow', light.shadowMap.texture );

View File

@@ -1,9 +1,7 @@
import { Entity } from '../heck/Entity';
import { InstancedGeometry } from '../heck/InstancedGeometry';
import { Lambda } from '../heck/components/Lambda';
import { Material } from '../heck/Material';
import { Mesh } from '../heck/components/Mesh';
import { Quaternion, Vector3 } from '@fms-cat/experimental';
import { dummyRenderTarget } from '../globals/dummyRenderTarget';
import { genTorus } from '../geometries/genTorus';
import { glCat } from '../globals/canvas';
@@ -17,15 +15,6 @@ export class Rings extends Entity {
public constructor() {
super();
const rot0 = Quaternion.fromAxisAngle(
new Vector3( [ 1.0, 0.0, 0.0 ] ),
0.4,
).multiply( Quaternion.fromAxisAngle(
new Vector3( [ 0.0, 0.0, 1.0 ] ),
0.4,
) );
this.transform.rotation = rot0;
// -- geometry ---------------------------------------------------------------------------------
const torus = genTorus( { segmentsRadial: 256 } );
@@ -47,7 +36,7 @@ export class Rings extends Entity {
geometry.primcount = PRIMCOUNT;
// -- materials --------------------------------------------------------------------------------
const forward = new Material(
const cubemap = new Material(
ringsVert,
ringsFrag,
{
@@ -72,7 +61,7 @@ export class Rings extends Entity {
);
const materials = {
forward,
cubemap,
deferred,
depth,
};
@@ -85,7 +74,7 @@ export class Rings extends Entity {
'../shaders/rings.frag',
],
() => {
forward.replaceShader( ringsVert, ringsFrag );
cubemap.replaceShader( ringsVert, ringsFrag );
deferred.replaceShader( ringsVert, ringsFrag );
depth.replaceShader( ringsVert, depthFrag );
},
@@ -100,18 +89,5 @@ export class Rings extends Entity {
name: process.env.DEV && 'Rings/mesh',
} );
this.components.push( mesh );
this.components.push( new Lambda( {
onUpdate: ( { time } ) => {
this.transform.rotation = rot0.multiply(
Quaternion.fromAxisAngle( new Vector3( [ 0.0, 1.0, 0.0 ] ), time )
).multiply(
Quaternion.fromAxisAngle( new Vector3( [ 1.0, 0.0, 0.0 ] ), 1.0 )
).multiply(
Quaternion.fromAxisAngle( new Vector3( [ 0.0, 0.0, 1.0 ] ), 1.0 )
);
},
name: process.env.DEV && 'Rings/speen',
} ) );
}
}

View File

@@ -1,46 +1,43 @@
import { Condition } from './Condition';
import { Cube } from './Cube';
import { Entity } from '../heck/Entity';
import { LightEntity } from './LightEntity';
import { Vector3 } from '@fms-cat/experimental';
interface LightsFirstOptions {
scenes: Entity[];
}
export class LightsFirst extends Entity {
export class SceneBegin extends Entity {
public readonly lights: LightEntity[];
public constructor( { scenes }: LightsFirstOptions ) {
public constructor() {
super();
// -- 1 ----------------------------------------------------------------------------------------
// -- lights -----------------------------------------------------------------------------------
const light1 = new LightEntity( {
scenes,
scenes: [ this ],
shadowMapFov: 30.0,
shadowMapNear: 1.0,
shadowMapFar: 20.0,
namePrefix: process.env.DEV && 'lightFirst',
namePrefix: process.env.DEV && 'lightBegin1',
} );
light1.color = [ 400.0, 400.0, 400.0 ];
light1.color = [ 200.0, 200.0, 200.0 ];
light1.transform.lookAt( new Vector3( [ 4.0, 4.0, 4.0 ] ) );
this.children.push( light1 );
// -- 2 ----------------------------------------------------------------------------------------
const light2 = new LightEntity( {
scenes,
scenes: [ this ],
shadowMapFov: 30.0,
shadowMapNear: 1.0,
shadowMapFar: 20.0,
namePrefix: process.env.DEV && 'lightFirst',
namePrefix: process.env.DEV && 'lightBegin2',
} );
light2.color = [ 100.0, 140.0, 200.0 ];
light2.color = [ 80.0, 90.0, 100.0 ];
light2.transform.lookAt( new Vector3( [ -4.0, 0.0, -4.0 ] ) );
this.children.push( light2 );
// -- haha -------------------------------------------------------------------------------------
this.lights = [ light1, light2 ];
// -- scene ------------------------------------------------------------------------------------
this.children.push(
new Cube(),
new Condition(),
...this.lights,
);
}
}

View File

@@ -0,0 +1,41 @@
import { Crystal } from './Crystal';
import { Entity } from '../heck/Entity';
import { Lambda } from '../heck/components/Lambda';
import { Quaternion, Vector3 } from '@fms-cat/experimental';
import { Rings } from './Rings';
export class SceneCrystals extends Entity {
public constructor() {
super();
const crystal = new Crystal( { width: 0.4, height: 1.5, noiseOffset: 7.0 } );
this.children.push( crystal );
const speen = new Entity();
this.children.push( speen );
const up = new Vector3( [ 0.0, 1.0, 0.0 ] );
this.components.push( new Lambda( {
onUpdate: ( { time } ) => {
speen.transform.rotation = Quaternion.fromAxisAngle( up, time );
},
} ) );
for ( let i = 0; i < 3; i ++ ) {
const smolCrystal = new Crystal( { width: 0.2, height: 0.8, noiseOffset: i } );
const t = Math.PI * i / 1.5;
smolCrystal.transform.position = new Vector3( [ Math.cos( t ), 0.0, Math.sin( t ) ] );
speen.children.push( smolCrystal );
}
const rings = new Rings();
rings.transform.rotation = Quaternion.fromAxisAngle(
new Vector3( [ 1.0, 0.0, 0.0 ] ),
0.1,
).multiply( Quaternion.fromAxisAngle(
new Vector3( [ 0.0, 0.0, 1.0 ] ),
0.1,
) );
this.children.push( rings );
}
}

View File

@@ -1,31 +1,32 @@
import { BoundingBox } from './BoundingBox';
import { BufferRenderTarget } from '../heck/BufferRenderTarget';
import { Entity } from '../heck/Entity';
import { IFSPistons } from './IFSPistons';
import { LightEntity } from './LightEntity';
import { LightShaft } from './LightShaft';
import { Vector3 } from '@fms-cat/experimental';
import { Quaternion, Vector3 } from '@fms-cat/experimental';
import { SufferTexts } from './SufferTexts';
import { Wobbleball } from './Wobbleball';
interface LightsPinkOptions {
scenes: Entity[];
}
export class LightsPink extends Entity {
export class SceneNeuro extends Entity {
public readonly lights: LightEntity[];
private readonly __shafts: LightShaft[];
public constructor( { scenes }: LightsPinkOptions ) {
public constructor() {
super();
// -- lights -----------------------------------------------------------------------------------
type TypeScriptSucks = [ [ number, number, number ], [ number, number, number ], boolean ][];
this.__shafts = [];
this.lights = ( [
[ [ 6000.0, 40.0, 200.0 ], [ 8.0, 4.0, -8.0 ], true ],
[ [ 6000.0, 40.0, 200.0 ], [ -8.0, 4.0, -8.0 ], true ],
[ [ 10.0, 14.0, 20.0 ], [ 0.0, -4.0, 4.0 ], false ],
[ [ 2000.0, 20.0, 100.0 ], [ 8.0, 4.0, -8.0 ], true ],
[ [ 2000.0, 20.0, 100.0 ], [ -8.0, 4.0, -8.0 ], true ],
[ [ 50.0, 50.0, 50.0 ], [ 0.0, -4.0, 4.0 ], false ],
] as TypeScriptSucks ).map( ( [ color, pos, isSpot ], i ) => {
const light = new LightEntity( {
scenes,
scenes: [ this ],
shadowMapFov: isSpot ? 15.0 : 50.0,
shadowMapNear: 0.5,
shadowMapFar: 20.0,
@@ -34,11 +35,9 @@ export class LightsPink extends Entity {
} );
light.color = color;
light.spotness = isSpot ? 0.9 : 0.0;
light.spotness = isSpot ? 0.99 : 0.0;
light.transform.lookAt( new Vector3( pos ) );
this.children.push( light );
if ( isSpot ) {
const shaft = new LightShaft( {
light,
@@ -51,6 +50,23 @@ export class LightsPink extends Entity {
return light;
} );
// -- 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 ] );
// -- scene ------------------------------------------------------------------------------------
this.children.push(
new Wobbleball(),
new IFSPistons(),
boundingBox,
new SufferTexts(),
...this.lights,
);
}
public setDefferedCameraTarget( deferredCameraTarget: BufferRenderTarget ): void {

View File

@@ -1,10 +1,9 @@
import { BoundingBox } from './BoundingBox';
import { Entity } from '../heck/Entity';
import { Geometry } from '../heck/Geometry';
import { Lambda } from '../heck/components/Lambda';
import { Material } from '../heck/Material';
import { Mesh, MeshCull } from '../heck/components/Mesh';
import { Quaternion, Vector3 } from '@fms-cat/experimental';
import { Vector3 } from '@fms-cat/experimental';
import { auto } from '../globals/automaton';
import { dummyRenderTarget, dummyRenderTargetFourDrawBuffers } from '../globals/dummyRenderTarget';
import { genOctahedron } from '../geometries/genOctahedron';
@@ -106,16 +105,5 @@ export class Wobbleball extends Entity {
} );
mesh.cull = MeshCull.None;
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 );
}
}

View File

@@ -16,9 +16,32 @@ export interface PerspectiveCameraOptions extends ComponentOptions {
}
export class PerspectiveCamera extends Camera {
public readonly fov: number;
public readonly near: number;
public readonly far: number;
public get fov(): number {
return this.__fov;
}
public set fov( value: number ) {
this.__fov = value;
this.__updatePerspectiveCamera();
}
private __fov: number;
public get near(): number {
return this.__near;
}
public set near( value: number ) {
this.__near = value;
this.__updatePerspectiveCamera();
}
private __near: number;
public get far(): number {
return this.__far;
}
public set far( value: number ) {
this.__far = value;
this.__updatePerspectiveCamera();
}
private __far: number;
public constructor( options: PerspectiveCameraOptions ) {
const fov = options.fov ?? 45.0;
@@ -35,8 +58,12 @@ export class PerspectiveCamera extends Camera {
clear: options.clear,
} );
this.fov = fov;
this.near = near;
this.far = far;
this.__fov = fov;
this.__near = near;
this.__far = far;
}
protected __updatePerspectiveCamera(): void {
this.projectionMatrix = Matrix4.perspective( this.fov, this.near, this.far );
}
}

View File

@@ -110,7 +110,7 @@ vec2 deepkick( float t ) {
vec2 tt = t + mix( 0.0, 0.007, smoothstep( 0.0, 0.1, t ) ) * wavetable( 0.1 * t, vec2( 2.0 ), vec2( -0.1 ) );
vec2 phase = 50.0 * tt - 3.0 * exp( -100.0 * tt ) - 5.4 * exp( -30.0 * tt );
return exp( -1.0 * tt ) * sin( TAU * phase );
return exp( -0.4 * tt ) * sin( TAU * phase );
}
vec2 longclap( float t, float tg ) {
@@ -612,7 +612,7 @@ vec2 mainAudio( vec4 time ) {
t += 1.0 * inRangeInteg( time.z, 28.0 * BEAT, 31.75 * BEAT, 50.0 );
float freq = n2f( chordsB[ progB ] ) * 0.125;
float fadetime = max( 0.0, time.w - SECTION_AAAA + 8.0 * BEAT );
dest += 0.12 * exp( -1.0 * fadetime ) * mix( 0.1, 1.0, sidechain ) * superbass( t, freq, exp( -2.0 * fadetime ) );
dest += 0.11 * exp( -1.0 * fadetime ) * mix( 0.1, 1.0, sidechain ) * superbass( t, freq, exp( -2.0 * fadetime ) );
}
// -- choir --------------------------------------------------------------------------------------
@@ -687,12 +687,12 @@ vec2 mainAudio( vec4 time ) {
sum += 0.1 * mix( 0.2, 1.0, sidechain ) * phase;
}
dest += 0.12 * aSaturate( sum );
dest += 0.14 * aSaturate( sum );
}
// -- deepkick -----------------------------------------------------------------------------------
if ( inRange( time.w, SECTION_BEGIN, SECTION_BEGIN + 16.0 * BEAT ) ) {
dest += 0.3 * deepkick( mod( time.z, 16.0 * BEAT ) );
if ( inRange( time.w, SECTION_BEGIN, SECTION_BEGIN + 64.0 * BEAT ) ) {
dest += 0.3 * deepkick( time.z );
}
if ( inRange( time.w, SECTION_AAAA - 8.0 * BEAT, SECTION_AAAA ) ) {

View File

@@ -3,9 +3,8 @@ import { Bloom } from './entities/Bloom';
import { BufferRenderTarget } from './heck/BufferRenderTarget';
import { CanvasRenderTarget } from './heck/CanvasRenderTarget';
import { Component } from './heck/components/Component';
import { Condition } from './entities/Condition';
import { Cube } from './entities/Cube';
import { CubemapCameraEntity } from './entities/CubemapCameraEntity';
import { DVi } from './entities/DVi';
import { DeferredCamera } from './entities/DeferredCamera';
import { Dog } from './heck/Dog';
import { Entity } from './heck/Entity';
@@ -15,20 +14,17 @@ import { FlickyParticles } from './entities/FlickyParticles';
import { ForwardCamera } from './entities/ForwardCamera';
import { Glitch } from './entities/Glitch';
import { IBLLUT } from './entities/IBLLUT';
import { IFSPistons } from './entities/IFSPistons';
import { Lambda } from './heck/components/Lambda';
import { LightsFirst } from './entities/LightsFirst';
import { LightsPink } from './entities/LightsPink';
import { PixelSorter } from './entities/PixelSorter';
import { Post } from './entities/Post';
import { RTInspector } from './entities/RTInspector';
import { Rings } from './entities/Rings';
import { SceneBegin } from './entities/SceneBegin';
import { SceneCrystals } from './entities/SceneCrystals';
import { SceneNeuro } from './entities/SceneNeuro';
import { Serial } from './entities/Serial';
import { SphereParticles } from './entities/SphereParticles';
import { SufferTexts } from './entities/SufferTexts';
import { Swap, Vector3 } from '@fms-cat/experimental';
import { Trails } from './entities/Trails';
import { Wobbleball } from './entities/Wobbleball';
import { arraySetDelete } from './utils/arraySetDelete';
import { auto, automaton } from './globals/automaton';
import { music } from './globals/music';
@@ -109,13 +105,6 @@ if ( process.env.DEV && module.hot ) {
} );
}
const replacerCondition = new EntityReplacer( deferredRoot, () => new Condition(), 'Condition' );
if ( process.env.DEV && module.hot ) {
module.hot.accept( './entities/Condition', () => {
replacerCondition.replace();
} );
}
const replacerFlashyTerrain = new EntityReplacer(
deferredRoot,
() => new FlashyTerrain(),
@@ -134,31 +123,29 @@ if ( process.env.DEV && module.hot ) {
} );
}
const replacerRings = new EntityReplacer( deferredRoot, () => new Rings(), 'Rings' );
const replacerSceneBegin = new EntityReplacer( deferredRoot, () => new SceneBegin(), 'SceneBegin' );
if ( process.env.DEV && module.hot ) {
module.hot.accept( './entities/Rings', () => {
replacerRings.replace();
module.hot.accept( './entities/SceneBegin', () => {
replacerSceneBegin.current.lights.map( ( light ) => arraySetDelete( lights, light ) );
replacerSceneBegin.replace();
lights.push( ...replacerSceneBegin.current.lights );
} );
}
const replacerCube = new EntityReplacer( deferredRoot, () => new Cube(), 'Cube' );
const replacerSceneNeuro = new EntityReplacer( deferredRoot, () => new SceneNeuro(), 'SceneNeuro' );
if ( process.env.DEV && module.hot ) {
module.hot.accept( './entities/Cube', () => {
replacerCube.replace();
module.hot.accept( './entities/SceneNeuro', () => {
replacerSceneNeuro.current.lights.map( ( light ) => arraySetDelete( lights, light ) );
replacerSceneNeuro.replace();
lights.push( ...replacerSceneNeuro.current.lights );
replacerSceneNeuro.current.setDefferedCameraTarget( deferredCamera.cameraTarget );
} );
}
const replacerWobbleball = new EntityReplacer( deferredRoot, () => new Wobbleball(), 'Wobbleball' );
const replacerSceneCrystals = new EntityReplacer( deferredRoot, () => new SceneCrystals(), 'SceneCrystals' );
if ( process.env.DEV && module.hot ) {
module.hot.accept( './entities/Wobbleball', () => {
replacerWobbleball.replace();
} );
}
const replacerIFSPistons = new EntityReplacer( deferredRoot, () => new IFSPistons(), 'IFSPistons' );
if ( process.env.DEV && module.hot ) {
module.hot.accept( './entities/IFSPistons', () => {
replacerIFSPistons.replace();
module.hot.accept( './entities/SceneCrystals', () => {
replacerSceneCrystals.replace();
} );
}
@@ -166,17 +153,6 @@ if ( process.env.DEV && module.hot ) {
const forwardRoot = new Entity();
dog.root.children.push( forwardRoot );
const replacerSufferTexts = new EntityReplacer(
forwardRoot,
() => new SufferTexts(),
'SufferTexts',
);
if ( process.env.DEV && module.hot ) {
module.hot.accept( './entities/SufferTexts', () => {
replacerSufferTexts.replace();
} );
}
const replacerFlickyParticles = new EntityReplacer(
forwardRoot,
() => new FlickyParticles(),
@@ -205,23 +181,9 @@ const swap = new Swap(
} ),
);
const replacerLightsFirst = new EntityReplacer(
dog.root,
() => new LightsFirst( { scenes: [ dog.root ] } ),
'LightsFirst',
);
const replacerLightsPink = new EntityReplacer(
dog.root,
() => new LightsPink( {
scenes: [ dog.root ],
} ),
'LightsPink',
);
const lights = [
...replacerLightsFirst.current.lights,
...replacerLightsPink.current.lights,
...replacerSceneBegin.current.lights,
...replacerSceneNeuro.current.lights,
];
// const light2 = new LightEntity( {
@@ -255,7 +217,7 @@ const deferredCamera = new DeferredCamera( {
textureEnv: environmentMap.texture,
} );
dog.root.children.push( deferredCamera );
replacerLightsPink.current.setDefferedCameraTarget( deferredCamera.cameraTarget );
replacerSceneNeuro.current.setDefferedCameraTarget( deferredCamera.cameraTarget );
const forwardCamera = new ForwardCamera( {
scenes: [ dog.root ],
@@ -314,6 +276,10 @@ dog.root.components.push( new Lambda( {
] ).scale( shake )
);
}
auto( 'Camera/fov', ( { value } ) => {
camera.camera.fov = 90.0 * value;
} );
} );
},
name: process.env.DEV && 'main/updateCamera',
@@ -355,6 +321,13 @@ const serial = new Serial( {
} );
dog.root.children.push( serial );
swap.swap();
const dvi = new DVi( {
input: swap.i,
target: swap.o,
} );
dog.root.children.push( dvi );
swap.swap();
const post = new Post( {
input: swap.i,

136
src/shaders/crystal.frag Normal file
View File

@@ -0,0 +1,136 @@
#version 300 es
precision highp float;
#define fs(i) (fract(sin((i)*114.514)*1919.810))
#define saturate(x) clamp(x,0.,1.)
#define linearstep(a,b,x) saturate(((x)-(a))/((b)-(a)))
const int MARCH_ITER = 90;
const float PI = 3.14159265;
const float TAU = PI * 2.0;
const float foldcos = cos( PI / 5.0 );
const float foldrem = sqrt( 0.75 - foldcos * foldcos );
const vec3 foldvec = vec3( -0.5, -foldcos, foldrem );
const vec3 foldface = vec3( 0.0, foldrem, foldcos );
#ifdef DEFERRED
layout (location = 0) out vec4 fragPosition;
layout (location = 1) out vec4 fragNormal;
layout (location = 2) out vec4 fragColor;
layout (location = 3) out vec4 fragWTF;
#endif
in vec4 vPositionWithoutModel;
#ifdef SHADOW
out vec4 fragColor;
#endif
uniform float deformAmp;
uniform float deformFreq;
uniform float deformTime;
uniform float time;
uniform float noiseOffset;
uniform vec2 resolution;
uniform vec2 size;
uniform vec2 cameraNearFar;
uniform vec3 cameraPos;
uniform mat4 normalMatrix;
uniform mat4 modelMatrix;
uniform mat4 viewMatrix;
uniform mat4 projectionMatrix;
uniform mat4 inversePVM;
uniform sampler2D samplerRandom;
uniform sampler2D samplerRandomStatic;
uniform sampler2D samplerCapture;
vec3 divideByW( vec4 v ) {
return v.xyz / v.w;
}
// https://www.iquilezles.org/www/articles/smin/smin.htm
float smin( float a, float b, float k ) {
float h = max( k - abs( a - b ), 0.0 ) / k;
return min( a, b ) - h * h * h * k * ( 1.0 / 6.0 );
}
mat2 rot2d( float t ) {
float c = cos( t );
float s = sin( t );
return mat2( c, -s, s, c );
}
#pragma glslify: cyclicNoise = require( ./modules/cyclicNoise );
vec3 fold( vec3 p ) {
for ( int i = 0; i < 5; i ++ ) {
p.xy = abs( p.xy );
p -= 2.0 * min( dot( foldvec, p ), 0.0 ) * foldvec;
}
return p;
}
float distFunc( vec3 p ) {
p.zx = rot2d( 0.5 * time ) * p.zx;
p -= size.xyx * vec3( 0.01, 0.2, 0.01 ) * cyclicNoise( vec3( 1.0, 0.04, 1.0 ) / size.xyx * p + noiseOffset );
p.y -= min( 0.8 * size.y - size.x, abs( p.y ) ) * sign( p.y );
p = fold( p );
return dot( p, foldface ) - size.x;
}
vec3 normalFunc( vec3 p, float dd ) {
vec2 d = vec2( 0.0, dd );
return normalize( vec3(
distFunc( p + d.yxx ) - distFunc( p - d.yxx ),
distFunc( p + d.xyx ) - distFunc( p - d.xyx ),
distFunc( p + d.xxy ) - distFunc( p - d.xxy )
) );
}
void main() {
vec2 p = ( gl_FragCoord.xy * 2.0 - resolution ) / resolution.y;
vec3 rayOri = divideByW( inversePVM * vec4( p, 0.0, 1.0 ) );
vec3 farPos = divideByW( inversePVM * vec4( p, 1.0, 1.0 ) );
vec3 rayDir = normalize( farPos - rayOri );
float rayLen = length( vPositionWithoutModel.xyz - rayOri );
vec3 rayPos = rayOri + rayDir * rayLen;
float dist;
for ( int i = 0; i < MARCH_ITER; i ++ ) {
dist = distFunc( rayPos );
rayLen += 0.5 * dist;
rayPos = rayOri + rayDir * rayLen;
if ( abs( dist ) < 1E-3 ) { break; }
if ( rayLen > cameraNearFar.y ) { break; }
}
if ( 0.01 < dist ) {
discard;
}
vec3 modelNormal = ( normalMatrix * vec4( normalFunc( rayPos, 1E-2 ), 1.0 ) ).xyz;
vec4 modelPos = modelMatrix * vec4( rayPos, 1.0 );
vec4 projPos = projectionMatrix * viewMatrix * modelPos; // terrible
float depth = projPos.z / projPos.w;
gl_FragDepth = 0.5 + 0.5 * depth;
#ifdef DEFERRED
fragPosition = vec4( modelPos.xyz, depth );
fragNormal = vec4( modelNormal, 1.0 );
fragColor = vec4( vec3( 0.5, 0.52, 1.0 ), 1.0 );
fragWTF = vec4( vec3( 0.02, 1.0, 0.0 ), 3 );
#endif
#ifdef SHADOW
float shadowDepth = linearstep(
cameraNearFar.x,
cameraNearFar.y,
length( cameraPos - rayPos )
);
fragColor = vec4( shadowDepth, shadowDepth * shadowDepth, shadowDepth, 1.0 );
#endif
}

111
src/shaders/dvi.frag Normal file
View File

@@ -0,0 +1,111 @@
#version 300 es
precision highp float;
const float PI = 3.14159265;
const vec3 LUMA = vec3( 0.2126, 0.7152, 0.0722 );
#define saturate(i) clamp(i,0.,1.)
#define linearstep(a,b,x) saturate(((x)-(a))/((b)-(a)))
#define lofi(i,m) (floor((i)/(m))*(m))
in vec2 vUv;
out vec4 fragColor;
uniform float time;
uniform vec2 resolution;
uniform sampler2D sampler0;
mat2 r2d( float t ) {
return mat2( cos( t ), sin( t ), -sin( t ), cos( t ) );
}
float smin(float a,float b,float k){
float h = linearstep( k, 0.0, abs( a - b ) );
return min( a, b ) - h * h * h * k / 6.0;
}
float dRadial(
vec2 p,
float offr,
float repr,
float exr,
float offx,
float exx,
float r
) {
p = r2d( offr ) * p;
float a = atan( p.y, p.x );
p = r2d( -lofi( a + repr / 2.0, repr ) ) * p;
a = atan( p.y, p.x );
p = r2d( -sign( a ) * min( abs( a ), exr ) ) * p;
p.x -= offx;
p.x -= sign( p.x ) * min( abs( p.x ), exx );
float d = length( p ) - r;
return d;
}
float sdbox( vec2 p,vec2 d ) {
vec2 pt = abs( p ) - d;
return min( max( pt.x, pt.y ), 0.0 ) + length( max( pt, 0.0 ) );
}
float dCirc( vec2 p ) {
return max( length( p ) - 0.02, 0.018 - length( p ) );
}
float dOverlay( vec2 p ) {
float d = 1E9;
float t = time;
// center bar
d = min( d, sdbox( p, vec2( 0.12, 0.002 ) ) );
// circles
{
vec2 pt = abs( p );
d = min( d, dCirc( pt - vec2( 0.0, 0.05 ) ) );
d = min( d, dCirc( pt - vec2( 0.07, 0.05 ) ) );
d = min( d, dCirc( pt - vec2( 0.035, 0.05 + 0.035 * sqrt( 3.0 ) ) ) );
}
// rings
{
float d2 = 1E9;
d2 = smin( d2, dRadial( p, 0.1 * t, PI / 2.0, PI / 8.0, 0.7, 0.0, 0.02 ), 0.05 );
d2 = smin( d2, dRadial( p, 0.1 * t + PI / 4.0, PI / 2.0, PI / 8.0, 0.72, 0.0, 0.02 ), 0.05 );
d = min( d2, d );
}
d = min( d, dRadial( p, 0.1 * t, PI / 8.0, PI / 19.0, 0.76, 0.002, 0.0 ) );
d = min( d, dRadial( p, -0.1 * t, PI / 8.0, PI / 9.0, 0.78, 0.01, 0.0 ) );
d = min( d, dRadial( p, 0.04 * t, PI / 48.0, 0.002, 0.815, 0.008, 0.0 ) );
d = min( d, dRadial( p, 0.04 * t, PI / 192.0, 0.002, 0.815, 0.002, 0.0 ) );
{
float d2 = 1E9;
d2 = smin( d2, dRadial( p, 0.1 * t, PI / 1.5, PI / 8.0, 0.86, 0.0, 0.02 ), 0.05 );
d2 = smin( d2, dRadial( p, 0.1 * t + PI / 4.0, PI / 1.5, PI, 0.88, 0.0, 0.02 ), 0.05 );
d = min( d2, d );
}
d = min( d, dRadial( p, 0.2 * t, PI / 2.0, PI / 4.2, 0.915, 0.002, 0.0 ) );
d = min( d, dRadial( p, -.1 * t, PI / 4.0, PI / 8.5, 0.94, 0.01, 0.0 ) );
d = min( d, dRadial( p, 0.04 * t, PI / 96.0, 0.002, 0.99, 0.03, 0.0 ) );
return d;
}
void main() {
vec2 uv = vUv;
vec2 p = ( uv * resolution * 2.0 - resolution ) / resolution.y;
vec3 col = texture( sampler0, uv ).rgb;
float d = dOverlay( p * 0.65 );
float shape = linearstep( 2.0 / resolution.y, 0.0, d );
col = mix( col, saturate( 0.5 - 0.3 * col.gbr ), shape );
fragColor = vec4( col, 1.0 );
}

View File

@@ -41,6 +41,12 @@ vec3 divideByW( vec4 v ) {
return v.xyz / v.w;
}
// https://www.iquilezles.org/www/articles/smin/smin.htm
float smin( float a, float b, float k ) {
float h = max( k - abs( a - b ), 0.0 ) / k;
return min( a, b ) - h * h * h * k * ( 1.0 / 6.0 );
}
mat2 rot2d( float t ) {
float c = cos( t );
float s = sin( t );
@@ -54,7 +60,7 @@ vec3 ifs( vec3 p, vec3 r, vec3 t ) {
vec3 s = t;
mat3 bas = orthBasis( r );
for ( int i = 0; i < 6; i ++ ) {
for ( int i = 0; i < 5; i ++ ) {
p = abs( p ) - abs( s ) * pow( 1.8, -float( i ) );
s = bas * s;
@@ -82,8 +88,8 @@ vec4 map( vec3 p ) {
pt.y += 10.0;
vec3 r = mix(
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, 3.2, 4.3 ) + floor( ifsSeed ) ),
fs( vec3( 4.7, 3.2, 4.3 ) + floor( ifsSeed + 1.0 ) ),
fract( ifsSeed )
);
vec3 t = 0.1 * vec3( 4.2, 3.5, 2.2 );
@@ -91,19 +97,21 @@ vec4 map( vec3 p ) {
pt = mod( pt - 0.1, 0.2 ) - 0.1;
isect = vec4( max( box( pt, vec3( 0.04 ) ), clampbox ), 2, 0, 0 );
float d = max( box( pt, vec3( 0.05 ) ), clampbox );
isect = vec4( d, 2, 0, 0 );
}
{
vec3 pt = p;
float clampbox = box( pt, vec3( 1.0, 10.0, 1.0 ) - 0.1 );
float clampbox = box( pt, vec3( 1.0, 10.0, 1.0 ) - 0.02 );
pt.y += 10.0;
vec3 r = mix(
fs( vec3( 5.3, 1.1, 2.9 ) + floor( ifsSeed ) ),
fs( vec3( 5.3, 1.1, 2.9 ) + floor( ifsSeed + 1.0 ) ),
fs( vec3( 5.3, 1.9, 3.9 ) + floor( ifsSeed ) ),
fs( vec3( 5.3, 1.9, 3.9 ) + floor( ifsSeed + 1.0 ) ),
fract( ifsSeed )
);
vec3 t = 0.2 * vec3( 3.0, 2.3, 3.5 );
@@ -111,7 +119,11 @@ vec4 map( vec3 p ) {
pt = mod( pt - 0.1, 0.2 ) - 0.1;
vec4 isectb = vec4( clampbox, 2, 0, 0 );
float d = max( box( pt, vec3( 0.07 ) ), clampbox );
float gorge = step( 0.0, 0.005 - abs( pt.x ) );
vec4 isectb = vec4( d, 1.0 + 2.0 * gorge, 0, 0 );
isect = isectb.x < isect.x ? isectb : isect;
}
@@ -120,7 +132,7 @@ vec4 map( vec3 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 );
vec4 isectb = vec4( d, 4, 0, 0 );
isect = isectb.x < isect.x ? isectb : isect;
}
@@ -170,21 +182,34 @@ void main() {
fragPosition = vec4( modelPos.xyz, depth );
fragNormal = vec4( modelNormal, 1.0 );
if ( isect.y == 2.0 ) {
if ( isect.y < 2.5 ) {
vec3 noise = cyclicNoise( 3.0 * rayPos );
vec3 noiseDetail = cyclicNoise( vec3( 38.0, 1.0, 1.0 ) * ( orthBasis( vec3( 1 ) ) * rayPos ) );
float roughness = (
0.6 +
0.1 * noise.x +
0.2 * smoothstep( -0.2, 0.4, noise.y ) * ( 0.8 + 0.2 * sin( 17.0 * noiseDetail.x ) )
);
fragColor = vec4( vec3( 0.4 ), 1.0 );
fragWTF = vec4( vec3( roughness, 0.9, 0.0 ), 2 );
} else if ( isect.y == 1.0 ) {
fragColor = vec4( vec3( 1.0 ), 1.0 );
fragWTF = vec4( vec3( 0.3, 0.1, 0.0 ), 2 );
if ( isect.y == 1.0 ) {
float roughness = (
0.6 +
0.1 * noise.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 );
fragWTF = vec4( vec3( roughness, 0.9, 0.0 ), 2 );
} else {
float roughness = (
0.2 +
0.2 * ( 0.5 + 0.5 * sin( 17.0 * noiseDetail.x ) )
);
fragColor = vec4( vec3( 0.3 ), 1.0 );
fragWTF = vec4( vec3( roughness, 0.1, 0.0 ), 2 );
}
} else if ( isect.y == 3.0 ) {
float amp = 20.0 * exp( -5.0 * fract( abs( rayPos.x ) - rayPos.y + abs( rayPos.z ) + time ) );
fragColor = vec4( 0.2 * vec3( 1.0, 0.002, 0.03 ), 1.0 );
fragWTF = vec4( vec3( 0.1, 0.1, amp ), 2 );
} else if ( isect.y == 4.0 ) {
fragColor = vec4( 0.2 * vec3( 1.0, 0.002, 0.03 ), 1.0 );
fragWTF = vec4( vec3( 0.1, 0.1, 20.0 ), 2 );
}

View File

@@ -16,6 +16,7 @@ in vec4 vPosition;
out vec4 fragColor;
uniform float time;
uniform float intensity;
uniform vec2 lightNearFar;
uniform vec2 resolution;
uniform vec2 cameraNearFar;
@@ -107,5 +108,5 @@ void main() {
if ( rayLen > cameraNearFar.y ) { break; }
}
fragColor = vec4( 0.01 * lightColor * accum, 1.0 );
fragColor = vec4( intensity * lightColor * accum, 1.0 );
}

View File

@@ -33,7 +33,7 @@ void main() {
}
float index = ( reverse ? texIndex.y : texIndex.x ) - 1.0;
float width = texIndex.x + texIndex.y - 1.0;
float width = texIndex.x + texIndex.y - 2.0;
bool isCompHigher = mod( index, 2.0 * comp * width ) < comp * width;
float offset = floor( ( ( isCompHigher ^^ reverse ) ? comp : -comp ) * width + 0.5 );

View File

@@ -24,14 +24,6 @@ uniform sampler2D samplerRandom;
#pragma glslify: prng = require( ./-prng );
vec3 colorMap( vec3 i ) {
return vec3(
smoothstep( 0.0, 1.0, i.r ),
i.g,
0.1 + 0.8 * i.b
);
}
vec3 barrel( float amp, vec2 uv ) {
float corn = length( vec2( 0.5 ) );
float a = min( 3.0 * sqrt( amp ), corn * PI );

View File

@@ -23,13 +23,13 @@ uniform float time;
void main() {
#ifdef FORWARD
fragColor = vec4( 8.0 * vec3( 0.1, 0.9, 0.4 ), 1.0 );
fragColor = vec4( 8.0 * vec3( 0.1, 0.4, 1.0 ), 1.0 );
#endif
#ifdef DEFERRED
fragPosition = vPosition;
fragNormal = vec4( normalize( vNormal ), 1.0 );
fragColor = vec4( 0.1, 0.9, 0.4, 1.0 );
fragColor = vec4( 0.1, 0.4, 1.0, 1.0 );
fragWTF = vec4( vec3( 0.2, 0.2, 8.0 ), MTL_PBR );
#endif
}

View File

@@ -37,7 +37,7 @@ void main() {
vNormal = normalize( ( normalMatrix * vec4( normal, 1.0 ) ).xyz );
vPosition = vec4( mix( 2.0, 2.7, random() ) * position, 1.0 );
vPosition.xyz += mix( 0.002, 0.005, random() ) * normal;
vPosition.xyz += mix( 0.005, 0.01, random() ) * normal;
vPosition.y += sin( random() * time + random() * vPosition.x + TAU * random() ) * 0.2 * random();
vPosition.y += sin( random() * time + random() * vPosition.z + TAU * random() ) * 0.2 * random();
vPosition.xy = rotate2D( 0.2 * ( random() - 0.5 ) ) * vPosition.xy;

View File

@@ -5,6 +5,7 @@ precision highp float;
const int MTL_NONE = 0;
const int MTL_UNLIT = 1;
const int MTL_PBR = 2;
const int MTL_REFRACT = 3;
const float ENV_UV_MARGIN = 0.9375;
const float AO_BIAS = 0.0;
const float AO_RADIUS = 0.5;
@@ -192,7 +193,6 @@ vec3 shadePBR( Isect isect ) {
);
shadow *= castShadow( iLight, lightP * 0.5 + 0.5, isect, NdotL );
shadow = mix( 0.0, 1.0, shadow );
// do shading
vec3 diffuse = brdfLambert( f0, albedo, VdotH );
@@ -268,6 +268,18 @@ void main() {
} else if ( isect.materialId == MTL_PBR ) {
color = shadePBR( isect );
} else if ( isect.materialId == MTL_REFRACT ) {
color = shadePBR( isect );
// really really cheap full spectrum
vec3 refrEnvRefractive = refract( V, isect.normal, 1.0 / 2.56 );
vec2 uvEnvRefractive = vec2(
0.5 + atan( refrEnvRefractive.x, -refrEnvRefractive.z ) / TAU,
0.5 + atan( refrEnvRefractive.y, length( refrEnvRefractive.zx ) ) / PI
);
vec3 texEnvRefractive = sampleEnvLinear( uvEnvRefractive, 0.1 ).rgb;
color += isect.color * texEnvRefractive;
}

View File

@@ -142,8 +142,8 @@ void main() {
#ifdef DEFERRED
fragPosition = vec4( modelPos.xyz, depth );
fragNormal = vec4( modelNormal, 1.0 );
fragColor = vec4( 0.4, 0.7, 0.9, 1.0 );
fragWTF = vec4( vec3( 0.9, 0.7, 0.0 ), MTL_PBR );
fragColor = vec4( vec3( 0.3 ), 1.0 );
fragWTF = vec4( vec3( 1.0, 0.1, 0.0 ), MTL_PBR );
#endif
#ifdef SHADOW