@shapediver/viewer.rendering-engine.rendering-engine-threejs 3.0.1 → 3.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/shaders/gem.d.ts +1 -1
- package/dist/shaders/gem.d.ts.map +1 -1
- package/dist/shaders/gem.js +26 -22
- package/dist/shaders/gem.js.map +1 -1
- package/package.json +16 -16
- package/src/shaders/gem.ts +26 -22
- package/src/shaders/gem_frag.glsl +27 -22
- package/src/shaders/gem_vert.glsl +1 -1
package/dist/shaders/gem.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export declare const vert = "\n#define STANDARD\nvarying vec3 vViewPosition;\n#ifdef USE_TRANSMISSION\n\tvarying vec3 vWorldPosition;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\n\n// CUSTOM START\nvarying vec3 frag_position;\nvarying vec3 frag_normal;\n// CUSTOM END\n\nvoid main() {\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <morphcolor_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n #ifdef USE_TRANSMISSION\n vWorldPosition = worldPosition.xyz;\n #endif\n\n // CUSTOM START\n frag_position = position;\n frag_normal = objectNormal;\n // CUSTOM END\n}\n";
|
|
2
|
-
export declare const frag = "\n#define STANDARD\n#ifdef PHYSICAL\n\t#define IOR\n\t#define SPECULAR\n#endif\n\n// CUSTOM START\n#ifdef USE_IMPURITYMAP\n\tuniform sampler2D impurityMap;\n#endif\n// CUSTOM END\n\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\n#ifdef IOR\n\tuniform float ior;\n#endif\n#ifdef SPECULAR\n\tuniform float specularIntensity;\n\tuniform vec3 specularColor;\n\t#ifdef USE_SPECULARINTENSITYMAP\n\t\tuniform sampler2D specularIntensityMap;\n\t#endif\n\t#ifdef USE_SPECULARCOLORMAP\n\t\tuniform sampler2D specularColorMap;\n\t#endif\n#endif\n#ifdef USE_CLEARCOAT\n\tuniform float clearcoat;\n\tuniform float clearcoatRoughness;\n#endif\n#ifdef USE_IRIDESCENCE\n\tuniform float iridescence;\n\tuniform float iridescenceIOR;\n\tuniform float iridescenceThicknessMinimum;\n\tuniform float iridescenceThicknessMaximum;\n#endif\n#ifdef USE_SHEEN\n\tuniform vec3 sheenColor;\n\tuniform float sheenRoughness;\n\t#ifdef USE_SHEENCOLORMAP\n\t\tuniform sampler2D sheenColorMap;\n\t#endif\n\t#ifdef USE_SHEENROUGHNESSMAP\n\t\tuniform sampler2D sheenRoughnessMap;\n\t#endif\n#endif\nvarying vec3 vViewPosition;\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <bsdfs>\n#include <iridescence_fragment>\n#include <cube_uv_reflection_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_physical_pars_fragment>\n#include <fog_pars_fragment>\n#include <lights_pars_begin>\n#include <normal_pars_fragment>\n#include <lights_physical_pars_fragment>\n#include <transmission_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <clearcoat_pars_fragment>\n#include <iridescence_pars_fragment>\n#include <roughnessmap_pars_fragment>\n#include <metalnessmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\n\n\n\n// CUSTOM START\n\nvarying vec4 initialPosition;\nvarying vec3 initialNormal;\n\nvarying vec3 frag_position;\nvarying vec3 frag_normal;\n\nuniform vec3 center;\nuniform float radius;\nuniform samplerCube sphericalNormalMap;\nuniform mat3 normalMatrix;\nuniform mat4 modelMatrix;\n\nuniform float impurityScale;\nuniform vec3 colorTransferBegin;\nuniform vec3 colorTransferEnd;\nuniform float refractionIndex;\nuniform float gamma;\nuniform float contrast;\nuniform float brightness;\nuniform float dispersion;\nuniform float tracingOpacity;\n\n\nvec3 getIBLRadianceVariation( const in vec3 viewDir, const in vec3 normal, const in float roughness ) {\n\t#if defined( ENVMAP_TYPE_CUBE_UV )\n\t\tvec3 reflectVec = reflect( - viewDir, normal );\n\t\t// Mixing the reflection with the normal is more accurate and keeps rough objects from gathering light from behind their tangent plane.\n\t\treflectVec = normalize( mix( reflectVec, normal, roughness * roughness) );\n\t\treflectVec = inverseTransformDirection( reflectVec, viewMatrix );\n\t\tvec4 envMapColor = textureCubeUV( envMap, reflectVec, roughness );\n\t\treturn min(envMapColor.rgb * envMapIntensity, vec3(1.0));\n\t#else\n\t\treturn vec3( 0.0 );\n\t#endif\n}\n\nvec3 calculateReflectedLight(vec3 position, vec3 normal, vec3 viewDir, PhysicalMaterial material, int depth) {\n\t\n\tGeometricContext currentGeometry;\n\tcurrentGeometry.position = (modelMatrix * vec4(position, 1.0)).xyz;\n\n\tmat3 normalMatrix;\n\tnormalMatrix[0] = normalize(modelMatrix[0].xyz);\n\tnormalMatrix[1] = normalize(modelMatrix[1].xyz);\n\tnormalMatrix[2] = normalize(modelMatrix[2].xyz);\n\t\n\t// Calculate the normal vector in world space\n\tcurrentGeometry.normal = normalize(normalMatrix * normal);\n\t\n\t// Calculate the view direction vector in world space\n\tcurrentGeometry.viewDir = normalize(normalMatrix * -viewDir);\n\n #ifdef USE_CLEARCOAT\n currentGeometry.clearcoatNormal = clearcoatNormal;\n #endif\n\n\tReflectedLight rLight;\n\tIncidentLight dLight;\n\n\tfloat temp = material.roughness;\n\tmaterial.roughness = 0.5;\n\n\t#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n\n\t\tPointLight pointLight;\n #if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0\n PointLightShadow pointLightShadow;\n #endif\n\n\t #pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\t\tpointLight = pointLights[ i ];\n getPointLightInfo( pointLight, currentGeometry, dLight );\n #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )\n pointLightShadow = pointLightShadows[ i ];\n dLight.color *= all( bvec2( dLight.visible, receiveShadow ) ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;\n #endif\n\t\t RE_Direct( dLight, currentGeometry, material, rLight );\n\t\t}\n #pragma unroll_loop_end\n\t#endif\n\t#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n SpotLight spotLight;\n #if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0\n SpotLightShadow spotLightShadow;\n #endif\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n spotLight = spotLights[ i ];\n getSpotLightInfo( spotLight, currentGeometry, dLight );\n #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n spotLightShadow = spotLightShadows[ i ];\n dLight.color *= all( bvec2( dLight.visible, receiveShadow ) ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n #endif\n RE_Direct( dLight, currentGeometry, material, rLight );\n }\n #pragma unroll_loop_end\n\t#endif\n\n #if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n DirectionalLight directionalLight;\n #if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0\n DirectionalLightShadow directionalLightShadow;\n #endif\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n directionalLight = directionalLights[ i ];\n getDirectionalLightInfo( directionalLight, currentGeometry, dLight );\n #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\n directionalLightShadow = directionalLightShadows[ i ];\n dLight.color *= all( bvec2( dLight.visible, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n #endif\n RE_Direct( dLight, currentGeometry, material, rLight );\n }\n #pragma unroll_loop_end\n #endif\n\tmaterial.roughness = temp;\n\t\n #if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )\n RectAreaLight rectAreaLight;\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {\n rectAreaLight = rectAreaLights[ i ];\n RE_Direct_RectArea( rectAreaLight, currentGeometry, material, rLight );\n }\n #pragma unroll_loop_end\n #endif\n #if defined( RE_IndirectDiffuse )\n vec3 iblIrradiance = vec3( 0.0 );\n vec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n irradiance += getLightProbeIrradiance( lightProbe, currentGeometry.normal );\n #if ( NUM_HEMI_LIGHTS > 0 )\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], currentGeometry.normal );\n }\n #pragma unroll_loop_end\n #endif\n #endif\n #if defined( RE_IndirectSpecular )\n vec3 radiance = vec3( 0.0 );\n vec3 clearcoatRadiance = vec3( 0.0 );\n #endif\n\n\n #if defined( RE_IndirectDiffuse )\n #ifdef USE_LIGHTMAP\n vec4 lightMapTexel = texture2D( lightMap, vUv2 );\n vec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity;\n irradiance += lightMapIrradiance;\n #endif\n #if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV )\n iblIrradiance += getIBLIrradiance( currentGeometry.normal );\n #endif\n #endif\n #if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n radiance += getIBLRadianceVariation( currentGeometry.viewDir, currentGeometry.normal, material.roughness );\n #ifdef USE_CLEARCOAT\n clearcoatRadiance += getIBLRadianceVariation( currentGeometry.viewDir, currentGeometry.clearcoatNormal, material.clearcoatRoughness );\n #endif\n #endif\n\n #if defined( RE_IndirectDiffuse )\n RE_IndirectDiffuse( irradiance, currentGeometry, material, rLight );\n #endif\n #if defined( RE_IndirectSpecular )\n RE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, currentGeometry, material, rLight );\n #endif\n\n\tif(depth >= 0) {\n\t\tfloat frac = float(depth) / float(TRACING_DEPTH);\n\t\tvec3 colorTransfer = (1.0-frac) * colorTransferBegin + frac * colorTransferEnd;\n\t\trLight.indirectSpecular *= colorTransfer;\n\t\trLight.directSpecular *= colorTransfer;\n\t}\n\n\tvec3 color = rLight.indirectSpecular + rLight.directSpecular + rLight.indirectDiffuse + rLight.directDiffuse;\n\n\t// gamma\n\tcolor = pow(color, vec3(1.0/gamma)); \n\n\t// contrast\n\tcolor.rgb = ((color.rgb - 0.5) * max(contrast, 0.0)) + 0.5; \n\n\t// brightness\n\tcolor.r = min(max(color.r + brightness, 0.0), 1.0);\n\tcolor.g = min(max(color.g + brightness, 0.0), 1.0);\n\tcolor.b = min(max(color.b + brightness, 0.0), 1.0);\n\n\treturn color;\n}\n\nvec3 normalLookUp(vec3 dir) {\n\tvec4 s = textureCube(sphericalNormalMap, dir);\n\tif(s.a < 1.0/256.0) {\n\t\treturn normalize(vec3(-s.x, -s.y, -s.z));\n\t} else if(s.a < 3.0/256.0) {\n\t\treturn normalize(vec3(-s.x, -s.y, s.z));\n\t} else if(s.a < 5.0/256.0) {\n\t\treturn normalize(vec3(-s.x, s.y, -s.z));\n\t} else if(s.a < 7.0/256.0) {\n\t\treturn normalize(vec3(s.x, -s.y, -s.z));\n\t} else if(s.a < 9.0/256.0) {\n\t\treturn normalize(vec3(-s.x, s.y, s.z));\n\t} else if(s.a < 11.0/256.0) {\n\t\treturn normalize(vec3(s.x, -s.y, s.z));\n\t} else if(s.a < 13.0/256.0) {\n\t\treturn normalize(vec3(s.x, s.y, -s.z));\n\t} else {\n\t\treturn normalize(s.xyz);\n\t}\n}\n\n#ifdef USE_IMPURITYMAP\n\tfloat impurityLookUp(vec3 dir) {\n\t\tvec3 c = textureCube(impurityMap, dir.xy).rgb;\n\t\treturn (c.x + c.y + c.z) / 3.0;\n\t}\n#endif\n\nvec3 raySphereIntersection(vec3 o, vec3 d) {\n\n\tvec3 oc = o - center;\n float a = dot(d, d);\n float b = 2.0 * dot(oc, d);\n float c = dot(oc,oc) - radius*radius;\n float discriminant = b*b - 4.0*a*c;\n if(discriminant < 0.0){\n return vec3(0.0);\n }\n else{\n return o +( (-b + sqrt(discriminant)) / (2.0*a)) * d;\n }\n}\n\nvec3 hueToSaturatedColor(float hue) {\n float r,g,b;\n if (hue < 0.25){\n\t\tfloat t = 1.0 - (hue / 0.25);\n r = 1.0;\n g = 1.0;\n b = t; \n\t} else if (hue < 0.5){\n \tfloat t = 1.0 - (hue - 0.25 / 0.25);\n\t\tr = 1.0;\n g = t;\n b = 0.0;\n\t} else if (hue < 0.75){\n \tfloat t = 1.0 - (hue - 0.5 / 0.25);\n\t\tr = t;\n g = 0.0;\n b = 1.0 - t;\n } else {\n \tfloat t = hue - 0.75 / 0.25;\n r = t;\n g = t;\n b = 1.0;\n }\n return vec3(r, g, b) / 0.5 + 0.5;\n}\n// CUSTOM END\n\nvoid main() { \n // CUSTOM START\n vec3 frag_normal_normalized = frag_normal;\n // CUSTOM END\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <roughnessmap_fragment>\n\t#include <metalnessmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <clearcoat_normal_fragment_begin>\n\t#include <clearcoat_normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_physical_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 totalDiffuse = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse;\n\tvec3 totalSpecular = reflectedLight.directSpecular + reflectedLight.indirectSpecular;\n\t#include <transmission_fragment>\n\tvec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance;\n\t#ifdef USE_SHEEN\n\t\tfloat sheenEnergyComp = 1.0 - 0.157 * max3( material.sheenColor );\n\t\toutgoingLight = outgoingLight * sheenEnergyComp + sheenSpecular;\n\t#endif\n\t#ifdef USE_CLEARCOAT\n\t\tfloat dotNVcc = saturate( dot( geometry.clearcoatNormal, geometry.viewDir ) );\n\t\tvec3 Fcc = F_Schlick( material.clearcoatF0, material.clearcoatF90, dotNVcc );\n\t\toutgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + clearcoatSpecular * material.clearcoat;\n\t#endif\n\t#include <output_fragment>\n\n // CUSTOM START\n\t\n // Extract the translation part of the model matrix\n\tvec3 translation = modelMatrix[3].xyz;\n\n\t// Extract the rotation part of the model matrix (3x3 upper-left submatrix)\n\tmat3 rotationMatrix = mat3(modelMatrix);\n\n\t// Calculate the inverse of the rotation matrix (transpose since it's orthogonal)\n\tmat3 inverseRotationMatrix;\n\tinverseRotationMatrix[0] = vec3(rotationMatrix[0].x, rotationMatrix[1].x, rotationMatrix[2].x);\n\tinverseRotationMatrix[1] = vec3(rotationMatrix[0].y, rotationMatrix[1].y, rotationMatrix[2].y);\n\tinverseRotationMatrix[2] = vec3(rotationMatrix[0].z, rotationMatrix[1].z, rotationMatrix[2].z);\n\n\t// Calculate the camera position in model space\n\tvec3 cameraPositionInModelSpace = inverseRotationMatrix * (cameraPosition - translation);\n\n\t// Calculate the initial direction\n\tvec3 initialDirection = normalize(frag_position.xyz - cameraPositionInModelSpace);\n\n\tvec4 outgoingLight2;\n\tfloat r_0 = (1.0-refractionIndex)/(1.0+refractionIndex);\n\tr_0 = r_0*r_0;\n\n\tfloat cos_theta_0 = -dot(initialDirection, frag_normal_normalized);\n\tfloat r_0_outside = (refractionIndex-1.0)/(refractionIndex+1.0);\n\tr_0_outside = r_0_outside*r_0_outside;\n\tfloat initialProbability = r_0_outside + (1.0 - r_0_outside)*pow(1.0 - cos_theta_0, 5.0);\n\n\toutgoingLight2 = vec4(calculateReflectedLight(frag_position, frag_normal_normalized, initialDirection, material, -1), 1.0);\n\t// gl_FragColor = outgoingLight2;\n\t// return;\n\tif(TRACING_DEPTH > 0) \n\t\toutgoingLight2 *= initialProbability;\n\t\t\n\tvec3 tempColor;\n\n\t#ifdef DISPERSION\n\t\tconst int loop = 3;\n\t\tvec3 dispersionColor;\n\t#else\n\t\tconst int loop = 1;\n\t#endif\n\t\t#pragma unroll_loop_start\n\t\tfor(int j = 0; j < loop; j++){\n\t\t\tvec3 refractedDirection = refract(initialDirection, frag_normal_normalized, 1.0/refractionIndex + float(j)*dispersion * 0.025);\n\t\t\tvec3 newPosition = raySphereIntersection(frag_position, refractedDirection);\n\t\t\tvec3 lookUpVector = normalize(newPosition - center);\n\t\t\tvec3 newNormal = normalLookUp(lookUpVector);\n\t\t\tvec3 newDirection = reflect(refractedDirection, newNormal);\n\n\t\t\tfloat currentProbability = 1.0;\n\n\t\t\t#ifdef USE_IMPURITYMAP\n\t\t\t\tfloat impurityProbability = impurityLookUp(lookUpVector);\n\t\t\t\tcurrentProbability -= impurityProbability * impurityScale;\n\t\t\t\t// gl_FragColor = vec4(vec3(impurityProbability), 1.0);\n\t\t\t\t// return;\n\t\t\t#endif\n\t\t\t\n\t\t\t// if(0 == TRACING_DEPTH) {\n\t\t\t// \tgl_FragColor = vec4(0.5 * newNormal + 0.5, 1.0);\n\t\t\t// \treturn;\n\t\t\t// }\n\n\t\t\ttempColor = vec3(0.0);\n\t\t\t#pragma unroll_loop_start\n\t\t\tfor(int i = 0; i < TRACING_DEPTH; i++) {\n\t\t\t\t// small position correction to avoid artefacts\n\t\t\t\tnewPosition = newPosition - lookUpVector * 1e-6;\n\t\t\t\tnewPosition = raySphereIntersection(newPosition, newDirection);\n\t\t\t\tlookUpVector = normalize(newPosition - center);\n\t\t\t\tnewNormal = normalLookUp(lookUpVector);\n\t\t\t\n\t\t\t\tfloat cos_theta = dot(newDirection, newNormal);\n\t\t\t\tfloat ratio;\n\t\t\t\tif(cos_theta > 0.0) {\n\t\t\t\t\tratio = refractionIndex;\n\t\t\t\t} else {\n\t\t\t\t\tcos_theta = -cos_theta;\n\t\t\t\t\tratio = 1.0 / refractionIndex;\n\t\t\t\t}\n\t\t\t\tfloat cos_theta_2 = 1.0 - ratio*ratio * (1.0 - cos_theta*cos_theta);\n\t\t\t\tfloat probability = r_0 + (1.0 - r_0)*pow(1.0 - cos_theta, 5.0);\n\t\t\t\tif(cos_theta_2 < 0.0) probability = 0.0;\n\n\t\t\t\tvec3 refracted = refract(newDirection, newNormal*-1.0, 1.0/refractionIndex);\n\t\t\t\ttempColor += probability * currentProbability * calculateReflectedLight(newPosition, newNormal*-1.0, reflect(refracted, newNormal), material, i);\n\t\t\t\tif(i+1 == TRACING_DEPTH)\n\t\t\t\t\ttempColor += (1.0 - probability) * currentProbability * calculateReflectedLight(newPosition, newNormal, newDirection, material, i);\n\n\t\t\t\tnewDirection = reflect(newDirection, newNormal);\n\n\t\t\t\t// if(i+1 == TRACING_DEPTH) {\n\t\t\t\t// \tgl_FragColor = vec4(0.5 * newNormal + 0.5, 1.0);\n\t\t\t\t// \treturn;\n\t\t\t\t// }\n\n\t\t\t\tcurrentProbability *= (1.0 - probability);\n\t\t\t}\n\t\t\t#pragma unroll_loop_end\n\n\t\t\t#ifdef DISPERSION\n\t\t\t\tif(j == 0) {\n\t\t\t\t\tdispersionColor.r = tempColor.r;\t\n\t\t\t\t} else if(j == 1) {\n\t\t\t\t\tdispersionColor.g = tempColor.g;\t\n\t\t\t\t} else if(j == 2) {\n\t\t\t\t\tdispersionColor.b = tempColor.b;\t\n\t\t\t\t}\n\t\t\t\ttempColor = dispersionColor;\n\t\t\t#endif\n\t\t}\t\n\t\t#pragma unroll_loop_end\n\n\tif(TRACING_DEPTH > 0)\n\t\toutgoingLight2.rgb += (1.0 - initialProbability) * tempColor;\n\n\tfloat alpha = (1.0 - initialProbability) + initialProbability*tracingOpacity;\n\tgl_FragColor = vec4(outgoingLight2.rgb, alpha*diffuseColor.a);\n\n // CUSTOM END\n\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}\n\n";
|
|
2
|
+
export declare const frag = "\n#define STANDARD\n#ifdef PHYSICAL\n\t#define IOR\n\t#define SPECULAR\n#endif\n\n// CUSTOM START\n#ifdef USE_IMPURITYMAP\n\tuniform sampler2D impurityMap;\n#endif\n// CUSTOM END\n\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\n#ifdef IOR\n\tuniform float ior;\n#endif\n#ifdef SPECULAR\n\tuniform float specularIntensity;\n\tuniform vec3 specularColor;\n\t#ifdef USE_SPECULARINTENSITYMAP\n\t\tuniform sampler2D specularIntensityMap;\n\t#endif\n\t#ifdef USE_SPECULARCOLORMAP\n\t\tuniform sampler2D specularColorMap;\n\t#endif\n#endif\n#ifdef USE_CLEARCOAT\n\tuniform float clearcoat;\n\tuniform float clearcoatRoughness;\n#endif\n#ifdef USE_IRIDESCENCE\n\tuniform float iridescence;\n\tuniform float iridescenceIOR;\n\tuniform float iridescenceThicknessMinimum;\n\tuniform float iridescenceThicknessMaximum;\n#endif\n#ifdef USE_SHEEN\n\tuniform vec3 sheenColor;\n\tuniform float sheenRoughness;\n\t#ifdef USE_SHEENCOLORMAP\n\t\tuniform sampler2D sheenColorMap;\n\t#endif\n\t#ifdef USE_SHEENROUGHNESSMAP\n\t\tuniform sampler2D sheenRoughnessMap;\n\t#endif\n#endif\nvarying vec3 vViewPosition;\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <bsdfs>\n#include <iridescence_fragment>\n#include <cube_uv_reflection_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_physical_pars_fragment>\n#include <fog_pars_fragment>\n#include <lights_pars_begin>\n#include <normal_pars_fragment>\n#include <lights_physical_pars_fragment>\n#include <transmission_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <clearcoat_pars_fragment>\n#include <iridescence_pars_fragment>\n#include <roughnessmap_pars_fragment>\n#include <metalnessmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\n\n\n\n// CUSTOM START\n\nvarying vec4 initialPosition;\nvarying vec3 initialNormal;\n\nvarying vec3 frag_position;\nvarying vec3 frag_normal;\n\nuniform vec3 center;\nuniform float radius;\nuniform samplerCube sphericalNormalMap;\nuniform mat3 normalMatrix;\nuniform mat4 modelMatrix;\n\nuniform float impurityScale;\nuniform vec3 colorTransferBegin;\nuniform vec3 colorTransferEnd;\nuniform float refractionIndex;\nuniform float gamma;\nuniform float contrast;\nuniform float brightness;\nuniform float dispersion;\nuniform float tracingOpacity;\n\n\nvec3 getIBLRadianceVariation( const in vec3 viewDir, const in vec3 normal, const in float roughness ) {\n\t#if defined( ENVMAP_TYPE_CUBE_UV )\n\t\tvec3 reflectVec = reflect( - viewDir, normal );\n\t\t// Mixing the reflection with the normal is more accurate and keeps rough objects from gathering light from behind their tangent plane.\n\t\treflectVec = normalize( mix( reflectVec, normal, roughness * roughness) );\n\t\treflectVec = inverseTransformDirection( reflectVec, viewMatrix );\n\t\tvec4 envMapColor = textureCubeUV( envMap, reflectVec, roughness );\n\t\treturn min(envMapColor.rgb * envMapIntensity, vec3(1.0));\n\t#else\n\t\treturn vec3( 0.0 );\n\t#endif\n}\n\nvec3 calculateReflectedLight(vec3 position, vec3 normal, vec3 viewDir, PhysicalMaterial material, int depth) {\n\t\n\tvec3 currentGeometryPosition = (modelMatrix * vec4(position, 1.0)).xyz;\n\n\tmat3 normalMatrix;\n\tnormalMatrix[0] = normalize(modelMatrix[0].xyz);\n\tnormalMatrix[1] = normalize(modelMatrix[1].xyz);\n\tnormalMatrix[2] = normalize(modelMatrix[2].xyz);\n\t\n\t// Calculate the normal vector in world space\n\tvec3 currentGeometryNormal = normalize(normalMatrix * normal);\n\t\n\t// Calculate the view direction vector in world space\n\tvec3 currentGeometryViewDir = normalize(normalMatrix * -viewDir);\n\n vec3 currentGeometryClearcoatNormal;\n\t\n\t#ifdef USE_CLEARCOAT\n currentGeometryClearcoatNormal = clearcoatNormal;\n #endif\n\n\tReflectedLight rLight;\n\tIncidentLight dLight;\n\n\tfloat temp = material.roughness;\n\tmaterial.roughness = 0.5;\n\n\t#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n\n\t\tPointLight pointLight;\n #if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0\n PointLightShadow pointLightShadow;\n #endif\n\n\t #pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\t\tpointLight = pointLights[ i ];\n getPointLightInfo( pointLight, currentGeometryPosition, dLight );\n #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )\n pointLightShadow = pointLightShadows[ i ];\n dLight.color *= all( bvec2( dLight.visible, receiveShadow ) ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;\n #endif\n\t\t RE_Direct( dLight, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );\n\t\t}\n #pragma unroll_loop_end\n\t#endif\n\t#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n SpotLight spotLight;\n #if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0\n SpotLightShadow spotLightShadow;\n #endif\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n spotLight = spotLights[ i ];\n getSpotLightInfo( spotLight, currentGeometryPosition, dLight );\n #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n spotLightShadow = spotLightShadows[ i ];\n dLight.color *= all( bvec2( dLight.visible, receiveShadow ) ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n #endif\n RE_Direct( dLight, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );\n }\n #pragma unroll_loop_end\n\t#endif\n\n #if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n DirectionalLight directionalLight;\n #if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0\n DirectionalLightShadow directionalLightShadow;\n #endif\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n directionalLight = directionalLights[ i ];\n getDirectionalLightInfo( directionalLight, dLight );\n #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\n directionalLightShadow = directionalLightShadows[ i ];\n dLight.color *= all( bvec2( dLight.visible, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n #endif\n RE_Direct( dLight, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );\n }\n #pragma unroll_loop_end\n #endif\n\tmaterial.roughness = temp;\n\t\n #if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )\n RectAreaLight rectAreaLight;\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {\n rectAreaLight = rectAreaLights[ i ];\n RE_Direct_RectArea( rectAreaLight, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );\n }\n #pragma unroll_loop_end\n #endif\n #if defined( RE_IndirectDiffuse )\n vec3 iblIrradiance = vec3( 0.0 );\n vec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n\t\t\n\t\t#if defined( USE_LIGHT_PROBES )\n \tirradiance += getLightProbeIrradiance( lightProbe, currentGeometryNormal );\n\t\t#endif\n #if ( NUM_HEMI_LIGHTS > 0 )\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], currentGeometryNormal );\n }\n #pragma unroll_loop_end\n #endif\n #endif\n #if defined( RE_IndirectSpecular )\n vec3 radiance = vec3( 0.0 );\n vec3 clearcoatRadiance = vec3( 0.0 );\n #endif\n\n\n #if defined( RE_IndirectDiffuse )\n #ifdef USE_LIGHTMAP\n vec4 lightMapTexel = texture2D( lightMap, vUv2 );\n vec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity;\n irradiance += lightMapIrradiance;\n #endif\n #if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV )\n iblIrradiance += getIBLIrradiance( currentGeometryNormal );\n #endif\n #endif\n #if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n radiance += getIBLRadianceVariation( currentGeometryViewDir, currentGeometryNormal, material.roughness );\n #ifdef USE_CLEARCOAT\n clearcoatRadiance += getIBLRadianceVariation( currentGeometryViewDir, currentGeometryClearcoatNormal, material.clearcoatRoughness );\n #endif\n #endif\n\n #if defined( RE_IndirectDiffuse )\n RE_IndirectDiffuse( irradiance, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );\n #endif\n #if defined( RE_IndirectSpecular )\n RE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );\n #endif\n\n\tif(depth >= 0) {\n\t\tfloat frac = float(depth) / float(TRACING_DEPTH);\n\t\tvec3 colorTransfer = (1.0-frac) * colorTransferBegin + frac * colorTransferEnd;\n\t\trLight.indirectSpecular *= colorTransfer;\n\t\trLight.directSpecular *= colorTransfer;\n\t}\n\n\tvec3 color = rLight.indirectSpecular + rLight.directSpecular + rLight.indirectDiffuse + rLight.directDiffuse;\n\n\t// gamma\n\tcolor = pow(color, vec3(1.0/gamma)); \n\n\t// contrast\n\tcolor.rgb = ((color.rgb - 0.5) * max(contrast, 0.0)) + 0.5; \n\n\t// brightness\n\tcolor.r = min(max(color.r + brightness, 0.0), 1.0);\n\tcolor.g = min(max(color.g + brightness, 0.0), 1.0);\n\tcolor.b = min(max(color.b + brightness, 0.0), 1.0);\n\n\treturn color;\n}\n\nvec3 normalLookUp(vec3 dir) {\n\tvec4 s = textureCube(sphericalNormalMap, dir);\n\tif(s.a < 1.0/256.0) {\n\t\treturn normalize(vec3(-s.x, -s.y, -s.z));\n\t} else if(s.a < 3.0/256.0) {\n\t\treturn normalize(vec3(-s.x, -s.y, s.z));\n\t} else if(s.a < 5.0/256.0) {\n\t\treturn normalize(vec3(-s.x, s.y, -s.z));\n\t} else if(s.a < 7.0/256.0) {\n\t\treturn normalize(vec3(s.x, -s.y, -s.z));\n\t} else if(s.a < 9.0/256.0) {\n\t\treturn normalize(vec3(-s.x, s.y, s.z));\n\t} else if(s.a < 11.0/256.0) {\n\t\treturn normalize(vec3(s.x, -s.y, s.z));\n\t} else if(s.a < 13.0/256.0) {\n\t\treturn normalize(vec3(s.x, s.y, -s.z));\n\t} else {\n\t\treturn normalize(s.xyz);\n\t}\n}\n\n#ifdef USE_IMPURITYMAP\n\tfloat impurityLookUp(vec3 dir) {\n\t\tvec3 c = textureCube(impurityMap, dir.xy).rgb;\n\t\treturn (c.x + c.y + c.z) / 3.0;\n\t}\n#endif\n\nvec3 raySphereIntersection(vec3 o, vec3 d) {\n\n\tvec3 oc = o - center;\n float a = dot(d, d);\n float b = 2.0 * dot(oc, d);\n float c = dot(oc,oc) - radius*radius;\n float discriminant = b*b - 4.0*a*c;\n if(discriminant < 0.0){\n return vec3(0.0);\n }\n else{\n return o +( (-b + sqrt(discriminant)) / (2.0*a)) * d;\n }\n}\n\nvec3 hueToSaturatedColor(float hue) {\n float r,g,b;\n if (hue < 0.25){\n\t\tfloat t = 1.0 - (hue / 0.25);\n r = 1.0;\n g = 1.0;\n b = t; \n\t} else if (hue < 0.5){\n \tfloat t = 1.0 - (hue - 0.25 / 0.25);\n\t\tr = 1.0;\n g = t;\n b = 0.0;\n\t} else if (hue < 0.75){\n \tfloat t = 1.0 - (hue - 0.5 / 0.25);\n\t\tr = t;\n g = 0.0;\n b = 1.0 - t;\n } else {\n \tfloat t = hue - 0.75 / 0.25;\n r = t;\n g = t;\n b = 1.0;\n }\n return vec3(r, g, b) / 0.5 + 0.5;\n}\n// CUSTOM END\n\nvoid main() { \n // CUSTOM START\n vec3 frag_normal_normalized = frag_normal;\n // CUSTOM END\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <roughnessmap_fragment>\n\t#include <metalnessmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <clearcoat_normal_fragment_begin>\n\t#include <clearcoat_normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_physical_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 totalDiffuse = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse;\n\tvec3 totalSpecular = reflectedLight.directSpecular + reflectedLight.indirectSpecular;\n\t#include <transmission_fragment>\n\tvec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance;\n\t#ifdef USE_SHEEN\n\t\tfloat sheenEnergyComp = 1.0 - 0.157 * max3( material.sheenColor );\n\t\toutgoingLight = outgoingLight * sheenEnergyComp + sheenSpecular;\n\t#endif\n\t#ifdef USE_CLEARCOAT\n\t\tfloat dotNVcc = saturate( dot( geometry.clearcoatNormal, geometry.viewDir ) );\n\t\tvec3 Fcc = F_Schlick( material.clearcoatF0, material.clearcoatF90, dotNVcc );\n\t\toutgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + clearcoatSpecular * material.clearcoat;\n\t#endif\n\t#include <opaque_fragment>\n\n // CUSTOM START\n\t\n // Extract the translation part of the model matrix\n\tvec3 translation = modelMatrix[3].xyz;\n\n\t// Extract the rotation part of the model matrix (3x3 upper-left submatrix)\n\tmat3 rotationMatrix = mat3(modelMatrix);\n\n\t// Calculate the inverse of the rotation matrix (transpose since it's orthogonal)\n\tmat3 inverseRotationMatrix;\n\tinverseRotationMatrix[0] = vec3(rotationMatrix[0].x, rotationMatrix[1].x, rotationMatrix[2].x);\n\tinverseRotationMatrix[1] = vec3(rotationMatrix[0].y, rotationMatrix[1].y, rotationMatrix[2].y);\n\tinverseRotationMatrix[2] = vec3(rotationMatrix[0].z, rotationMatrix[1].z, rotationMatrix[2].z);\n\n\t// Calculate the camera position in model space\n\tvec3 cameraPositionInModelSpace = inverseRotationMatrix * (cameraPosition - translation);\n\n\t// Calculate the initial direction\n\tvec3 initialDirection = normalize(frag_position.xyz - cameraPositionInModelSpace);\n\n\tvec4 outgoingLight2;\n\tfloat r_0 = (1.0-refractionIndex)/(1.0+refractionIndex);\n\tr_0 = r_0*r_0;\n\n\tfloat cos_theta_0 = -dot(initialDirection, frag_normal_normalized);\n\tfloat r_0_outside = (refractionIndex-1.0)/(refractionIndex+1.0);\n\tr_0_outside = r_0_outside*r_0_outside;\n\tfloat initialProbability = r_0_outside + (1.0 - r_0_outside)*pow(1.0 - cos_theta_0, 5.0);\n\n\toutgoingLight2 = vec4(calculateReflectedLight(frag_position, frag_normal_normalized, initialDirection, material, -1), 1.0);\n\t// gl_FragColor = outgoingLight2;\n\t// return;\n\tif(TRACING_DEPTH > 0) \n\t\toutgoingLight2 *= initialProbability;\n\t\t\n\tvec3 tempColor;\n\n\t#ifdef DISPERSION\n\t\tconst int loop = 3;\n\t\tvec3 dispersionColor;\n\t#else\n\t\tconst int loop = 1;\n\t#endif\n\t\t#pragma unroll_loop_start\n\t\tfor(int j = 0; j < loop; j++){\n\t\t\tvec3 refractedDirection = refract(initialDirection, frag_normal_normalized, 1.0/refractionIndex + float(j)*dispersion * 0.025);\n\t\t\tvec3 newPosition = raySphereIntersection(frag_position, refractedDirection);\n\t\t\tvec3 lookUpVector = normalize(newPosition - center);\n\t\t\tvec3 newNormal = normalLookUp(lookUpVector);\n\t\t\tvec3 newDirection = reflect(refractedDirection, newNormal);\n\n\t\t\tfloat currentProbability = 1.0;\n\n\t\t\t#ifdef USE_IMPURITYMAP\n\t\t\t\tfloat impurityProbability = impurityLookUp(lookUpVector);\n\t\t\t\tcurrentProbability -= impurityProbability * impurityScale;\n\t\t\t\t// gl_FragColor = vec4(vec3(impurityProbability), 1.0);\n\t\t\t\t// return;\n\t\t\t#endif\n\t\t\t\n\t\t\t// if(0 == TRACING_DEPTH) {\n\t\t\t// \tgl_FragColor = vec4(0.5 * newNormal + 0.5, 1.0);\n\t\t\t// \treturn;\n\t\t\t// }\n\n\t\t\ttempColor = vec3(0.0);\n\t\t\t#pragma unroll_loop_start\n\t\t\tfor(int i = 0; i < TRACING_DEPTH; i++) {\n\t\t\t\t// small position correction to avoid artefacts\n\t\t\t\tnewPosition = newPosition - lookUpVector * 1e-6;\n\t\t\t\tnewPosition = raySphereIntersection(newPosition, newDirection);\n\t\t\t\tlookUpVector = normalize(newPosition - center);\n\t\t\t\tnewNormal = normalLookUp(lookUpVector);\n\t\t\t\n\t\t\t\tfloat cos_theta = dot(newDirection, newNormal);\n\t\t\t\tfloat ratio;\n\t\t\t\tif(cos_theta > 0.0) {\n\t\t\t\t\tratio = refractionIndex;\n\t\t\t\t} else {\n\t\t\t\t\tcos_theta = -cos_theta;\n\t\t\t\t\tratio = 1.0 / refractionIndex;\n\t\t\t\t}\n\t\t\t\tfloat cos_theta_2 = 1.0 - ratio*ratio * (1.0 - cos_theta*cos_theta);\n\t\t\t\tfloat probability = r_0 + (1.0 - r_0)*pow(1.0 - cos_theta, 5.0);\n\t\t\t\tif(cos_theta_2 < 0.0) probability = 0.0;\n\n\t\t\t\tvec3 refracted = refract(newDirection, newNormal*-1.0, 1.0/refractionIndex);\n\t\t\t\ttempColor += probability * currentProbability * calculateReflectedLight(newPosition, newNormal*-1.0, reflect(refracted, newNormal), material, i);\n\t\t\t\tif(i+1 == TRACING_DEPTH)\n\t\t\t\t\ttempColor += (1.0 - probability) * currentProbability * calculateReflectedLight(newPosition, newNormal, newDirection, material, i);\n\n\t\t\t\tnewDirection = reflect(newDirection, newNormal);\n\n\t\t\t\t// if(i+1 == TRACING_DEPTH) {\n\t\t\t\t// \tgl_FragColor = vec4(0.5 * newNormal + 0.5, 1.0);\n\t\t\t\t// \treturn;\n\t\t\t\t// }\n\n\t\t\t\tcurrentProbability *= (1.0 - probability);\n\t\t\t}\n\t\t\t#pragma unroll_loop_end\n\n\t\t\t#ifdef DISPERSION\n\t\t\t\tif(j == 0) {\n\t\t\t\t\tdispersionColor.r = tempColor.r;\t\n\t\t\t\t} else if(j == 1) {\n\t\t\t\t\tdispersionColor.g = tempColor.g;\t\n\t\t\t\t} else if(j == 2) {\n\t\t\t\t\tdispersionColor.b = tempColor.b;\t\n\t\t\t\t}\n\t\t\t\ttempColor = dispersionColor;\n\t\t\t#endif\n\t\t}\t\n\t\t#pragma unroll_loop_end\n\n\tif(TRACING_DEPTH > 0)\n\t\toutgoingLight2.rgb += (1.0 - initialProbability) * tempColor;\n\n\tfloat alpha = (1.0 - initialProbability) + initialProbability*tracingOpacity;\n\tgl_FragColor = vec4(outgoingLight2.rgb, alpha*diffuseColor.a);\n\n // CUSTOM END\n\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}\n\n";
|
|
3
3
|
//# sourceMappingURL=gem.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gem.d.ts","sourceRoot":"","sources":["../../src/shaders/gem.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI,s3CAqDhB,CAAC;AAEF,eAAO,MAAM,IAAI,
|
|
1
|
+
{"version":3,"file":"gem.d.ts","sourceRoot":"","sources":["../../src/shaders/gem.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI,s3CAqDhB,CAAC;AAEF,eAAO,MAAM,IAAI,q9lBA2gBhB,CAAA"}
|
package/dist/shaders/gem.js
CHANGED
|
@@ -180,8 +180,7 @@ vec3 getIBLRadianceVariation( const in vec3 viewDir, const in vec3 normal, const
|
|
|
180
180
|
|
|
181
181
|
vec3 calculateReflectedLight(vec3 position, vec3 normal, vec3 viewDir, PhysicalMaterial material, int depth) {
|
|
182
182
|
|
|
183
|
-
|
|
184
|
-
currentGeometry.position = (modelMatrix * vec4(position, 1.0)).xyz;
|
|
183
|
+
vec3 currentGeometryPosition = (modelMatrix * vec4(position, 1.0)).xyz;
|
|
185
184
|
|
|
186
185
|
mat3 normalMatrix;
|
|
187
186
|
normalMatrix[0] = normalize(modelMatrix[0].xyz);
|
|
@@ -189,13 +188,15 @@ vec3 calculateReflectedLight(vec3 position, vec3 normal, vec3 viewDir, PhysicalM
|
|
|
189
188
|
normalMatrix[2] = normalize(modelMatrix[2].xyz);
|
|
190
189
|
|
|
191
190
|
// Calculate the normal vector in world space
|
|
192
|
-
|
|
191
|
+
vec3 currentGeometryNormal = normalize(normalMatrix * normal);
|
|
193
192
|
|
|
194
193
|
// Calculate the view direction vector in world space
|
|
195
|
-
|
|
194
|
+
vec3 currentGeometryViewDir = normalize(normalMatrix * -viewDir);
|
|
196
195
|
|
|
197
|
-
|
|
198
|
-
|
|
196
|
+
vec3 currentGeometryClearcoatNormal;
|
|
197
|
+
|
|
198
|
+
#ifdef USE_CLEARCOAT
|
|
199
|
+
currentGeometryClearcoatNormal = clearcoatNormal;
|
|
199
200
|
#endif
|
|
200
201
|
|
|
201
202
|
ReflectedLight rLight;
|
|
@@ -214,12 +215,12 @@ vec3 calculateReflectedLight(vec3 position, vec3 normal, vec3 viewDir, PhysicalM
|
|
|
214
215
|
#pragma unroll_loop_start
|
|
215
216
|
for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {
|
|
216
217
|
pointLight = pointLights[ i ];
|
|
217
|
-
getPointLightInfo( pointLight,
|
|
218
|
+
getPointLightInfo( pointLight, currentGeometryPosition, dLight );
|
|
218
219
|
#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )
|
|
219
220
|
pointLightShadow = pointLightShadows[ i ];
|
|
220
221
|
dLight.color *= all( bvec2( dLight.visible, receiveShadow ) ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;
|
|
221
222
|
#endif
|
|
222
|
-
RE_Direct( dLight,
|
|
223
|
+
RE_Direct( dLight, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );
|
|
223
224
|
}
|
|
224
225
|
#pragma unroll_loop_end
|
|
225
226
|
#endif
|
|
@@ -231,12 +232,12 @@ vec3 calculateReflectedLight(vec3 position, vec3 normal, vec3 viewDir, PhysicalM
|
|
|
231
232
|
#pragma unroll_loop_start
|
|
232
233
|
for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {
|
|
233
234
|
spotLight = spotLights[ i ];
|
|
234
|
-
getSpotLightInfo( spotLight,
|
|
235
|
+
getSpotLightInfo( spotLight, currentGeometryPosition, dLight );
|
|
235
236
|
#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )
|
|
236
237
|
spotLightShadow = spotLightShadows[ i ];
|
|
237
238
|
dLight.color *= all( bvec2( dLight.visible, receiveShadow ) ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;
|
|
238
239
|
#endif
|
|
239
|
-
RE_Direct( dLight,
|
|
240
|
+
RE_Direct( dLight, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );
|
|
240
241
|
}
|
|
241
242
|
#pragma unroll_loop_end
|
|
242
243
|
#endif
|
|
@@ -249,12 +250,12 @@ vec3 calculateReflectedLight(vec3 position, vec3 normal, vec3 viewDir, PhysicalM
|
|
|
249
250
|
#pragma unroll_loop_start
|
|
250
251
|
for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {
|
|
251
252
|
directionalLight = directionalLights[ i ];
|
|
252
|
-
getDirectionalLightInfo( directionalLight,
|
|
253
|
+
getDirectionalLightInfo( directionalLight, dLight );
|
|
253
254
|
#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )
|
|
254
255
|
directionalLightShadow = directionalLightShadows[ i ];
|
|
255
256
|
dLight.color *= all( bvec2( dLight.visible, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
|
|
256
257
|
#endif
|
|
257
|
-
RE_Direct( dLight,
|
|
258
|
+
RE_Direct( dLight, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );
|
|
258
259
|
}
|
|
259
260
|
#pragma unroll_loop_end
|
|
260
261
|
#endif
|
|
@@ -265,18 +266,21 @@ vec3 calculateReflectedLight(vec3 position, vec3 normal, vec3 viewDir, PhysicalM
|
|
|
265
266
|
#pragma unroll_loop_start
|
|
266
267
|
for ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {
|
|
267
268
|
rectAreaLight = rectAreaLights[ i ];
|
|
268
|
-
RE_Direct_RectArea( rectAreaLight,
|
|
269
|
+
RE_Direct_RectArea( rectAreaLight, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );
|
|
269
270
|
}
|
|
270
271
|
#pragma unroll_loop_end
|
|
271
272
|
#endif
|
|
272
273
|
#if defined( RE_IndirectDiffuse )
|
|
273
274
|
vec3 iblIrradiance = vec3( 0.0 );
|
|
274
275
|
vec3 irradiance = getAmbientLightIrradiance( ambientLightColor );
|
|
275
|
-
|
|
276
|
+
|
|
277
|
+
#if defined( USE_LIGHT_PROBES )
|
|
278
|
+
irradiance += getLightProbeIrradiance( lightProbe, currentGeometryNormal );
|
|
279
|
+
#endif
|
|
276
280
|
#if ( NUM_HEMI_LIGHTS > 0 )
|
|
277
281
|
#pragma unroll_loop_start
|
|
278
282
|
for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {
|
|
279
|
-
irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ],
|
|
283
|
+
irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], currentGeometryNormal );
|
|
280
284
|
}
|
|
281
285
|
#pragma unroll_loop_end
|
|
282
286
|
#endif
|
|
@@ -294,21 +298,21 @@ vec3 calculateReflectedLight(vec3 position, vec3 normal, vec3 viewDir, PhysicalM
|
|
|
294
298
|
irradiance += lightMapIrradiance;
|
|
295
299
|
#endif
|
|
296
300
|
#if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV )
|
|
297
|
-
iblIrradiance += getIBLIrradiance(
|
|
301
|
+
iblIrradiance += getIBLIrradiance( currentGeometryNormal );
|
|
298
302
|
#endif
|
|
299
303
|
#endif
|
|
300
304
|
#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )
|
|
301
|
-
radiance += getIBLRadianceVariation(
|
|
305
|
+
radiance += getIBLRadianceVariation( currentGeometryViewDir, currentGeometryNormal, material.roughness );
|
|
302
306
|
#ifdef USE_CLEARCOAT
|
|
303
|
-
clearcoatRadiance += getIBLRadianceVariation(
|
|
307
|
+
clearcoatRadiance += getIBLRadianceVariation( currentGeometryViewDir, currentGeometryClearcoatNormal, material.clearcoatRoughness );
|
|
304
308
|
#endif
|
|
305
309
|
#endif
|
|
306
310
|
|
|
307
311
|
#if defined( RE_IndirectDiffuse )
|
|
308
|
-
RE_IndirectDiffuse( irradiance,
|
|
312
|
+
RE_IndirectDiffuse( irradiance, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );
|
|
309
313
|
#endif
|
|
310
314
|
#if defined( RE_IndirectSpecular )
|
|
311
|
-
RE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance,
|
|
315
|
+
RE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );
|
|
312
316
|
#endif
|
|
313
317
|
|
|
314
318
|
if(depth >= 0) {
|
|
@@ -442,7 +446,7 @@ void main() {
|
|
|
442
446
|
vec3 Fcc = F_Schlick( material.clearcoatF0, material.clearcoatF90, dotNVcc );
|
|
443
447
|
outgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + clearcoatSpecular * material.clearcoat;
|
|
444
448
|
#endif
|
|
445
|
-
#include <
|
|
449
|
+
#include <opaque_fragment>
|
|
446
450
|
|
|
447
451
|
// CUSTOM START
|
|
448
452
|
|
|
@@ -568,7 +572,7 @@ void main() {
|
|
|
568
572
|
// CUSTOM END
|
|
569
573
|
|
|
570
574
|
#include <tonemapping_fragment>
|
|
571
|
-
#include <
|
|
575
|
+
#include <colorspace_fragment>
|
|
572
576
|
#include <fog_fragment>
|
|
573
577
|
#include <premultiplied_alpha_fragment>
|
|
574
578
|
#include <dithering_fragment>
|
package/dist/shaders/gem.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gem.js","sourceRoot":"","sources":["../../src/shaders/gem.ts"],"names":[],"mappings":";;;AAAa,QAAA,IAAI,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqDnB,CAAC;AAEW,QAAA,IAAI,GAAG
|
|
1
|
+
{"version":3,"file":"gem.js","sourceRoot":"","sources":["../../src/shaders/gem.ts"],"names":[],"mappings":";;;AAAa,QAAA,IAAI,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqDnB,CAAC;AAEW,QAAA,IAAI,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2gBnB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shapediver/viewer.rendering-engine.rendering-engine-threejs",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "Michael Oppitz <michael@shapediver.com>",
|
|
@@ -39,20 +39,20 @@
|
|
|
39
39
|
"testEnvironment": "node"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@shapediver/viewer.data-engine.gltf-converter": "3.0.
|
|
43
|
-
"@shapediver/viewer.data-engine.shared-types": "3.0.
|
|
44
|
-
"@shapediver/viewer.data-engine.tag3d-engine": "3.0.
|
|
45
|
-
"@shapediver/viewer.rendering-engine.animation-engine": "3.0.
|
|
46
|
-
"@shapediver/viewer.rendering-engine.animation-frame-engine": "3.0.
|
|
47
|
-
"@shapediver/viewer.rendering-engine.camera-engine": "3.0.
|
|
48
|
-
"@shapediver/viewer.rendering-engine.canvas-engine": "3.0.
|
|
49
|
-
"@shapediver/viewer.rendering-engine.intersection-engine": "3.0.
|
|
50
|
-
"@shapediver/viewer.rendering-engine.light-engine": "3.0.
|
|
51
|
-
"@shapediver/viewer.rendering-engine.rendering-engine": "3.0.
|
|
52
|
-
"@shapediver/viewer.shared.math": "3.0.
|
|
53
|
-
"@shapediver/viewer.shared.node-tree": "3.0.
|
|
54
|
-
"@shapediver/viewer.shared.services": "3.0.
|
|
55
|
-
"@shapediver/viewer.shared.types": "3.0.
|
|
42
|
+
"@shapediver/viewer.data-engine.gltf-converter": "3.0.3",
|
|
43
|
+
"@shapediver/viewer.data-engine.shared-types": "3.0.3",
|
|
44
|
+
"@shapediver/viewer.data-engine.tag3d-engine": "3.0.3",
|
|
45
|
+
"@shapediver/viewer.rendering-engine.animation-engine": "3.0.3",
|
|
46
|
+
"@shapediver/viewer.rendering-engine.animation-frame-engine": "3.0.3",
|
|
47
|
+
"@shapediver/viewer.rendering-engine.camera-engine": "3.0.3",
|
|
48
|
+
"@shapediver/viewer.rendering-engine.canvas-engine": "3.0.3",
|
|
49
|
+
"@shapediver/viewer.rendering-engine.intersection-engine": "3.0.3",
|
|
50
|
+
"@shapediver/viewer.rendering-engine.light-engine": "3.0.3",
|
|
51
|
+
"@shapediver/viewer.rendering-engine.rendering-engine": "3.0.3",
|
|
52
|
+
"@shapediver/viewer.shared.math": "3.0.3",
|
|
53
|
+
"@shapediver/viewer.shared.node-tree": "3.0.3",
|
|
54
|
+
"@shapediver/viewer.shared.services": "3.0.3",
|
|
55
|
+
"@shapediver/viewer.shared.types": "3.0.3",
|
|
56
56
|
"@tweenjs/tween.js": "^18.6.4",
|
|
57
57
|
"@types/stats.js": "^0.17.0",
|
|
58
58
|
"@types/three": "0.162.0",
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"stats.js": "^0.17.0",
|
|
62
62
|
"three": "0.162.0"
|
|
63
63
|
},
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "701801cf60901ecb3149994899512fff7122b52c"
|
|
65
65
|
}
|
package/src/shaders/gem.ts
CHANGED
|
@@ -178,8 +178,7 @@ vec3 getIBLRadianceVariation( const in vec3 viewDir, const in vec3 normal, const
|
|
|
178
178
|
|
|
179
179
|
vec3 calculateReflectedLight(vec3 position, vec3 normal, vec3 viewDir, PhysicalMaterial material, int depth) {
|
|
180
180
|
|
|
181
|
-
|
|
182
|
-
currentGeometry.position = (modelMatrix * vec4(position, 1.0)).xyz;
|
|
181
|
+
vec3 currentGeometryPosition = (modelMatrix * vec4(position, 1.0)).xyz;
|
|
183
182
|
|
|
184
183
|
mat3 normalMatrix;
|
|
185
184
|
normalMatrix[0] = normalize(modelMatrix[0].xyz);
|
|
@@ -187,13 +186,15 @@ vec3 calculateReflectedLight(vec3 position, vec3 normal, vec3 viewDir, PhysicalM
|
|
|
187
186
|
normalMatrix[2] = normalize(modelMatrix[2].xyz);
|
|
188
187
|
|
|
189
188
|
// Calculate the normal vector in world space
|
|
190
|
-
|
|
189
|
+
vec3 currentGeometryNormal = normalize(normalMatrix * normal);
|
|
191
190
|
|
|
192
191
|
// Calculate the view direction vector in world space
|
|
193
|
-
|
|
192
|
+
vec3 currentGeometryViewDir = normalize(normalMatrix * -viewDir);
|
|
194
193
|
|
|
195
|
-
|
|
196
|
-
|
|
194
|
+
vec3 currentGeometryClearcoatNormal;
|
|
195
|
+
|
|
196
|
+
#ifdef USE_CLEARCOAT
|
|
197
|
+
currentGeometryClearcoatNormal = clearcoatNormal;
|
|
197
198
|
#endif
|
|
198
199
|
|
|
199
200
|
ReflectedLight rLight;
|
|
@@ -212,12 +213,12 @@ vec3 calculateReflectedLight(vec3 position, vec3 normal, vec3 viewDir, PhysicalM
|
|
|
212
213
|
#pragma unroll_loop_start
|
|
213
214
|
for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {
|
|
214
215
|
pointLight = pointLights[ i ];
|
|
215
|
-
getPointLightInfo( pointLight,
|
|
216
|
+
getPointLightInfo( pointLight, currentGeometryPosition, dLight );
|
|
216
217
|
#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )
|
|
217
218
|
pointLightShadow = pointLightShadows[ i ];
|
|
218
219
|
dLight.color *= all( bvec2( dLight.visible, receiveShadow ) ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;
|
|
219
220
|
#endif
|
|
220
|
-
RE_Direct( dLight,
|
|
221
|
+
RE_Direct( dLight, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );
|
|
221
222
|
}
|
|
222
223
|
#pragma unroll_loop_end
|
|
223
224
|
#endif
|
|
@@ -229,12 +230,12 @@ vec3 calculateReflectedLight(vec3 position, vec3 normal, vec3 viewDir, PhysicalM
|
|
|
229
230
|
#pragma unroll_loop_start
|
|
230
231
|
for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {
|
|
231
232
|
spotLight = spotLights[ i ];
|
|
232
|
-
getSpotLightInfo( spotLight,
|
|
233
|
+
getSpotLightInfo( spotLight, currentGeometryPosition, dLight );
|
|
233
234
|
#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )
|
|
234
235
|
spotLightShadow = spotLightShadows[ i ];
|
|
235
236
|
dLight.color *= all( bvec2( dLight.visible, receiveShadow ) ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;
|
|
236
237
|
#endif
|
|
237
|
-
RE_Direct( dLight,
|
|
238
|
+
RE_Direct( dLight, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );
|
|
238
239
|
}
|
|
239
240
|
#pragma unroll_loop_end
|
|
240
241
|
#endif
|
|
@@ -247,12 +248,12 @@ vec3 calculateReflectedLight(vec3 position, vec3 normal, vec3 viewDir, PhysicalM
|
|
|
247
248
|
#pragma unroll_loop_start
|
|
248
249
|
for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {
|
|
249
250
|
directionalLight = directionalLights[ i ];
|
|
250
|
-
getDirectionalLightInfo( directionalLight,
|
|
251
|
+
getDirectionalLightInfo( directionalLight, dLight );
|
|
251
252
|
#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )
|
|
252
253
|
directionalLightShadow = directionalLightShadows[ i ];
|
|
253
254
|
dLight.color *= all( bvec2( dLight.visible, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
|
|
254
255
|
#endif
|
|
255
|
-
RE_Direct( dLight,
|
|
256
|
+
RE_Direct( dLight, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );
|
|
256
257
|
}
|
|
257
258
|
#pragma unroll_loop_end
|
|
258
259
|
#endif
|
|
@@ -263,18 +264,21 @@ vec3 calculateReflectedLight(vec3 position, vec3 normal, vec3 viewDir, PhysicalM
|
|
|
263
264
|
#pragma unroll_loop_start
|
|
264
265
|
for ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {
|
|
265
266
|
rectAreaLight = rectAreaLights[ i ];
|
|
266
|
-
RE_Direct_RectArea( rectAreaLight,
|
|
267
|
+
RE_Direct_RectArea( rectAreaLight, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );
|
|
267
268
|
}
|
|
268
269
|
#pragma unroll_loop_end
|
|
269
270
|
#endif
|
|
270
271
|
#if defined( RE_IndirectDiffuse )
|
|
271
272
|
vec3 iblIrradiance = vec3( 0.0 );
|
|
272
273
|
vec3 irradiance = getAmbientLightIrradiance( ambientLightColor );
|
|
273
|
-
|
|
274
|
+
|
|
275
|
+
#if defined( USE_LIGHT_PROBES )
|
|
276
|
+
irradiance += getLightProbeIrradiance( lightProbe, currentGeometryNormal );
|
|
277
|
+
#endif
|
|
274
278
|
#if ( NUM_HEMI_LIGHTS > 0 )
|
|
275
279
|
#pragma unroll_loop_start
|
|
276
280
|
for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {
|
|
277
|
-
irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ],
|
|
281
|
+
irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], currentGeometryNormal );
|
|
278
282
|
}
|
|
279
283
|
#pragma unroll_loop_end
|
|
280
284
|
#endif
|
|
@@ -292,21 +296,21 @@ vec3 calculateReflectedLight(vec3 position, vec3 normal, vec3 viewDir, PhysicalM
|
|
|
292
296
|
irradiance += lightMapIrradiance;
|
|
293
297
|
#endif
|
|
294
298
|
#if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV )
|
|
295
|
-
iblIrradiance += getIBLIrradiance(
|
|
299
|
+
iblIrradiance += getIBLIrradiance( currentGeometryNormal );
|
|
296
300
|
#endif
|
|
297
301
|
#endif
|
|
298
302
|
#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )
|
|
299
|
-
radiance += getIBLRadianceVariation(
|
|
303
|
+
radiance += getIBLRadianceVariation( currentGeometryViewDir, currentGeometryNormal, material.roughness );
|
|
300
304
|
#ifdef USE_CLEARCOAT
|
|
301
|
-
clearcoatRadiance += getIBLRadianceVariation(
|
|
305
|
+
clearcoatRadiance += getIBLRadianceVariation( currentGeometryViewDir, currentGeometryClearcoatNormal, material.clearcoatRoughness );
|
|
302
306
|
#endif
|
|
303
307
|
#endif
|
|
304
308
|
|
|
305
309
|
#if defined( RE_IndirectDiffuse )
|
|
306
|
-
RE_IndirectDiffuse( irradiance,
|
|
310
|
+
RE_IndirectDiffuse( irradiance, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );
|
|
307
311
|
#endif
|
|
308
312
|
#if defined( RE_IndirectSpecular )
|
|
309
|
-
RE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance,
|
|
313
|
+
RE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );
|
|
310
314
|
#endif
|
|
311
315
|
|
|
312
316
|
if(depth >= 0) {
|
|
@@ -440,7 +444,7 @@ void main() {
|
|
|
440
444
|
vec3 Fcc = F_Schlick( material.clearcoatF0, material.clearcoatF90, dotNVcc );
|
|
441
445
|
outgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + clearcoatSpecular * material.clearcoat;
|
|
442
446
|
#endif
|
|
443
|
-
#include <
|
|
447
|
+
#include <opaque_fragment>
|
|
444
448
|
|
|
445
449
|
// CUSTOM START
|
|
446
450
|
|
|
@@ -566,7 +570,7 @@ void main() {
|
|
|
566
570
|
// CUSTOM END
|
|
567
571
|
|
|
568
572
|
#include <tonemapping_fragment>
|
|
569
|
-
#include <
|
|
573
|
+
#include <colorspace_fragment>
|
|
570
574
|
#include <fog_fragment>
|
|
571
575
|
#include <premultiplied_alpha_fragment>
|
|
572
576
|
#include <dithering_fragment>
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
|
|
1
2
|
#define STANDARD
|
|
2
3
|
#ifdef PHYSICAL
|
|
3
4
|
#define IOR
|
|
@@ -122,8 +123,7 @@ vec3 getIBLRadianceVariation( const in vec3 viewDir, const in vec3 normal, const
|
|
|
122
123
|
|
|
123
124
|
vec3 calculateReflectedLight(vec3 position, vec3 normal, vec3 viewDir, PhysicalMaterial material, int depth) {
|
|
124
125
|
|
|
125
|
-
|
|
126
|
-
currentGeometry.position = (modelMatrix * vec4(position, 1.0)).xyz;
|
|
126
|
+
vec3 currentGeometryPosition = (modelMatrix * vec4(position, 1.0)).xyz;
|
|
127
127
|
|
|
128
128
|
mat3 normalMatrix;
|
|
129
129
|
normalMatrix[0] = normalize(modelMatrix[0].xyz);
|
|
@@ -131,13 +131,15 @@ vec3 calculateReflectedLight(vec3 position, vec3 normal, vec3 viewDir, PhysicalM
|
|
|
131
131
|
normalMatrix[2] = normalize(modelMatrix[2].xyz);
|
|
132
132
|
|
|
133
133
|
// Calculate the normal vector in world space
|
|
134
|
-
|
|
134
|
+
vec3 currentGeometryNormal = normalize(normalMatrix * normal);
|
|
135
135
|
|
|
136
136
|
// Calculate the view direction vector in world space
|
|
137
|
-
|
|
137
|
+
vec3 currentGeometryViewDir = normalize(normalMatrix * -viewDir);
|
|
138
138
|
|
|
139
|
-
|
|
140
|
-
|
|
139
|
+
vec3 currentGeometryClearcoatNormal;
|
|
140
|
+
|
|
141
|
+
#ifdef USE_CLEARCOAT
|
|
142
|
+
currentGeometryClearcoatNormal = clearcoatNormal;
|
|
141
143
|
#endif
|
|
142
144
|
|
|
143
145
|
ReflectedLight rLight;
|
|
@@ -156,12 +158,12 @@ vec3 calculateReflectedLight(vec3 position, vec3 normal, vec3 viewDir, PhysicalM
|
|
|
156
158
|
#pragma unroll_loop_start
|
|
157
159
|
for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {
|
|
158
160
|
pointLight = pointLights[ i ];
|
|
159
|
-
getPointLightInfo( pointLight,
|
|
161
|
+
getPointLightInfo( pointLight, currentGeometryPosition, dLight );
|
|
160
162
|
#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )
|
|
161
163
|
pointLightShadow = pointLightShadows[ i ];
|
|
162
164
|
dLight.color *= all( bvec2( dLight.visible, receiveShadow ) ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;
|
|
163
165
|
#endif
|
|
164
|
-
RE_Direct( dLight,
|
|
166
|
+
RE_Direct( dLight, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );
|
|
165
167
|
}
|
|
166
168
|
#pragma unroll_loop_end
|
|
167
169
|
#endif
|
|
@@ -173,12 +175,12 @@ vec3 calculateReflectedLight(vec3 position, vec3 normal, vec3 viewDir, PhysicalM
|
|
|
173
175
|
#pragma unroll_loop_start
|
|
174
176
|
for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {
|
|
175
177
|
spotLight = spotLights[ i ];
|
|
176
|
-
getSpotLightInfo( spotLight,
|
|
178
|
+
getSpotLightInfo( spotLight, currentGeometryPosition, dLight );
|
|
177
179
|
#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )
|
|
178
180
|
spotLightShadow = spotLightShadows[ i ];
|
|
179
181
|
dLight.color *= all( bvec2( dLight.visible, receiveShadow ) ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;
|
|
180
182
|
#endif
|
|
181
|
-
RE_Direct( dLight,
|
|
183
|
+
RE_Direct( dLight, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );
|
|
182
184
|
}
|
|
183
185
|
#pragma unroll_loop_end
|
|
184
186
|
#endif
|
|
@@ -191,12 +193,12 @@ vec3 calculateReflectedLight(vec3 position, vec3 normal, vec3 viewDir, PhysicalM
|
|
|
191
193
|
#pragma unroll_loop_start
|
|
192
194
|
for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {
|
|
193
195
|
directionalLight = directionalLights[ i ];
|
|
194
|
-
getDirectionalLightInfo( directionalLight,
|
|
196
|
+
getDirectionalLightInfo( directionalLight, dLight );
|
|
195
197
|
#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )
|
|
196
198
|
directionalLightShadow = directionalLightShadows[ i ];
|
|
197
199
|
dLight.color *= all( bvec2( dLight.visible, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
|
|
198
200
|
#endif
|
|
199
|
-
RE_Direct( dLight,
|
|
201
|
+
RE_Direct( dLight, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );
|
|
200
202
|
}
|
|
201
203
|
#pragma unroll_loop_end
|
|
202
204
|
#endif
|
|
@@ -207,18 +209,21 @@ vec3 calculateReflectedLight(vec3 position, vec3 normal, vec3 viewDir, PhysicalM
|
|
|
207
209
|
#pragma unroll_loop_start
|
|
208
210
|
for ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {
|
|
209
211
|
rectAreaLight = rectAreaLights[ i ];
|
|
210
|
-
RE_Direct_RectArea( rectAreaLight,
|
|
212
|
+
RE_Direct_RectArea( rectAreaLight, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );
|
|
211
213
|
}
|
|
212
214
|
#pragma unroll_loop_end
|
|
213
215
|
#endif
|
|
214
216
|
#if defined( RE_IndirectDiffuse )
|
|
215
217
|
vec3 iblIrradiance = vec3( 0.0 );
|
|
216
218
|
vec3 irradiance = getAmbientLightIrradiance( ambientLightColor );
|
|
217
|
-
|
|
219
|
+
|
|
220
|
+
#if defined( USE_LIGHT_PROBES )
|
|
221
|
+
irradiance += getLightProbeIrradiance( lightProbe, currentGeometryNormal );
|
|
222
|
+
#endif
|
|
218
223
|
#if ( NUM_HEMI_LIGHTS > 0 )
|
|
219
224
|
#pragma unroll_loop_start
|
|
220
225
|
for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {
|
|
221
|
-
irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ],
|
|
226
|
+
irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], currentGeometryNormal );
|
|
222
227
|
}
|
|
223
228
|
#pragma unroll_loop_end
|
|
224
229
|
#endif
|
|
@@ -236,21 +241,21 @@ vec3 calculateReflectedLight(vec3 position, vec3 normal, vec3 viewDir, PhysicalM
|
|
|
236
241
|
irradiance += lightMapIrradiance;
|
|
237
242
|
#endif
|
|
238
243
|
#if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV )
|
|
239
|
-
iblIrradiance += getIBLIrradiance(
|
|
244
|
+
iblIrradiance += getIBLIrradiance( currentGeometryNormal );
|
|
240
245
|
#endif
|
|
241
246
|
#endif
|
|
242
247
|
#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )
|
|
243
|
-
radiance += getIBLRadianceVariation(
|
|
248
|
+
radiance += getIBLRadianceVariation( currentGeometryViewDir, currentGeometryNormal, material.roughness );
|
|
244
249
|
#ifdef USE_CLEARCOAT
|
|
245
|
-
clearcoatRadiance += getIBLRadianceVariation(
|
|
250
|
+
clearcoatRadiance += getIBLRadianceVariation( currentGeometryViewDir, currentGeometryClearcoatNormal, material.clearcoatRoughness );
|
|
246
251
|
#endif
|
|
247
252
|
#endif
|
|
248
253
|
|
|
249
254
|
#if defined( RE_IndirectDiffuse )
|
|
250
|
-
RE_IndirectDiffuse( irradiance,
|
|
255
|
+
RE_IndirectDiffuse( irradiance, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );
|
|
251
256
|
#endif
|
|
252
257
|
#if defined( RE_IndirectSpecular )
|
|
253
|
-
RE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance,
|
|
258
|
+
RE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );
|
|
254
259
|
#endif
|
|
255
260
|
|
|
256
261
|
if(depth >= 0) {
|
|
@@ -384,7 +389,7 @@ void main() {
|
|
|
384
389
|
vec3 Fcc = F_Schlick( material.clearcoatF0, material.clearcoatF90, dotNVcc );
|
|
385
390
|
outgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + clearcoatSpecular * material.clearcoat;
|
|
386
391
|
#endif
|
|
387
|
-
#include <
|
|
392
|
+
#include <opaque_fragment>
|
|
388
393
|
|
|
389
394
|
// CUSTOM START
|
|
390
395
|
|
|
@@ -510,7 +515,7 @@ void main() {
|
|
|
510
515
|
// CUSTOM END
|
|
511
516
|
|
|
512
517
|
#include <tonemapping_fragment>
|
|
513
|
-
#include <
|
|
518
|
+
#include <colorspace_fragment>
|
|
514
519
|
#include <fog_fragment>
|
|
515
520
|
#include <premultiplied_alpha_fragment>
|
|
516
521
|
#include <dithering_fragment>
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
|
|
1
2
|
#define STANDARD
|
|
2
3
|
varying vec3 vViewPosition;
|
|
3
4
|
#ifdef USE_TRANSMISSION
|
|
@@ -22,7 +23,6 @@ varying vec3 frag_normal;
|
|
|
22
23
|
|
|
23
24
|
void main() {
|
|
24
25
|
#include <uv_vertex>
|
|
25
|
-
#include <uv2_vertex>
|
|
26
26
|
#include <color_vertex>
|
|
27
27
|
#include <morphcolor_vertex>
|
|
28
28
|
#include <beginnormal_vertex>
|