From f239ba86196746d8ef69ff2687b088dbf9ef564f Mon Sep 17 00:00:00 2001 From: Kevin Levron Date: Thu, 17 Sep 2020 17:09:45 +0200 Subject: [PATCH] update sub surface --- src/materials/SubSurfaceMaterial.js | 19 +++++++++++++++++-- src/materials/SubsurfaceScatteringShader.js | 14 +++++++++++++- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/materials/SubSurfaceMaterial.js b/src/materials/SubSurfaceMaterial.js index 467327a..e7cc9ef 100644 --- a/src/materials/SubSurfaceMaterial.js +++ b/src/materials/SubSurfaceMaterial.js @@ -33,6 +33,18 @@ export default { type: Number, default: 4, }, + transparent: { + type: Boolean, + default: false, + }, + opacity: { + type: Number, + default: 1, + }, + vertexColors: { + type: Boolean, + default: false, + }, }, created() { const params = SubsurfaceScatteringShader; @@ -41,14 +53,17 @@ export default { if (key === 'diffuse' || key === 'thicknessColor') { value = new Color(value); } - if (key !== 'id') uniforms[key].value = value; + if (key !== 'id' && key !== 'transparent' && key !== 'vertexColors') { + uniforms[key].value = value; + } }); this.material = new TShaderMaterial({ ...params, uniforms, lights: true, - transparent: true, + transparent: this.transparent, + vertexColors: this.vertexColors, }); }, }; diff --git a/src/materials/SubsurfaceScatteringShader.js b/src/materials/SubsurfaceScatteringShader.js index 49283f0..1fe5356 100644 --- a/src/materials/SubsurfaceScatteringShader.js +++ b/src/materials/SubsurfaceScatteringShader.js @@ -1,3 +1,11 @@ +/** + * ------------------------------------------------------------------------------------------ + * Subsurface Scattering shader + * Based on three/examples/jsm/shaders/SubsurfaceScatteringShader.js + * Based 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/ + *------------------------------------------------------------------------------------------ + */ import { Color, ShaderChunk, @@ -45,7 +53,11 @@ const SubsurfaceScatteringShader = { uniform vec3 thicknessColor; void RE_Direct_Scattering(const in IncidentLight directLight, const in vec2 uv, const in GeometricContext geometry, inout ReflectedLight reflectedLight) { - vec3 thickness = thicknessColor; + #ifdef USE_COLOR + vec3 thickness = vColor * thicknessColor; + #else + vec3 thickness = thicknessColor; + #endif vec3 scatteringHalf = normalize(directLight.direction + (geometry.normal * thicknessDistortion)); float scatteringDot = pow(saturate(dot(geometry.viewDir, -scatteringHalf)), thicknessPower) * thicknessScale; vec3 scatteringIllu = (scatteringDot + thicknessAmbient) * thickness;