Initial commit
This commit is contained in:
122
HTML/ThreeJS/node_modules/three/examples/jsm/nodes/functions/BSDFs.js
generated
vendored
Normal file
122
HTML/ThreeJS/node_modules/three/examples/jsm/nodes/functions/BSDFs.js
generated
vendored
Normal file
@@ -0,0 +1,122 @@
|
||||
import { ShaderNode,
|
||||
add, addTo, sub, mul, div, saturate, dot, pow, pow2, exp2, normalize, max, sqrt, negate,
|
||||
cond, greaterThan, and,
|
||||
transformedNormalView, positionViewDirection,
|
||||
diffuseColor, specularColor, roughness,
|
||||
PI, RECIPROCAL_PI, EPSILON
|
||||
} from '../ShaderNode.js';
|
||||
|
||||
export const F_Schlick = new ShaderNode( ( inputs ) => {
|
||||
|
||||
const { f0, f90, dotVH } = inputs;
|
||||
|
||||
// Original approximation by Christophe Schlick '94
|
||||
// float fresnel = pow( 1.0 - dotVH, 5.0 );
|
||||
|
||||
// Optimized variant (presented by Epic at SIGGRAPH '13)
|
||||
// https://cdn2.unrealengine.com/Resources/files/2013SiggraphPresentationsNotes-26915738.pdf
|
||||
const fresnel = exp2( mul( sub( mul( - 5.55473, dotVH ), 6.98316 ), dotVH ) );
|
||||
|
||||
return add( mul( f0, sub( 1.0, fresnel ) ), mul( f90, fresnel ) );
|
||||
|
||||
} ); // validated
|
||||
|
||||
export const BRDF_Lambert = new ShaderNode( ( inputs ) => {
|
||||
|
||||
return mul( RECIPROCAL_PI, inputs.diffuseColor ); // punctual light
|
||||
|
||||
} ); // validated
|
||||
|
||||
export const getDistanceAttenuation = new ShaderNode( ( inputs ) => {
|
||||
|
||||
const { lightDistance, cutoffDistance, decayExponent } = inputs;
|
||||
|
||||
return cond(
|
||||
and( greaterThan( cutoffDistance, 0 ), greaterThan( decayExponent, 0 ) ),
|
||||
pow( saturate( add( div( negate( lightDistance ), cutoffDistance ), 1.0 ) ), decayExponent ),
|
||||
1.0
|
||||
);
|
||||
|
||||
} ); // validated
|
||||
|
||||
//
|
||||
// STANDARD
|
||||
//
|
||||
|
||||
// Moving Frostbite to Physically Based Rendering 3.0 - page 12, listing 2
|
||||
// https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
|
||||
export const V_GGX_SmithCorrelated = new ShaderNode( ( inputs ) => {
|
||||
|
||||
const { alpha, dotNL, dotNV } = inputs;
|
||||
|
||||
const a2 = pow2( alpha );
|
||||
|
||||
const gv = mul( dotNL, sqrt( add( a2, mul( sub( 1.0, a2 ), pow2( dotNV ) ) ) ) );
|
||||
const gl = mul( dotNV, sqrt( add( a2, mul( sub( 1.0, a2 ), pow2( dotNL ) ) ) ) );
|
||||
|
||||
return div( 0.5, max( add( gv, gl ), EPSILON ) );
|
||||
|
||||
} ); // validated
|
||||
|
||||
// Microfacet Models for Refraction through Rough Surfaces - equation (33)
|
||||
// http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html
|
||||
// alpha is "roughness squared" in Disney’s reparameterization
|
||||
export const D_GGX = new ShaderNode( ( inputs ) => {
|
||||
|
||||
const { alpha, dotNH } = inputs;
|
||||
|
||||
const a2 = pow2( alpha );
|
||||
|
||||
const denom = add( mul( pow2( dotNH ), sub( a2, 1.0 ) ), 1.0 ); // avoid alpha = 0 with dotNH = 1
|
||||
|
||||
return mul( RECIPROCAL_PI, div( a2, pow2( denom ) ) );
|
||||
|
||||
} ); // validated
|
||||
|
||||
|
||||
// GGX Distribution, Schlick Fresnel, GGX_SmithCorrelated Visibility
|
||||
export const BRDF_GGX = new ShaderNode( ( inputs ) => {
|
||||
|
||||
const { lightDirection, f0, f90, roughness } = inputs;
|
||||
|
||||
const alpha = pow2( roughness ); // UE4's roughness
|
||||
|
||||
const halfDir = normalize( add( lightDirection, positionViewDirection ) );
|
||||
|
||||
const dotNL = saturate( dot( transformedNormalView, lightDirection ) );
|
||||
const dotNV = saturate( dot( transformedNormalView, positionViewDirection ) );
|
||||
const dotNH = saturate( dot( transformedNormalView, halfDir ) );
|
||||
const dotVH = saturate( dot( positionViewDirection, halfDir ) );
|
||||
|
||||
const F = F_Schlick( { f0, f90, dotVH } );
|
||||
|
||||
const V = V_GGX_SmithCorrelated( { alpha, dotNL, dotNV } );
|
||||
|
||||
const D = D_GGX( { alpha, dotNH } );
|
||||
|
||||
return mul( F, mul( V, D ) );
|
||||
|
||||
} ); // validated
|
||||
|
||||
export const RE_Direct_Physical = new ShaderNode( ( inputs ) => {
|
||||
|
||||
const { lightDirection, lightColor, directDiffuse, directSpecular } = inputs;
|
||||
|
||||
const dotNL = saturate( dot( transformedNormalView, lightDirection ) );
|
||||
let irradiance = mul( dotNL, lightColor );
|
||||
|
||||
irradiance = mul( irradiance, PI ); // punctual light
|
||||
|
||||
addTo( directDiffuse, mul( irradiance, BRDF_Lambert( { diffuseColor: diffuseColor.rgb } ) ) );
|
||||
|
||||
addTo( directSpecular, mul( irradiance, BRDF_GGX( { lightDirection, f0: specularColor, f90: 1, roughness } ) ) );
|
||||
|
||||
} );
|
||||
|
||||
export const PhysicalLightingModel = new ShaderNode( ( inputs/*, builder*/ ) => {
|
||||
|
||||
// PHYSICALLY_CORRECT_LIGHTS <-> builder.renderer.physicallyCorrectLights === true
|
||||
|
||||
RE_Direct_Physical( inputs );
|
||||
|
||||
} );
|
||||
27
HTML/ThreeJS/node_modules/three/examples/jsm/nodes/functions/PhysicalMaterialFunctions.js
generated
vendored
Normal file
27
HTML/ThreeJS/node_modules/three/examples/jsm/nodes/functions/PhysicalMaterialFunctions.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
import { ShaderNode,
|
||||
add, max, min, abs, dFdx, dFdy,
|
||||
normalGeometry
|
||||
} from '../ShaderNode.js';
|
||||
|
||||
export const getGeometryRoughness = new ShaderNode( () => {
|
||||
|
||||
const dxy = max( abs( dFdx( normalGeometry ) ), abs( dFdy( normalGeometry ) ) );
|
||||
const geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );
|
||||
|
||||
return geometryRoughness;
|
||||
|
||||
} );
|
||||
|
||||
export const getRoughness = new ShaderNode( ( inputs ) => {
|
||||
|
||||
const { roughness } = inputs;
|
||||
|
||||
const geometryRoughness = getGeometryRoughness();
|
||||
|
||||
let roughnessFactor = max( roughness, 0.0525 ); // 0.0525 corresponds to the base mip of a 256 cubemap.
|
||||
roughnessFactor = add( roughnessFactor, geometryRoughness );
|
||||
roughnessFactor = min( roughnessFactor, 1.0 );
|
||||
|
||||
return roughnessFactor;
|
||||
|
||||
} );
|
||||
Reference in New Issue
Block a user