Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/manual/en/introduction/Import-via-modules.html
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ <h2>Importable Examples</h2>
<li>SSAOShader</li>
<li>TechnicolorShader</li>
<li>ToneMapShader</li>
<li>TranslucentShader</li>
<li>TriangleBlurShader</li>
<li>UnpackDepthRGBAShader</li>
<li>VerticalBlurShader</li>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
/**
* @author daoshengmu / http://dsmu.me/
*
* ------------------------------------------------------------------------------------------
* Subsurface Scattering shader
* Base on GDC 2011 – Approximating Translucency for a Fast, Cheap and Convincing Subsurface Scattering Look
* https://colinbarrebrisebois.com/2011/03/07/gdc-2011-approximating-translucency-for-a-fast-cheap-and-convincing-subsurface-scattering-look/
*------------------------------------------------------------------------------------------
*/

THREE.TranslucentShader = {

THREE.TranslucentShader = function TranslucentShader() {

/* ------------------------------------------------------------------------------------------
// Subsurface Scattering shader
// - Base on GDC 2011 – Approximating Translucency for a Fast, Cheap and Convincing Subsurface Scattering Look
// https://colinbarrebrisebois.com/2011/03/07/gdc-2011-approximating-translucency-for-a-fast-cheap-and-convincing-subsurface-scattering-look/
// ------------------------------------------------------------------------------------------ */

this.uniforms = THREE.UniformsUtils.merge( [
uniforms: THREE.UniformsUtils.merge( [

THREE.UniformsLib[ "common" ],
THREE.UniformsLib[ "lights" ],

{
"color": { value: new THREE.Color( 0xffffff ) },
"diffuse": { value: new THREE.Color( 0xffffff ) },
"color": { value: new THREE.Color( 0xffffff ) },
"diffuse": { value: new THREE.Color( 0xffffff ) },
"specular": { value: new THREE.Color( 0xffffff ) },
"emissive": { value: new THREE.Color( 0x000000 ) },
"opacity": { value: 1 },
Expand All @@ -34,9 +31,36 @@ THREE.TranslucentShader = function TranslucentShader() {
"thicknessScale": { value: 10.0 }
}

] );
] ),

vertexShader: [

"varying vec3 vNormal;",
"varying vec2 vUv;",

"varying vec3 vViewPosition;",

THREE.ShaderChunk[ "common" ],

"void main() {",

" vec4 worldPosition = modelMatrix * vec4( position, 1.0 );",

" vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",

" vViewPosition = -mvPosition.xyz;",

" vNormal = normalize( normalMatrix * normal );",

" vUv = uv;",

" gl_Position = projectionMatrix * mvPosition;",

"}",

].join( "\n" ),

this.fragmentShader = [
fragmentShader: [
"#define USE_MAP",
"#define PHONG",
"#define TRANSLUCENT",
Expand Down Expand Up @@ -82,13 +106,13 @@ THREE.TranslucentShader = function TranslucentShader() {
" vec4 diffuseColor = vec4( diffuse, opacity );",
" ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );",

THREE.ShaderChunk[ "map_fragment" ],
THREE.ShaderChunk[ "color_fragment" ],
THREE.ShaderChunk[ "specularmap_fragment" ],
THREE.ShaderChunk[ "map_fragment" ],
THREE.ShaderChunk[ "color_fragment" ],
THREE.ShaderChunk[ "specularmap_fragment" ],

" vec3 totalEmissiveRadiance = emissive;",

THREE.ShaderChunk["lights_phong_fragment"],
THREE.ShaderChunk[ "lights_phong_fragment" ],

// Doing lights fragment begin.
" GeometricContext geometry;",
Expand Down Expand Up @@ -165,42 +189,15 @@ THREE.TranslucentShader = function TranslucentShader() {
" vec3 clearCoatRadiance = vec3( 0.0 );",

" #endif",
THREE.ShaderChunk["lights_fragment_end"],
THREE.ShaderChunk[ "lights_fragment_end" ],

" vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;",
" gl_FragColor = vec4( outgoingLight, diffuseColor.a );", // TODO, this should be pre-multiplied to allow for bright highlights on very transparent objects

THREE.ShaderChunk["encodings_fragment"],
THREE.ShaderChunk[ "encodings_fragment" ],

"}"

].join( "\n" ),

this.vertexShader = [

"varying vec3 vNormal;",
"varying vec2 vUv;",

"varying vec3 vViewPosition;",

THREE.ShaderChunk[ "common" ],

"void main() {",

" vec4 worldPosition = modelMatrix * vec4( position, 1.0 );",

" vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",

" vViewPosition = -mvPosition.xyz;",

" vNormal = normalize( normalMatrix * normal );",

" vUv = uv;",

" gl_Position = projectionMatrix * mvPosition;",

"}",

].join( "\n" )

};
8 changes: 7 additions & 1 deletion examples/jsm/loaders/GLTFLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2705,7 +2705,13 @@ var GLTFLoader = ( function () {
? new SkinnedMesh( geometry, material )
: new Mesh( geometry, material );

if ( mesh.isSkinnedMesh === true ) mesh.normalizeSkinWeights(); // #15319
if ( mesh.isSkinnedMesh === true && !mesh.geometry.attributes.skinWeight.normalized ) {

// we normalize floating point skin weight array to fix malformed assets (see #15319)
// it's important to skip this for non-float32 data since normalizeSkinWeights assumes non-normalized inputs
mesh.normalizeSkinWeights();

}

if ( primitive.mode === WEBGL_CONSTANTS.TRIANGLE_STRIP ) {

Expand Down
7 changes: 3 additions & 4 deletions examples/jsm/renderers/RaytracingRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ var RaytracingRenderer = function ( parameters ) {
canvasWidth = canvas.width;
canvasHeight = canvas.height;

context.fillStyle = 'white';

pool.forEach( updateSettings );

};
Expand Down Expand Up @@ -181,7 +179,6 @@ var RaytracingRenderer = function ( parameters ) {
} );

context.fillStyle = '#' + worker.color;

context.fillRect( blockX, blockY, blockSize, blockSize );

}
Expand Down Expand Up @@ -252,7 +249,9 @@ var RaytracingRenderer = function ( parameters ) {

} );

context.clearRect( 0, 0, canvasWidth, canvasHeight );
context.fillStyle = clearColor.getStyle();
context.fillRect( 0, 0, canvasWidth, canvasHeight );

reallyThen = Date.now();

xblocks = Math.ceil( canvasWidth / blockSize );
Expand Down
39 changes: 39 additions & 0 deletions examples/jsm/shaders/TranslucentShader.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {
Uniform
} from '../../../src/Three';

export interface TranslucentShader {
uniforms: {
alphaMap: Uniform;
ambientLightColor: Uniform;
color: Uniform;
diffuse: Uniform;
directionalLights: Uniform;
directionalShadowMap: Uniform;
directionalShadowMatrix: Uniform;
emissive: Uniform;
hemisphereLights: Uniform;
lightProbe: Uniform;
map: Uniform;
opacity: Uniform;
pointLights: Uniform;
pointShadowMap: Uniform;
pointShadowMatrix: Uniform;
rectAreaLights: Uniform;
shininess: Uniform;
specular: Uniform;
spotLights: Uniform;
spotShadowMap: Uniform;
spotShadowMatrix: Uniform;
thicknessAmbient: Uniform;
thicknessAttenuation: Uniform;
thicknessColor: Uniform;
thicknessDistortion: Uniform;
thicknessMap: Uniform;
thicknessPower: Uniform;
thicknessScale: Uniform;
uvTransform: Uniform;
};
vertexShader: string;
fragmentShader: string;
}
Loading