Skip to content

Commit 38a49a5

Browse files
authored
Merge pull request #16628 from Mugen87/dev33
JSM: Added module and TS file for TranslucentShader.
2 parents 10c2ff6 + 6459e0c commit 38a49a5

File tree

8 files changed

+309
-54
lines changed

8 files changed

+309
-54
lines changed

docs/manual/en/introduction/Import-via-modules.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ <h2>Importable Examples</h2>
290290
<li>TechnicolorShader</li>
291291
<li>TerrainShader</li>
292292
<li>ToneMapShader</li>
293+
<li>TranslucentShader</li>
293294
<li>TriangleBlurShader</li>
294295
<li>UnpackDepthRGBAShader</li>
295296
<li>VerticalBlurShader</li>

examples/js/ShaderTranslucent.js renamed to examples/js/shaders/TranslucentShader.js

Lines changed: 44 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
/**
22
* @author daoshengmu / http://dsmu.me/
33
*
4+
* ------------------------------------------------------------------------------------------
5+
* Subsurface Scattering shader
6+
* Base on GDC 2011 – Approximating Translucency for a Fast, Cheap and Convincing Subsurface Scattering Look
7+
* https://colinbarrebrisebois.com/2011/03/07/gdc-2011-approximating-translucency-for-a-fast-cheap-and-convincing-subsurface-scattering-look/
8+
*------------------------------------------------------------------------------------------
49
*/
510

11+
THREE.TranslucentShader = {
612

7-
THREE.TranslucentShader = function TranslucentShader() {
8-
9-
/* ------------------------------------------------------------------------------------------
10-
// Subsurface Scattering shader
11-
// - Base on GDC 2011 – Approximating Translucency for a Fast, Cheap and Convincing Subsurface Scattering Look
12-
// https://colinbarrebrisebois.com/2011/03/07/gdc-2011-approximating-translucency-for-a-fast-cheap-and-convincing-subsurface-scattering-look/
13-
// ------------------------------------------------------------------------------------------ */
14-
15-
this.uniforms = THREE.UniformsUtils.merge( [
13+
uniforms: THREE.UniformsUtils.merge( [
1614

1715
THREE.UniformsLib[ "common" ],
1816
THREE.UniformsLib[ "lights" ],
19-
2017
{
21-
"color": { value: new THREE.Color( 0xffffff ) },
22-
"diffuse": { value: new THREE.Color( 0xffffff ) },
18+
"color": { value: new THREE.Color( 0xffffff ) },
19+
"diffuse": { value: new THREE.Color( 0xffffff ) },
2320
"specular": { value: new THREE.Color( 0xffffff ) },
2421
"emissive": { value: new THREE.Color( 0x000000 ) },
2522
"opacity": { value: 1 },
@@ -34,9 +31,36 @@ THREE.TranslucentShader = function TranslucentShader() {
3431
"thicknessScale": { value: 10.0 }
3532
}
3633

37-
] );
34+
] ),
35+
36+
vertexShader: [
37+
38+
"varying vec3 vNormal;",
39+
"varying vec2 vUv;",
40+
41+
"varying vec3 vViewPosition;",
42+
43+
THREE.ShaderChunk[ "common" ],
44+
45+
"void main() {",
46+
47+
" vec4 worldPosition = modelMatrix * vec4( position, 1.0 );",
48+
49+
" vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
50+
51+
" vViewPosition = -mvPosition.xyz;",
52+
53+
" vNormal = normalize( normalMatrix * normal );",
54+
55+
" vUv = uv;",
56+
57+
" gl_Position = projectionMatrix * mvPosition;",
58+
59+
"}",
60+
61+
].join( "\n" ),
3862

39-
this.fragmentShader = [
63+
fragmentShader: [
4064
"#define USE_MAP",
4165
"#define PHONG",
4266
"#define TRANSLUCENT",
@@ -82,13 +106,13 @@ THREE.TranslucentShader = function TranslucentShader() {
82106
" vec4 diffuseColor = vec4( diffuse, opacity );",
83107
" ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );",
84108

85-
THREE.ShaderChunk[ "map_fragment" ],
86-
THREE.ShaderChunk[ "color_fragment" ],
87-
THREE.ShaderChunk[ "specularmap_fragment" ],
109+
THREE.ShaderChunk[ "map_fragment" ],
110+
THREE.ShaderChunk[ "color_fragment" ],
111+
THREE.ShaderChunk[ "specularmap_fragment" ],
88112

89113
" vec3 totalEmissiveRadiance = emissive;",
90114

91-
THREE.ShaderChunk["lights_phong_fragment"],
115+
THREE.ShaderChunk[ "lights_phong_fragment" ],
92116

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

167191
" #endif",
168-
THREE.ShaderChunk["lights_fragment_end"],
192+
THREE.ShaderChunk[ "lights_fragment_end" ],
169193

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

173-
THREE.ShaderChunk["encodings_fragment"],
197+
THREE.ShaderChunk[ "encodings_fragment" ],
174198

175199
"}"
176200

177201
].join( "\n" ),
178202

179-
this.vertexShader = [
180-
181-
"varying vec3 vNormal;",
182-
"varying vec2 vUv;",
183-
184-
"varying vec3 vViewPosition;",
185-
186-
THREE.ShaderChunk[ "common" ],
187-
188-
"void main() {",
189-
190-
" vec4 worldPosition = modelMatrix * vec4( position, 1.0 );",
191-
192-
" vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
193-
194-
" vViewPosition = -mvPosition.xyz;",
195-
196-
" vNormal = normalize( normalMatrix * normal );",
197-
198-
" vUv = uv;",
199-
200-
" gl_Position = projectionMatrix * mvPosition;",
201-
202-
"}",
203-
204-
].join( "\n" )
205-
206203
};

examples/jsm/loaders/GLTFLoader.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2705,7 +2705,13 @@ var GLTFLoader = ( function () {
27052705
? new SkinnedMesh( geometry, material )
27062706
: new Mesh( geometry, material );
27072707

2708-
if ( mesh.isSkinnedMesh === true ) mesh.normalizeSkinWeights(); // #15319
2708+
if ( mesh.isSkinnedMesh === true && !mesh.geometry.attributes.skinWeight.normalized ) {
2709+
2710+
// we normalize floating point skin weight array to fix malformed assets (see #15319)
2711+
// it's important to skip this for non-float32 data since normalizeSkinWeights assumes non-normalized inputs
2712+
mesh.normalizeSkinWeights();
2713+
2714+
}
27092715

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

examples/jsm/renderers/RaytracingRenderer.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,6 @@ var RaytracingRenderer = function ( parameters ) {
130130
canvasWidth = canvas.width;
131131
canvasHeight = canvas.height;
132132

133-
context.fillStyle = 'white';
134-
135133
pool.forEach( updateSettings );
136134

137135
};
@@ -181,7 +179,6 @@ var RaytracingRenderer = function ( parameters ) {
181179
} );
182180

183181
context.fillStyle = '#' + worker.color;
184-
185182
context.fillRect( blockX, blockY, blockSize, blockSize );
186183

187184
}
@@ -252,7 +249,9 @@ var RaytracingRenderer = function ( parameters ) {
252249

253250
} );
254251

255-
context.clearRect( 0, 0, canvasWidth, canvasHeight );
252+
context.fillStyle = clearColor.getStyle();
253+
context.fillRect( 0, 0, canvasWidth, canvasHeight );
254+
256255
reallyThen = Date.now();
257256

258257
xblocks = Math.ceil( canvasWidth / blockSize );
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import {
2+
Uniform
3+
} from '../../../src/Three';
4+
5+
export interface TranslucentShader {
6+
uniforms: {
7+
alphaMap: Uniform;
8+
ambientLightColor: Uniform;
9+
color: Uniform;
10+
diffuse: Uniform;
11+
directionalLights: Uniform;
12+
directionalShadowMap: Uniform;
13+
directionalShadowMatrix: Uniform;
14+
emissive: Uniform;
15+
hemisphereLights: Uniform;
16+
lightProbe: Uniform;
17+
map: Uniform;
18+
opacity: Uniform;
19+
pointLights: Uniform;
20+
pointShadowMap: Uniform;
21+
pointShadowMatrix: Uniform;
22+
rectAreaLights: Uniform;
23+
shininess: Uniform;
24+
specular: Uniform;
25+
spotLights: Uniform;
26+
spotShadowMap: Uniform;
27+
spotShadowMatrix: Uniform;
28+
thicknessAmbient: Uniform;
29+
thicknessAttenuation: Uniform;
30+
thicknessColor: Uniform;
31+
thicknessDistortion: Uniform;
32+
thicknessMap: Uniform;
33+
thicknessPower: Uniform;
34+
thicknessScale: Uniform;
35+
uvTransform: Uniform;
36+
};
37+
vertexShader: string;
38+
fragmentShader: string;
39+
}

0 commit comments

Comments
 (0)