mirror of
https://github.com/troisjs/trois.git
synced 2024-11-24 04:12:02 +08:00
update sub surface
This commit is contained in:
parent
6d74085ce9
commit
f239ba8619
@ -33,6 +33,18 @@ export default {
|
|||||||
type: Number,
|
type: Number,
|
||||||
default: 4,
|
default: 4,
|
||||||
},
|
},
|
||||||
|
transparent: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
opacity: {
|
||||||
|
type: Number,
|
||||||
|
default: 1,
|
||||||
|
},
|
||||||
|
vertexColors: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
const params = SubsurfaceScatteringShader;
|
const params = SubsurfaceScatteringShader;
|
||||||
@ -41,14 +53,17 @@ export default {
|
|||||||
if (key === 'diffuse' || key === 'thicknessColor') {
|
if (key === 'diffuse' || key === 'thicknessColor') {
|
||||||
value = new Color(value);
|
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({
|
this.material = new TShaderMaterial({
|
||||||
...params,
|
...params,
|
||||||
uniforms,
|
uniforms,
|
||||||
lights: true,
|
lights: true,
|
||||||
transparent: true,
|
transparent: this.transparent,
|
||||||
|
vertexColors: this.vertexColors,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -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 {
|
import {
|
||||||
Color,
|
Color,
|
||||||
ShaderChunk,
|
ShaderChunk,
|
||||||
@ -45,7 +53,11 @@ const SubsurfaceScatteringShader = {
|
|||||||
uniform vec3 thicknessColor;
|
uniform vec3 thicknessColor;
|
||||||
|
|
||||||
void RE_Direct_Scattering(const in IncidentLight directLight, const in vec2 uv, const in GeometricContext geometry, inout ReflectedLight reflectedLight) {
|
void RE_Direct_Scattering(const in IncidentLight directLight, const in vec2 uv, const in GeometricContext geometry, inout ReflectedLight reflectedLight) {
|
||||||
|
#ifdef USE_COLOR
|
||||||
|
vec3 thickness = vColor * thicknessColor;
|
||||||
|
#else
|
||||||
vec3 thickness = thicknessColor;
|
vec3 thickness = thicknessColor;
|
||||||
|
#endif
|
||||||
vec3 scatteringHalf = normalize(directLight.direction + (geometry.normal * thicknessDistortion));
|
vec3 scatteringHalf = normalize(directLight.direction + (geometry.normal * thicknessDistortion));
|
||||||
float scatteringDot = pow(saturate(dot(geometry.viewDir, -scatteringHalf)), thicknessPower) * thicknessScale;
|
float scatteringDot = pow(saturate(dot(geometry.viewDir, -scatteringHalf)), thicknessPower) * thicknessScale;
|
||||||
vec3 scatteringIllu = (scatteringDot + thicknessAmbient) * thickness;
|
vec3 scatteringIllu = (scatteringDot + thicknessAmbient) * thickness;
|
||||||
|
Loading…
Reference in New Issue
Block a user