Skip to content

Commit

Permalink
Merge branch 'chasedavis-main'
Browse files Browse the repository at this point in the history
  • Loading branch information
FarazzShaikh committed Feb 28, 2023
2 parents f43a63f + 6b42269 commit 3b2717e
Show file tree
Hide file tree
Showing 9 changed files with 10,015 additions and 9,588 deletions.
42 changes: 36 additions & 6 deletions examples/debug/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { Canvas } from '@react-three/fiber'
import { OrbitControls, PerspectiveCamera, Sphere } from '@react-three/drei'
import { OrbitControls, PerspectiveCamera, Sphere, Environment } from '@react-three/drei'
import Lights from './components/Lights'
import { useMemo, useState } from 'react'
import CustomShaderMaterial from 'three-custom-shader-material'

import { Color, MeshBasicMaterial, MeshPhysicalMaterial } from 'three'
import { Color, MeshBasicMaterial, MeshNormalMaterial, MeshPhysicalMaterial, MeshStandardMaterial } from 'three'
import { Perf } from 'r3f-perf'

// @ts-ignore
import { patchShaders } from 'gl-noise/build/glNoise.m'
import common from './shaders/common'
import psrd from './shaders/psrd'

function Thing() {
const [mat2, setMat2] = useState<any>()

Expand Down Expand Up @@ -35,12 +40,37 @@ function Thing() {
onPointerLeave={() => (uniforms.uColor.value = new Color('red'))}
>
<CustomShaderMaterial
baseMaterial={mat2}
baseMaterial={MeshStandardMaterial}
fragmentShader={
common +
psrd +
/* glsl */ `
varying vec2 csm_vUv;
varying vec3 csm_vPosition;
void main() {
csm_DiffuseColor = vec4(1., 1., 0., 1.0);
csm_Roughness = 0.;
// Size of bump, .01 to .20 is sensible in this example
float bumpSize = 0.1;
// How much it perturbs the normals, looks best between 0 and 0.1
float bumpStrength = 0.1;
gln_PSRDOpts opts = gln_PSRDOpts(1., vec3(0.0), 1.);
gln_psrd((1. / bumpSize) * csm_vPosition, opts, csm_Bump);
// bump more visible with low roughness
csm_Roughness = 0.1;
csm_DiffuseColor = vec4(1.0, 0., 1., 0.);
}
`
}
vertexShader={
/* glsl */ `
varying vec2 csm_vUv;
varying vec3 csm_vPosition;
void main() {
csm_vUv = uv;
csm_vPosition = position;
}
`
}
Expand Down Expand Up @@ -79,7 +109,7 @@ export default function App() {
<Canvas shadows>
<OrbitControls makeDefault />
<PerspectiveCamera position={[-5, 5, 5]} makeDefault />

<Environment preset="warehouse" />
<Thing />
<Perf />

Expand Down
85 changes: 85 additions & 0 deletions examples/debug/src/shaders/common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
export default /* glsl */ `
// private
#define GLN_PI 3.1415926538
float _gln_mod289(float x) {
return x - floor(x * (1.0 / 289.0)) * 289.0;
}
vec2 _gln_mod289(vec2 x) {
return x - floor(x * (1.0 / 289.0)) * 289.0;
}
vec3 _gln_mod289(vec3 x) {
return x - floor(x * (1.0 / 289.0)) * 289.0;
}
vec4 _gln_mod289(vec4 x) {
return x - floor(x * (1.0 / 289.0)) * 289.0;
}
vec3 _gln_mod7(vec3 x) {
return x - floor(x * (1.0 / 7.0)) * 7.0;
}
float _gln_permute(float x) {
return _gln_mod289((34.0 * x + 10.0) * x);
}
vec2 _gln_permute(vec2 x) {
return _gln_mod289((34.0 * x + 10.0) * x);
}
vec3 _gln_permute(vec3 x) {
return _gln_mod289((34.0 * x + 10.0) * x);
}
vec4 _gln_permute(vec4 x) {
return _gln_mod289(((x * 34.0) + 10.0) * x);
}
vec4 _gln_taylorInvSqrt(vec4 r) {
return 1.79284291400159 - 0.85373472095314 * r;
}
vec2 _gln_fade(vec2 t) {
return t * t * t * (t * (t * 6.0 - 15.0) + 10.0);
}
vec3 _gln_fade(vec3 t) {
return t * t * t * (t * (t * 6.0 - 15.0) + 10.0);
}
// public
float gln_map(float value, float min1, float max1, float min2, float max2) {
return min2 + (value - min1) * (max2 - min2) / (max1 - min1);
}
float gln_normalize(float v) {
return gln_map(v, -1., 1., 0., 1.);
}
vec2 gln_normalize(vec2 v) {
return vec2(
gln_normalize(v.x),
gln_normalize(v.y)
);
}
vec3 gln_normalize(vec3 v) {
return vec3(
gln_normalize(v.x),
gln_normalize(v.y),
gln_normalize(v.z)
);
}
struct gln_FBMOpts {
float seed;
float persistance;
float lacunarity;
int octaves;
};
`
Loading

0 comments on commit 3b2717e

Please sign in to comment.