@aura3d/rendering 1.4.0 → 1.4.2
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/package.json +38 -4
- package/AGENTS.md +0 -46
- package/src/ArchitecturalLightingFixtures.ts +0 -241
- package/src/ArchitecturalMaterialCatalog.ts +0 -130
- package/src/ArchitecturalMeasurementFixtures.ts +0 -155
- package/src/BRDFLut.ts +0 -47
- package/src/CameraFraming.ts +0 -200
- package/src/CanonicalSceneFixtures.ts +0 -95
- package/src/CascadedShadowMaps.ts +0 -449
- package/src/ColorManagement.ts +0 -127
- package/src/CullingFixtures.ts +0 -280
- package/src/DecalGeometry.ts +0 -26
- package/src/DepthPass.ts +0 -110
- package/src/EnvironmentBackgroundPass.ts +0 -194
- package/src/EnvironmentBackgroundResources.ts +0 -309
- package/src/EnvironmentLighting.ts +0 -96
- package/src/EnvironmentMapResources.ts +0 -1026
- package/src/EnvironmentPipeline.ts +0 -69
- package/src/EnvironmentPlatform.ts +0 -1306
- package/src/EnvironmentPreset.ts +0 -155
- package/src/Exposure.ts +0 -66
- package/src/ExternalParityRenderPreset.ts +0 -725
- package/src/ForwardPass.ts +0 -1668
- package/src/FrameVisualMetrics.ts +0 -301
- package/src/Geometry.ts +0 -461
- package/src/GeometryPrimitives.ts +0 -2
- package/src/HDRRenderPipeline.ts +0 -94
- package/src/IBL.ts +0 -86
- package/src/IndexBuffer.ts +0 -57
- package/src/InstancedPBRMaterial.ts +0 -186
- package/src/InstancedUnlitMaterial.ts +0 -60
- package/src/Instancing.ts +0 -19
- package/src/LightCollector.ts +0 -82
- package/src/LightUniforms.ts +0 -47
- package/src/LightingDebug.ts +0 -80
- package/src/LightingDefaults.ts +0 -79
- package/src/LightingRig.ts +0 -301
- package/src/LineGeometry.ts +0 -2
- package/src/Material.ts +0 -209
- package/src/MaterialBinding.ts +0 -131
- package/src/MaterialInstance.ts +0 -59
- package/src/MaterialPresets.ts +0 -272
- package/src/MorphTarget.ts +0 -124
- package/src/MorphTargetPlan.ts +0 -178
- package/src/MorphUnlitMaterial.ts +0 -60
- package/src/NormalMappedPBRMaterial.ts +0 -188
- package/src/OceanFixtures.ts +0 -318
- package/src/PBRLightingDefaults.ts +0 -12
- package/src/PBRMaterial.ts +0 -442
- package/src/PMREM.ts +0 -53
- package/src/PbrReference.ts +0 -681
- package/src/PostProcessPass.ts +0 -2507
- package/src/ProceduralTextureFixtures.ts +0 -393
- package/src/ProductTurntableFixtures.ts +0 -815
- package/src/Raycaster.ts +0 -21
- package/src/ReflectionProbe.ts +0 -13
- package/src/ReflectionSurfaces.ts +0 -219
- package/src/RenderBackend.ts +0 -43
- package/src/RenderDebugViews.ts +0 -138
- package/src/RenderDevice.ts +0 -836
- package/src/RenderGraph.ts +0 -194
- package/src/RenderPass.ts +0 -27
- package/src/RenderPipeline.ts +0 -101
- package/src/RenderQueue.ts +0 -12
- package/src/RenderState.ts +0 -12
- package/src/Renderer.ts +0 -2631
- package/src/RendererDebugOverlay.ts +0 -80
- package/src/RendererFeatureGates.ts +0 -150
- package/src/RendererPostprocessPlan.ts +0 -279
- package/src/RendererTiming.ts +0 -251
- package/src/RendererVisualPipelineReport.ts +0 -836
- package/src/ResourceLifecycle.ts +0 -21
- package/src/Sampler.ts +0 -37
- package/src/SceneOptimization.ts +0 -518
- package/src/ShaderChunks.ts +0 -393
- package/src/ShaderLibrary.ts +0 -2766
- package/src/ShaderModule.ts +0 -36
- package/src/ShaderPreprocessor.ts +0 -260
- package/src/ShaderReflection.ts +0 -201
- package/src/ShadowMap.ts +0 -237
- package/src/ShadowPass.ts +0 -198
- package/src/ShadowProjection.ts +0 -115
- package/src/SkinnedLitMaterial.ts +0 -397
- package/src/SkinnedUnlitMaterial.ts +0 -63
- package/src/SkinningBounds.ts +0 -131
- package/src/SpaceEnvironmentFixtures.ts +0 -200
- package/src/SpriteGeometry.ts +0 -21
- package/src/StereoCameraRig.ts +0 -127
- package/src/StereoEffects.ts +0 -274
- package/src/TerrainFixtures.ts +0 -180
- package/src/Texture.ts +0 -307
- package/src/TextureBinding.ts +0 -91
- package/src/TexturedPBRMaterial.ts +0 -1112
- package/src/TexturedUnlitMaterial.ts +0 -67
- package/src/ToneMapping.ts +0 -105
- package/src/UniformBinder.ts +0 -16
- package/src/UniformLayout.ts +0 -129
- package/src/UnlitMaterial.ts +0 -75
- package/src/VegetationFixtures.ts +0 -314
- package/src/VertexBuffer.ts +0 -120
- package/src/VertexFormat.ts +0 -171
- package/src/VoxelWorldFixtures.ts +0 -280
- package/src/WeatherFixtures.ts +0 -223
- package/src/WebGL2Device.ts +0 -2280
- package/src/WebGL2StateCache.ts +0 -330
- package/src/WebGPUDevice.ts +0 -2877
- package/src/WebGPURenderToTextureProof.ts +0 -139
- package/src/advanced-runtime/AdvancedRenderer.ts +0 -73
- package/src/advanced-runtime/index.ts +0 -9
- package/src/animation/AnimationMaterialStyle.ts +0 -32
- package/src/animation/AnimationRenderPreset.ts +0 -45
- package/src/animation/AnimationToonMaterial.ts +0 -387
- package/src/animation/AnimationVisualQuality.ts +0 -71
- package/src/animation/applyAnimationRenderPreset.ts +0 -180
- package/src/animation/index.ts +0 -5
- package/src/cinematic/BloomPass.ts +0 -26
- package/src/cinematic/CinematicDepthComposition.ts +0 -30
- package/src/cinematic/CinematicEvidence.ts +0 -123
- package/src/cinematic/CinematicLightingRig.ts +0 -144
- package/src/cinematic/CinematicMaterialPresets.ts +0 -130
- package/src/cinematic/CinematicPostProcess.ts +0 -83
- package/src/cinematic/DepthHazePass.ts +0 -30
- package/src/cinematic/EmissivePracticalLightSystem.ts +0 -45
- package/src/cinematic/FilmGrainPass.ts +0 -24
- package/src/cinematic/FogVolumeSystem.ts +0 -30
- package/src/cinematic/GlowCardSystem.ts +0 -44
- package/src/cinematic/RainParticleSystem.ts +0 -151
- package/src/cinematic/VignettePass.ts +0 -25
- package/src/cinematic/WetReflectionApproximation.ts +0 -27
- package/src/cinematic/index.ts +0 -14
- package/src/effects/CollisionModule.ts +0 -64
- package/src/effects/ColorModule.ts +0 -60
- package/src/effects/ForceModule.ts +0 -25
- package/src/effects/GPUParticleBackend.ts +0 -569
- package/src/effects/Particle.ts +0 -108
- package/src/effects/ParticleDiagnostics.ts +0 -224
- package/src/effects/ParticleEffectPresets.ts +0 -147
- package/src/effects/ParticleEmitter.ts +0 -326
- package/src/effects/ParticleModule.ts +0 -26
- package/src/effects/ParticleRenderPass.ts +0 -117
- package/src/effects/ParticleRenderer.ts +0 -132
- package/src/effects/ParticleSystem.ts +0 -333
- package/src/effects/SizeModule.ts +0 -56
- package/src/effects/TrailModule.ts +0 -72
- package/src/effects/VelocityModule.ts +0 -75
- package/src/effects/index.ts +0 -15
- package/src/index.ts +0 -925
- package/src/materials/AlphaSorting.ts +0 -30
- package/src/materials/MaterialExtensions.ts +0 -42
- package/src/materials/PhysicalMaterial.ts +0 -133
- package/src/materials/TransmissionPass.ts +0 -51
- package/src/performance/BVH.ts +0 -18
- package/src/performance/Batcher.ts +0 -2
- package/src/performance/FrustumCuller.ts +0 -9
- package/src/performance/LOD.ts +0 -20
- package/src/performance/Octree.ts +0 -10
- package/src/performance/RenderItemSorting.ts +0 -170
- package/src/performance/RendererStats.ts +0 -43
- package/src/performance/ResourceBudget.ts +0 -44
- package/src/postprocess/BloomPass.ts +0 -28
- package/src/postprocess/CinematicDiagnostics.ts +0 -642
- package/src/postprocess/ColorGradingPass.ts +0 -24
- package/src/postprocess/DepthOfFieldPass.ts +0 -12
- package/src/postprocess/EffectComposer.ts +0 -349
- package/src/postprocess/SSAOPass.ts +0 -20
- package/src/postprocess/index.ts +0 -34
- package/src/production-runtime/AnimationControlsPipeline.ts +0 -77
- package/src/production-runtime/PBRHDRPipeline.ts +0 -381
- package/src/production-runtime/ProductionEffectsPipeline.ts +0 -85
- package/src/production-runtime/ProductionRendererTypes.ts +0 -136
- package/src/production-runtime/ProductionRuntimeRenderer.ts +0 -172
- package/src/production-runtime/ProductionWebGL2Renderer.ts +0 -313
- package/src/production-runtime/ProductionWebGPURenderer.ts +0 -396
- package/src/production-runtime/TransmissionBackdropCapture.ts +0 -130
- package/src/production-runtime/animation/MorphTargetRenderer.ts +0 -2
- package/src/production-runtime/animation/SkinningRenderer.ts +0 -2
- package/src/production-runtime/backends/RendererBackend.ts +0 -17
- package/src/production-runtime/backends/WebGL2RendererBackend.ts +0 -30
- package/src/production-runtime/backends/WebGPURendererBackend.ts +0 -24
- package/src/production-runtime/backends/webgl2/WebGL2Buffer.ts +0 -2
- package/src/production-runtime/backends/webgl2/WebGL2Capabilities.ts +0 -2
- package/src/production-runtime/backends/webgl2/WebGL2RenderTarget.ts +0 -2
- package/src/production-runtime/backends/webgl2/WebGL2Shader.ts +0 -2
- package/src/production-runtime/backends/webgl2/WebGL2StateCache.ts +0 -1
- package/src/production-runtime/backends/webgl2/WebGL2Texture.ts +0 -2
- package/src/production-runtime/backends/webgpu/WebGPUBuffer.ts +0 -2
- package/src/production-runtime/backends/webgpu/WebGPUCapabilities.ts +0 -2
- package/src/production-runtime/backends/webgpu/WebGPURenderTarget.ts +0 -2
- package/src/production-runtime/backends/webgpu/WebGPUShader.ts +0 -2
- package/src/production-runtime/backends/webgpu/WebGPUTexture.ts +0 -2
- package/src/production-runtime/color/ColorManagement.ts +0 -3
- package/src/production-runtime/color/ToneMapping.ts +0 -7
- package/src/production-runtime/diagnostics/FrameCapture.ts +0 -2
- package/src/production-runtime/diagnostics/GPUCapabilities.ts +0 -2
- package/src/production-runtime/diagnostics/RendererStats.ts +0 -2
- package/src/production-runtime/environment/EnvironmentMap.ts +0 -1
- package/src/production-runtime/environment/HDRLoader.ts +0 -57
- package/src/production-runtime/environment/PMREMGenerator.ts +0 -713
- package/src/production-runtime/framegraph/FrameGraph.ts +0 -18
- package/src/production-runtime/framegraph/RenderPass.ts +0 -15
- package/src/production-runtime/geometry/ProjectedDecalGeometry.ts +0 -439
- package/src/production-runtime/index.ts +0 -127
- package/src/production-runtime/lights/LightManager.ts +0 -7
- package/src/production-runtime/lights/ShadowMapRenderer.ts +0 -5
- package/src/production-runtime/materials/GLTFMaterialAdapter.ts +0 -6
- package/src/production-runtime/materials/GLTFPBRMaterialAdapter.ts +0 -2
- package/src/production-runtime/materials/MaterialCompiler.ts +0 -7
- package/src/production-runtime/materials/MaterialTextureBindings.ts +0 -5
- package/src/production-runtime/materials/PBRMaterial.ts +0 -2
- package/src/production-runtime/materials/PBRShaderFeatures.ts +0 -2
- package/src/production-runtime/passes/ContactShadowPass.ts +0 -184
- package/src/production-runtime/passes/DepthPrepass.ts +0 -7
- package/src/production-runtime/passes/OpaquePass.ts +0 -7
- package/src/production-runtime/passes/ShadowPass.ts +0 -7
- package/src/production-runtime/passes/SkyboxPass.ts +0 -7
- package/src/production-runtime/passes/ToneMappingPass.ts +0 -7
- package/src/production-runtime/passes/TransparentPass.ts +0 -7
- package/src/production-runtime/postprocess/BloomPass.ts +0 -51
- package/src/production-runtime/postprocess/ColorGradingPass.ts +0 -49
- package/src/production-runtime/postprocess/DOFPass.ts +0 -47
- package/src/production-runtime/postprocess/FXAAPass.ts +0 -53
- package/src/production-runtime/postprocess/ProductionEffectComposer.ts +0 -78
- package/src/production-runtime/postprocess/ProductionPostProcessTypes.ts +0 -174
- package/src/production-runtime/postprocess/SSAOPass.ts +0 -45
- package/src/production-runtime/resources/GPUBuffer.ts +0 -2
- package/src/production-runtime/resources/GPUTexture.ts +0 -2
- package/src/production-runtime/resources/RenderTarget.ts +0 -3
- package/src/production-runtime/resources/ResourceCache.ts +0 -7
- package/src/production-runtime/scene/Camera.ts +0 -1
- package/src/production-runtime/scene/Lights.ts +0 -2
- package/src/production-runtime/scene/RenderableMesh.ts +0 -2
- package/src/production-runtime/scene/RenderablePrimitive.ts +0 -1
- package/src/production-runtime/scene/RenderableScene.ts +0 -4
- package/src/production-runtime/shaders/ShaderProgramLibrary.ts +0 -7
- package/src/production-runtime/shaders/chunks/brdf.glsl +0 -2
- package/src/production-runtime/shaders/chunks/ibl.glsl +0 -3
- package/src/production-runtime/shaders/chunks/pbr.frag.glsl +0 -47
- package/src/production-runtime/shaders/chunks/pbr.vert.glsl +0 -8
- package/src/production-runtime/shaders/chunks/shadows.glsl +0 -2
- package/src/production-runtime/shaders/wgsl/pbr.wgsl +0 -3
- package/src/production-runtime/shaders/wgsl/postprocess.wgsl +0 -2
- package/src/production-runtime/shaders/wgsl/skybox.wgsl +0 -2
- package/src/shaders/depth.frag.glsl +0 -5
- package/src/shaders/depth.vert.glsl +0 -8
- package/src/shaders/pbr-direct.frag.glsl +0 -687
- package/src/shaders/pbr-direct.vert.glsl +0 -18
- package/src/shaders/unlit.frag.glsl +0 -18
- package/src/shaders/unlit.vert.glsl +0 -13
- package/src/shadows/CascadedShadowPipeline.ts +0 -53
- package/src/shadows/ContactShadows.ts +0 -106
- package/src/shadows/ShadowDebugViews.ts +0 -46
- package/src/threejs-compatibility/InstancingSystem.ts +0 -17
- package/src/threejs-compatibility/LightingSystem.ts +0 -22
- package/src/threejs-compatibility/MaterialSystem.ts +0 -9
- package/src/threejs-compatibility/RenderTargetSystem.ts +0 -35
- package/src/threejs-compatibility/RendererDiagnostics.ts +0 -61
- package/src/threejs-compatibility/SceneRenderer.ts +0 -34
- package/src/threejs-compatibility/ShadowSystem.ts +0 -19
- package/src/threejs-compatibility/TextureSystem.ts +0 -19
- package/src/threejs-compatibility/ThreeCompatRenderer.ts +0 -90
- package/src/threejs-compatibility/TransparencySystem.ts +0 -19
- package/src/threejs-compatibility/index.ts +0 -29
- package/src/threejs-compatibility/performance/BVH.ts +0 -14
- package/src/threejs-compatibility/performance/FrustumCulling.ts +0 -10
- package/src/threejs-compatibility/performance/Instancing.ts +0 -4
- package/src/threejs-compatibility/performance/LODSystem.ts +0 -16
- package/src/threejs-compatibility/performance/OcclusionCulling.ts +0 -6
- package/src/threejs-compatibility/performance/RaycastAcceleration.ts +0 -12
- package/src/threejs-compatibility/performance/RendererProfiler.ts +0 -19
- package/src/threejs-compatibility/performance/TextureStreaming.ts +0 -4
- package/src/threejs-compatibility/performance/index.ts +0 -12
- package/src/threejs-compatibility/postprocess/BloomPass.ts +0 -16
- package/src/threejs-compatibility/postprocess/ColorGradingPass.ts +0 -16
- package/src/threejs-compatibility/postprocess/DepthOfFieldPass.ts +0 -21
- package/src/threejs-compatibility/postprocess/EffectComposer.ts +0 -14
- package/src/threejs-compatibility/postprocess/FXAAPass.ts +0 -15
- package/src/threejs-compatibility/postprocess/MotionBlurPass.ts +0 -20
- package/src/threejs-compatibility/postprocess/OutlinePass.ts +0 -21
- package/src/threejs-compatibility/postprocess/PostProcessTypes.ts +0 -169
- package/src/threejs-compatibility/postprocess/RenderPass.ts +0 -9
- package/src/threejs-compatibility/postprocess/SMAAPass.ts +0 -15
- package/src/threejs-compatibility/postprocess/SSAOPass.ts +0 -21
- package/src/threejs-compatibility/postprocess/ShaderPass.ts +0 -7
- package/src/threejs-compatibility/postprocess/TAAPass.ts +0 -15
- package/src/threejs-compatibility/postprocess/VignettePass.ts +0 -16
- package/src/threejs-compatibility/postprocess/index.ts +0 -15
- package/src/threejs-compatibility/shaders/NodeMaterial.ts +0 -21
- package/src/threejs-compatibility/shaders/RawShaderMaterial.ts +0 -6
- package/src/threejs-compatibility/shaders/ShaderDiagnostics.ts +0 -17
- package/src/threejs-compatibility/shaders/ShaderMaterial.ts +0 -18
- package/src/threejs-compatibility/shaders/ThreeCompatShaderChunks.ts +0 -6
- package/src/threejs-compatibility/shaders/Uniforms.ts +0 -18
- package/src/threejs-compatibility/shaders/index.ts +0 -9
- package/src/threejs-compatibility/vfx/GPUPointCloud.ts +0 -7
- package/src/threejs-compatibility/vfx/LineRenderer.ts +0 -13
- package/src/threejs-compatibility/vfx/ParticleSystem.ts +0 -23
- package/src/threejs-compatibility/vfx/SpriteSystem.ts +0 -14
- package/src/threejs-compatibility/vfx/TrailRenderer.ts +0 -8
- package/src/threejs-compatibility/vfx/VFXDiagnostics.ts +0 -23
- package/src/threejs-compatibility/vfx/index.ts +0 -9
- package/src/threejs-example-parity/index.ts +0 -205
- package/src/webgpu/WebGPUBuffer.ts +0 -1
- package/src/webgpu/WebGPUCompute.ts +0 -2
- package/src/webgpu/WebGPUPipelineCache.ts +0 -15
- package/src/webgpu/WebGPUPostProcess.ts +0 -2
- package/src/webgpu/WebGPUTexture.ts +0 -2
- package/tsconfig.json +0 -26
- package/vitest.config.ts +0 -20
|
@@ -1,687 +0,0 @@
|
|
|
1
|
-
#version 300 es
|
|
2
|
-
// @aura3d-shader:pbr-direct
|
|
3
|
-
precision highp float;
|
|
4
|
-
struct A3DLight {
|
|
5
|
-
vec4 colorIntensity;
|
|
6
|
-
vec4 positionRange;
|
|
7
|
-
vec4 directionKind;
|
|
8
|
-
};
|
|
9
|
-
vec3 a3dLambert(vec3 normal, vec3 lightDirection, vec3 lightColor, float intensity) {
|
|
10
|
-
float ndotl = max(dot(normalize(normal), normalize(lightDirection)), 0.0);
|
|
11
|
-
return lightColor * intensity * ndotl;
|
|
12
|
-
}
|
|
13
|
-
const float A3D_PI = 3.14159265359;
|
|
14
|
-
const float A3D_INV_PI = 0.31830988618;
|
|
15
|
-
const float A3D_EPSILON = 0.00001;
|
|
16
|
-
const float A3D_MIN_ROUGHNESS = 0.045;
|
|
17
|
-
float a3dSaturate(float value) {
|
|
18
|
-
return clamp(value, 0.0, 1.0);
|
|
19
|
-
}
|
|
20
|
-
vec3 a3dFresnelSchlick(vec3 f0, float vDotH) {
|
|
21
|
-
float f = pow(a3dSaturate(1.0 - vDotH), 5.0);
|
|
22
|
-
return f0 + (1.0 - f0) * f;
|
|
23
|
-
}
|
|
24
|
-
vec3 a3dFresnelSchlickSpecular(vec3 f0, float vDotH, float specularFactor) {
|
|
25
|
-
float f = pow(a3dSaturate(1.0 - vDotH), 5.0);
|
|
26
|
-
vec3 f90 = vec3(max(clamp(specularFactor, 0.0, 1.0), max(max(f0.r, f0.g), f0.b)));
|
|
27
|
-
return f0 + (f90 - f0) * f;
|
|
28
|
-
}
|
|
29
|
-
vec3 a3dFresnelSchlickRoughness(vec3 f0, float nDotV, float roughness) {
|
|
30
|
-
float smoothness = 1.0 - clamp(roughness, 0.0, 1.0);
|
|
31
|
-
return f0 + (max(vec3(smoothness), f0) - f0) * pow(a3dSaturate(1.0 - nDotV), 5.0);
|
|
32
|
-
}
|
|
33
|
-
vec3 a3dFresnelSchlickRoughnessSpecular(vec3 f0, float nDotV, float roughness, float specularFactor) {
|
|
34
|
-
float smoothness = 1.0 - clamp(roughness, 0.0, 1.0);
|
|
35
|
-
vec3 f90 = vec3(max(clamp(smoothness * specularFactor, 0.0, 1.0), max(max(f0.r, f0.g), f0.b)));
|
|
36
|
-
return f0 + (f90 - f0) * pow(a3dSaturate(1.0 - nDotV), 5.0);
|
|
37
|
-
}
|
|
38
|
-
float a3dDistributionGGX(float nDotH, float roughness) {
|
|
39
|
-
float alpha = max(roughness, A3D_MIN_ROUGHNESS);
|
|
40
|
-
alpha *= alpha;
|
|
41
|
-
float alpha2 = alpha * alpha;
|
|
42
|
-
float nDotH2 = nDotH * nDotH;
|
|
43
|
-
float denom = nDotH2 * (alpha2 - 1.0) + 1.0;
|
|
44
|
-
return alpha2 / max(A3D_PI * denom * denom, A3D_EPSILON);
|
|
45
|
-
}
|
|
46
|
-
float a3dGeometrySmithGGXCorrelated(float nDotV, float nDotL, float roughness) {
|
|
47
|
-
float alpha = max(roughness, A3D_MIN_ROUGHNESS);
|
|
48
|
-
alpha *= alpha;
|
|
49
|
-
float alpha2 = alpha * alpha;
|
|
50
|
-
float lambdaV = nDotL * sqrt(max((nDotV - alpha2 * nDotV) * nDotV + alpha2, A3D_EPSILON));
|
|
51
|
-
float lambdaL = nDotV * sqrt(max((nDotL - alpha2 * nDotL) * nDotL + alpha2, A3D_EPSILON));
|
|
52
|
-
return 0.5 / max(lambdaV + lambdaL, A3D_EPSILON);
|
|
53
|
-
}
|
|
54
|
-
float a3dDiffuseBurley(float nDotV, float nDotL, float lDotH, float roughness) {
|
|
55
|
-
float energyBias = mix(0.0, 0.5, roughness);
|
|
56
|
-
float energyFactor = mix(1.0, 1.0 / 1.51, roughness);
|
|
57
|
-
float fd90 = energyBias + 2.0 * lDotH * lDotH * roughness;
|
|
58
|
-
float lightScatter = 1.0 + (fd90 - 1.0) * pow(a3dSaturate(1.0 - nDotL), 5.0);
|
|
59
|
-
float viewScatter = 1.0 + (fd90 - 1.0) * pow(a3dSaturate(1.0 - nDotV), 5.0);
|
|
60
|
-
return lightScatter * viewScatter * energyFactor;
|
|
61
|
-
}
|
|
62
|
-
vec3 a3dPbrF0(vec3 albedo, float metallic, float specularFactor, vec3 specularColorFactor) {
|
|
63
|
-
vec3 dielectricF0 = vec3(0.04) * clamp(specularFactor, 0.0, 1.0) * clamp(specularColorFactor, vec3(0.0), vec3(1.0));
|
|
64
|
-
return mix(dielectricF0, clamp(albedo, vec3(0.0), vec3(1.0)), clamp(metallic, 0.0, 1.0));
|
|
65
|
-
}
|
|
66
|
-
vec3 a3dPbrDirectLight(
|
|
67
|
-
vec3 normal,
|
|
68
|
-
vec3 viewDirection,
|
|
69
|
-
vec3 lightDirection,
|
|
70
|
-
vec3 lightColor,
|
|
71
|
-
float lightIntensity,
|
|
72
|
-
vec3 albedo,
|
|
73
|
-
float metallic,
|
|
74
|
-
float roughness,
|
|
75
|
-
float specularFactor,
|
|
76
|
-
vec3 specularColorFactor
|
|
77
|
-
) {
|
|
78
|
-
vec3 N = normalize(normal);
|
|
79
|
-
vec3 V = normalize(viewDirection);
|
|
80
|
-
vec3 L = normalize(lightDirection);
|
|
81
|
-
vec3 H = normalize(V + L);
|
|
82
|
-
float nDotL = a3dSaturate(dot(N, L));
|
|
83
|
-
float nDotV = max(a3dSaturate(dot(N, V)), A3D_EPSILON);
|
|
84
|
-
float nDotH = a3dSaturate(dot(N, H));
|
|
85
|
-
float vDotH = a3dSaturate(dot(V, H));
|
|
86
|
-
float lDotH = a3dSaturate(dot(L, H));
|
|
87
|
-
vec3 f0 = a3dPbrF0(albedo, metallic, specularFactor, specularColorFactor);
|
|
88
|
-
vec3 F = a3dFresnelSchlickSpecular(f0, vDotH, specularFactor);
|
|
89
|
-
float D = a3dDistributionGGX(nDotH, roughness);
|
|
90
|
-
float G = a3dGeometrySmithGGXCorrelated(nDotV, nDotL, roughness);
|
|
91
|
-
vec3 specular = D * G * F;
|
|
92
|
-
vec3 kd = (vec3(1.0) - F) * (1.0 - clamp(metallic, 0.0, 1.0));
|
|
93
|
-
vec3 diffuse = kd * albedo * A3D_INV_PI * a3dDiffuseBurley(nDotV, nDotL, lDotH, clamp(roughness, 0.0, 1.0));
|
|
94
|
-
return (diffuse + specular) * lightColor * lightIntensity * nDotL;
|
|
95
|
-
}
|
|
96
|
-
vec3 a3dPbrEnvironmentLight(
|
|
97
|
-
vec3 normal,
|
|
98
|
-
vec3 viewDirection,
|
|
99
|
-
vec3 diffuseIrradiance,
|
|
100
|
-
vec3 specularRadiance,
|
|
101
|
-
vec3 albedo,
|
|
102
|
-
float metallic,
|
|
103
|
-
float roughness,
|
|
104
|
-
float specularFactor,
|
|
105
|
-
vec3 specularColorFactor
|
|
106
|
-
) {
|
|
107
|
-
float nDotV = max(a3dSaturate(dot(normalize(normal), normalize(viewDirection))), A3D_EPSILON);
|
|
108
|
-
vec3 f0 = a3dPbrF0(albedo, metallic, specularFactor, specularColorFactor);
|
|
109
|
-
vec3 F = a3dFresnelSchlickRoughnessSpecular(f0, nDotV, roughness, specularFactor);
|
|
110
|
-
vec3 kd = (vec3(1.0) - F) * (1.0 - clamp(metallic, 0.0, 1.0));
|
|
111
|
-
vec3 diffuse = kd * albedo * diffuseIrradiance;
|
|
112
|
-
vec3 specular = specularRadiance * F;
|
|
113
|
-
return diffuse + specular;
|
|
114
|
-
}
|
|
115
|
-
vec3 a3dPbrEnvironmentLightSplitSum(
|
|
116
|
-
vec3 normal,
|
|
117
|
-
vec3 viewDirection,
|
|
118
|
-
vec3 diffuseIrradiance,
|
|
119
|
-
vec3 specularRadiance,
|
|
120
|
-
vec2 environmentBrdf,
|
|
121
|
-
vec3 albedo,
|
|
122
|
-
float metallic,
|
|
123
|
-
float roughness,
|
|
124
|
-
float specularFactor,
|
|
125
|
-
vec3 specularColorFactor
|
|
126
|
-
) {
|
|
127
|
-
float nDotV = max(a3dSaturate(dot(normalize(normal), normalize(viewDirection))), A3D_EPSILON);
|
|
128
|
-
vec3 f0 = a3dPbrF0(albedo, metallic, specularFactor, specularColorFactor);
|
|
129
|
-
vec3 F = a3dFresnelSchlickRoughnessSpecular(f0, nDotV, roughness, specularFactor);
|
|
130
|
-
vec3 kd = (vec3(1.0) - F) * (1.0 - clamp(metallic, 0.0, 1.0));
|
|
131
|
-
vec3 diffuse = kd * albedo * diffuseIrradiance;
|
|
132
|
-
vec2 brdf = clamp(environmentBrdf, vec2(0.0), vec2(1.0));
|
|
133
|
-
float hasSplitSum = step(0.0001, brdf.x + brdf.y);
|
|
134
|
-
vec3 splitSumFresnel = F * brdf.x + vec3(brdf.y);
|
|
135
|
-
vec3 specular = specularRadiance * mix(F, splitSumFresnel, hasSplitSum);
|
|
136
|
-
return diffuse + specular;
|
|
137
|
-
}
|
|
138
|
-
vec3 a3dApplyMetalRough(vec3 baseColor, float metallic, float roughness) {
|
|
139
|
-
float dielectric = clamp(1.0 - metallic, 0.0, 1.0);
|
|
140
|
-
float energy = mix(0.08, 1.0, dielectric) * (1.0 - clamp(roughness, 0.0, 1.0) * 0.35);
|
|
141
|
-
return baseColor * energy;
|
|
142
|
-
}
|
|
143
|
-
vec3 a3dApplyAdvancedPbrLobes(
|
|
144
|
-
vec3 baseColor,
|
|
145
|
-
float clearcoatFactor,
|
|
146
|
-
float clearcoatRoughnessFactor,
|
|
147
|
-
float transmissionFactor,
|
|
148
|
-
float diffuseTransmissionFactor,
|
|
149
|
-
vec3 diffuseTransmissionColorFactor,
|
|
150
|
-
float transmissionFallbackEnergy,
|
|
151
|
-
float volumeThicknessFactor,
|
|
152
|
-
float volumeAttenuationDistance,
|
|
153
|
-
vec3 volumeAttenuationColor,
|
|
154
|
-
float ior,
|
|
155
|
-
float specularFactor,
|
|
156
|
-
vec3 specularColorFactor,
|
|
157
|
-
vec3 sheenColorFactor,
|
|
158
|
-
float sheenRoughnessFactor,
|
|
159
|
-
float anisotropyStrength,
|
|
160
|
-
float anisotropyRotation,
|
|
161
|
-
float iridescenceFactor,
|
|
162
|
-
float iridescenceIor,
|
|
163
|
-
float iridescenceThicknessMinimum,
|
|
164
|
-
float iridescenceThicknessMaximum,
|
|
165
|
-
float dispersion
|
|
166
|
-
) {
|
|
167
|
-
float clearcoatRoughness = max(clamp(clearcoatRoughnessFactor, 0.0, 1.0), 0.18);
|
|
168
|
-
float clearcoat = clamp(clearcoatFactor, 0.0, 1.0);
|
|
169
|
-
float transmission = clamp(transmissionFactor, 0.0, 1.0);
|
|
170
|
-
float diffuseTransmission = clamp(diffuseTransmissionFactor, 0.0, 1.0) * (1.0 - transmission);
|
|
171
|
-
float volumeThickness = max(volumeThicknessFactor, 0.0);
|
|
172
|
-
float volumeTravel = clamp(volumeThickness / max(volumeAttenuationDistance, 0.0001), 0.0, 16.0);
|
|
173
|
-
vec3 volumeAttenuation = pow(clamp(volumeAttenuationColor, vec3(0.0001), vec3(1.0)), vec3(volumeTravel));
|
|
174
|
-
float iorBoost = clamp((ior - 1.0) / 1.5, 0.0, 1.0);
|
|
175
|
-
float specular = clamp(specularFactor, 0.0, 1.0);
|
|
176
|
-
float sheenRoughness = clamp(sheenRoughnessFactor, 0.0, 1.0);
|
|
177
|
-
float sheen = 1.0 - sheenRoughness;
|
|
178
|
-
vec3 transmitted = mix(baseColor, vec3(dot(baseColor, vec3(0.2126, 0.7152, 0.0722))), transmission * 0.35);
|
|
179
|
-
transmitted = mix(transmitted, clamp(diffuseTransmissionColorFactor, vec3(0.0), vec3(1.0)), diffuseTransmission);
|
|
180
|
-
transmitted = mix(transmitted, transmitted * volumeAttenuation, transmission * step(0.0001, volumeThickness));
|
|
181
|
-
float fallbackEnergy = clamp(transmissionFallbackEnergy, 0.0, 1.0);
|
|
182
|
-
// The WebGL fallback has no scene-color refraction; keep clear glass from turning into a bright white plate.
|
|
183
|
-
float fallbackTransmissionEnergy = mix(1.0, fallbackEnergy, transmission);
|
|
184
|
-
float fallbackSpecularEnergy = mix(1.0, max(fallbackEnergy < 0.079 ? clamp(fallbackEnergy * 8.0, 0.0, 1.0) : fallbackEnergy, 0.18), transmission);
|
|
185
|
-
float thickIorTransmissionLift = mix(1.0, 1.28, iorBoost * transmission * smoothstep(0.45, 1.0, volumeThickness));
|
|
186
|
-
transmitted *= fallbackTransmissionEnergy * thickIorTransmissionLift;
|
|
187
|
-
float iorF0 = pow((max(ior, 1.0) - 1.0) / (max(ior, 1.0) + 1.0), 2.0);
|
|
188
|
-
float specularGloss = pow(1.0 - clearcoatRoughness, 2.0);
|
|
189
|
-
vec3 specularLobe = clamp(specularColorFactor, vec3(0.0), vec3(1.0))
|
|
190
|
-
* specular
|
|
191
|
-
* fallbackSpecularEnergy
|
|
192
|
-
* transmission
|
|
193
|
-
* (0.018 + iorF0 * 0.46 + transmission * 0.04)
|
|
194
|
-
* (0.3 + specularGloss * 0.42);
|
|
195
|
-
float clearcoatGloss = pow(1.0 - clearcoatRoughness, 2.0);
|
|
196
|
-
vec3 clearcoatLobe = vec3(clearcoat * (0.022 + iorBoost * 0.045) * (0.28 + clearcoatGloss * 0.42));
|
|
197
|
-
float sheenGloss = pow(1.0 - sheenRoughness, 2.0);
|
|
198
|
-
vec3 sheenLobe = sheenColorFactor * sheen * (0.05 + sheenGloss * 0.18);
|
|
199
|
-
float anisotropy = clamp(anisotropyStrength, 0.0, 1.0);
|
|
200
|
-
float anisotropyDirection = 0.5 + 0.5 * cos(anisotropyRotation * 2.0);
|
|
201
|
-
vec3 anisotropyLobe = vec3(anisotropy * mix(0.025, 0.085, anisotropyDirection));
|
|
202
|
-
float iridescence = clamp(iridescenceFactor, 0.0, 1.0);
|
|
203
|
-
float iridescenceThickness = clamp((iridescenceThicknessMinimum + iridescenceThicknessMaximum) * 0.5, 0.0, 1200.0);
|
|
204
|
-
float iridescencePhase = clamp((iridescenceThickness - 100.0) / 1100.0, 0.0, 1.0) * 6.2831853;
|
|
205
|
-
float iridescenceIorBoost = clamp((iridescenceIor - 1.0) / 2.0, 0.0, 1.0);
|
|
206
|
-
vec3 iridescenceColor = 0.5 + 0.5 * cos(iridescencePhase + vec3(0.0, 2.0943951, 4.1887902));
|
|
207
|
-
vec3 iridescenceLobe = iridescenceColor * iridescence * (0.04 + iridescenceIorBoost * 0.04);
|
|
208
|
-
float dispersionAmount = clamp(dispersion / 100.0, 0.0, 1.0);
|
|
209
|
-
vec3 dispersionTint = mix(vec3(1.0), vec3(1.04, 0.98, 0.94), dispersionAmount * transmission);
|
|
210
|
-
float sheenEnergy = max(max(sheenLobe.r, sheenLobe.g), sheenLobe.b);
|
|
211
|
-
float layerEnergy = clamp(clearcoat * 0.08 + sheenEnergy * 0.26 + anisotropy * 0.035 + iridescence * 0.03, 0.0, 0.28);
|
|
212
|
-
vec3 layeredBase = transmitted * dispersionTint * (1.0 - layerEnergy);
|
|
213
|
-
return max(vec3(0.0), layeredBase);
|
|
214
|
-
}
|
|
215
|
-
vec3 a3dPbrIridescenceColor(float minimumThickness, float maximumThickness, float iridescenceIor) {
|
|
216
|
-
float thickness = clamp((minimumThickness + maximumThickness) * 0.5, 0.0, 1200.0);
|
|
217
|
-
float phase = clamp((thickness - 100.0) / 1100.0, 0.0, 1.0) * 6.2831853;
|
|
218
|
-
float iorShift = clamp((iridescenceIor - 1.0) / 2.0, 0.0, 1.0) * 0.65;
|
|
219
|
-
return clamp(0.5 + 0.5 * cos(phase + iorShift + vec3(0.0, 2.0943951, 4.1887902)), vec3(0.0), vec3(1.0));
|
|
220
|
-
}
|
|
221
|
-
vec3 a3dPbrExtensionDirectLight(
|
|
222
|
-
vec3 normal,
|
|
223
|
-
vec3 viewDirection,
|
|
224
|
-
vec3 lightDirection,
|
|
225
|
-
vec3 lightColor,
|
|
226
|
-
float lightIntensity,
|
|
227
|
-
float clearcoat,
|
|
228
|
-
float clearcoatRoughness,
|
|
229
|
-
vec3 sheenColor,
|
|
230
|
-
float sheenRoughness,
|
|
231
|
-
float anisotropy,
|
|
232
|
-
float anisotropyRotation,
|
|
233
|
-
float iridescence,
|
|
234
|
-
float iridescenceIor,
|
|
235
|
-
float iridescenceThicknessMinimum,
|
|
236
|
-
float iridescenceThicknessMaximum
|
|
237
|
-
) {
|
|
238
|
-
vec3 N = normalize(normal);
|
|
239
|
-
vec3 V = normalize(viewDirection);
|
|
240
|
-
vec3 L = normalize(lightDirection);
|
|
241
|
-
vec3 H = normalize(V + L);
|
|
242
|
-
float nDotL = a3dSaturate(dot(N, L));
|
|
243
|
-
float nDotV = max(a3dSaturate(dot(N, V)), A3D_EPSILON);
|
|
244
|
-
float nDotH = a3dSaturate(dot(N, H));
|
|
245
|
-
float vDotH = a3dSaturate(dot(V, H));
|
|
246
|
-
float clearcoatRough = clamp(clearcoatRoughness, 0.18, 1.0);
|
|
247
|
-
vec3 clearcoatF = a3dFresnelSchlick(vec3(0.04), vDotH);
|
|
248
|
-
float clearcoatD = a3dDistributionGGX(nDotH, clearcoatRough);
|
|
249
|
-
float clearcoatG = a3dGeometrySmithGGXCorrelated(nDotV, nDotL, clearcoatRough);
|
|
250
|
-
vec3 clearcoatLobe = clearcoatF * clearcoatD * clearcoatG * clamp(clearcoat, 0.0, 1.0) * 0.12;
|
|
251
|
-
float sheenStrength = (1.0 - clamp(sheenRoughness, 0.0, 1.0)) * pow(a3dSaturate(1.0 - vDotH), 5.0);
|
|
252
|
-
vec3 sheenLobe = clamp(sheenColor, vec3(0.0), vec3(1.0)) * sheenStrength * 0.18;
|
|
253
|
-
vec3 anisotropyAxis = normalize(vec3(cos(anisotropyRotation), 0.0, sin(anisotropyRotation)));
|
|
254
|
-
float anisotropyBand = pow(abs(dot(H, anisotropyAxis)), mix(28.0, 6.0, clearcoatRough));
|
|
255
|
-
vec3 anisotropyLobe = vec3(clamp(anisotropy, 0.0, 1.0) * anisotropyBand * 0.055);
|
|
256
|
-
vec3 iridescenceColor = a3dPbrIridescenceColor(iridescenceThicknessMinimum, iridescenceThicknessMaximum, iridescenceIor);
|
|
257
|
-
vec3 iridescenceLobe = iridescenceColor * clamp(iridescence, 0.0, 1.0) * clearcoatF * pow(a3dSaturate(1.0 - nDotV), 2.0) * 0.22;
|
|
258
|
-
return (clearcoatLobe + sheenLobe + anisotropyLobe + iridescenceLobe) * lightColor * lightIntensity * nDotL;
|
|
259
|
-
}
|
|
260
|
-
vec3 a3dPbrExtensionEnvironmentLight(
|
|
261
|
-
vec3 normal,
|
|
262
|
-
vec3 viewDirection,
|
|
263
|
-
vec3 specularRadiance,
|
|
264
|
-
float clearcoat,
|
|
265
|
-
float clearcoatRoughness,
|
|
266
|
-
vec3 sheenColor,
|
|
267
|
-
float sheenRoughness,
|
|
268
|
-
float anisotropy,
|
|
269
|
-
float anisotropyRotation,
|
|
270
|
-
float iridescence,
|
|
271
|
-
float iridescenceIor,
|
|
272
|
-
float iridescenceThicknessMinimum,
|
|
273
|
-
float iridescenceThicknessMaximum
|
|
274
|
-
) {
|
|
275
|
-
float nDotV = max(a3dSaturate(dot(normalize(normal), normalize(viewDirection))), A3D_EPSILON);
|
|
276
|
-
float clearcoatGloss = pow(1.0 - clamp(clearcoatRoughness, 0.18, 1.0), 2.0);
|
|
277
|
-
vec3 clearcoatLobe = specularRadiance * clamp(clearcoat, 0.0, 1.0) * (0.018 + clearcoatGloss * 0.055);
|
|
278
|
-
vec3 sheenLobe = clamp(sheenColor, vec3(0.0), vec3(1.0)) * (1.0 - clamp(sheenRoughness, 0.0, 1.0)) * pow(a3dSaturate(1.0 - nDotV), 5.0) * 0.12;
|
|
279
|
-
float anisotropyBand = 0.5 + 0.5 * cos(anisotropyRotation * 2.0);
|
|
280
|
-
vec3 anisotropyLobe = specularRadiance * clamp(anisotropy, 0.0, 1.0) * mix(0.025, 0.07, anisotropyBand);
|
|
281
|
-
vec3 iridescenceColor = a3dPbrIridescenceColor(iridescenceThicknessMinimum, iridescenceThicknessMaximum, iridescenceIor);
|
|
282
|
-
vec3 iridescenceLobe = specularRadiance * iridescenceColor * clamp(iridescence, 0.0, 1.0) * pow(a3dSaturate(1.0 - nDotV), 1.5) * 0.1;
|
|
283
|
-
return clearcoatLobe + sheenLobe + anisotropyLobe + iridescenceLobe;
|
|
284
|
-
}
|
|
285
|
-
uniform vec4 u_baseColor;
|
|
286
|
-
uniform float u_alphaCutoff;
|
|
287
|
-
uniform float u_metallic;
|
|
288
|
-
uniform float u_roughness;
|
|
289
|
-
uniform vec3 u_environmentColor;
|
|
290
|
-
uniform float u_environmentIntensity;
|
|
291
|
-
uniform vec3 u_environmentSkyColor;
|
|
292
|
-
uniform vec3 u_environmentHorizonColor;
|
|
293
|
-
uniform vec3 u_environmentGroundColor;
|
|
294
|
-
uniform vec3 u_environmentSpecularColor;
|
|
295
|
-
uniform float u_environmentMapIntensity;
|
|
296
|
-
uniform float u_environmentSpecularIntensity;
|
|
297
|
-
uniform sampler2D u_environmentMapTexture;
|
|
298
|
-
uniform samplerCube u_environmentCubeMapTexture;
|
|
299
|
-
uniform float u_environmentCubeMapTextureEnabled;
|
|
300
|
-
uniform float u_environmentMapTextureEnabled;
|
|
301
|
-
uniform float u_environmentMapTextureIntensity;
|
|
302
|
-
uniform float u_environmentMapTextureSpecularIntensity;
|
|
303
|
-
uniform float u_environmentMapTextureRotation;
|
|
304
|
-
uniform float u_environmentMapTextureMipCount;
|
|
305
|
-
uniform float u_environmentMapTextureEncoding;
|
|
306
|
-
uniform sampler2D u_environmentBrdfLutTexture;
|
|
307
|
-
uniform float u_environmentBrdfLutEnabled;
|
|
308
|
-
uniform vec3 u_emissiveColor;
|
|
309
|
-
uniform float u_emissiveStrength;
|
|
310
|
-
uniform float u_clearcoatFactor;
|
|
311
|
-
uniform float u_clearcoatRoughnessFactor;
|
|
312
|
-
uniform float u_transmissionFactor;
|
|
313
|
-
uniform float u_diffuseTransmissionFactor;
|
|
314
|
-
uniform vec3 u_diffuseTransmissionColorFactor;
|
|
315
|
-
uniform float u_transmissionFallbackEnergy;
|
|
316
|
-
uniform float u_volumeThicknessFactor;
|
|
317
|
-
uniform float u_volumeAttenuationDistance;
|
|
318
|
-
uniform vec3 u_volumeAttenuationColor;
|
|
319
|
-
uniform float u_transmissionParallaxStrength;
|
|
320
|
-
uniform vec3 u_transmissionParallaxBoxMin;
|
|
321
|
-
uniform vec3 u_transmissionParallaxBoxMax;
|
|
322
|
-
uniform float u_transmissionBounceCount;
|
|
323
|
-
uniform float u_transmissionCausticStrength;
|
|
324
|
-
uniform float u_ior;
|
|
325
|
-
uniform float u_specularFactor;
|
|
326
|
-
uniform vec3 u_specularColorFactor;
|
|
327
|
-
uniform vec3 u_sheenColorFactor;
|
|
328
|
-
uniform float u_sheenRoughnessFactor;
|
|
329
|
-
uniform float u_anisotropyStrength;
|
|
330
|
-
uniform float u_anisotropyRotation;
|
|
331
|
-
uniform float u_iridescenceFactor;
|
|
332
|
-
uniform float u_iridescenceIor;
|
|
333
|
-
uniform float u_iridescenceThicknessMinimum;
|
|
334
|
-
uniform float u_iridescenceThicknessMaximum;
|
|
335
|
-
uniform float u_dispersion;
|
|
336
|
-
uniform float u_lightCount;
|
|
337
|
-
uniform vec4 u_lightData[64];
|
|
338
|
-
uniform sampler2D u_shadowMapTexture;
|
|
339
|
-
uniform float u_shadowMapEnabled;
|
|
340
|
-
uniform mat4 u_shadowMapMatrix;
|
|
341
|
-
uniform float u_shadowMapStrength;
|
|
342
|
-
uniform float u_shadowMapBias;
|
|
343
|
-
uniform float u_shadowMapSlopeBias;
|
|
344
|
-
uniform vec2 u_shadowMapTexelSize;
|
|
345
|
-
uniform float u_shadowPcfSampleCount;
|
|
346
|
-
uniform vec4 u_shadowPcfSamples[32];
|
|
347
|
-
uniform sampler2D u_pointShadowMapTexture;
|
|
348
|
-
uniform float u_pointShadowMapEnabled;
|
|
349
|
-
uniform vec3 u_pointShadowLightPosition;
|
|
350
|
-
uniform float u_pointShadowRange;
|
|
351
|
-
uniform mat4 u_pointShadowFaceMatrices[6];
|
|
352
|
-
uniform vec4 u_pointShadowFaceRects[6];
|
|
353
|
-
uniform float u_pointShadowStrength;
|
|
354
|
-
uniform float u_pointShadowBias;
|
|
355
|
-
uniform float u_pointShadowSlopeBias;
|
|
356
|
-
uniform vec2 u_pointShadowTexelSize;
|
|
357
|
-
uniform float u_pointShadowPcfSampleCount;
|
|
358
|
-
uniform vec4 u_pointShadowPcfSamples[32];
|
|
359
|
-
uniform float u_outputColorSpace;
|
|
360
|
-
uniform vec3 u_cameraPosition;
|
|
361
|
-
uniform float u_environmentFogEnabled;
|
|
362
|
-
uniform float u_environmentFogMode;
|
|
363
|
-
uniform vec3 u_environmentFogColor;
|
|
364
|
-
uniform float u_environmentFogNear;
|
|
365
|
-
uniform float u_environmentFogFar;
|
|
366
|
-
uniform float u_environmentFogDensity;
|
|
367
|
-
uniform float u_environmentFogHeightFalloff;
|
|
368
|
-
uniform float u_environmentFogHeightReference;
|
|
369
|
-
uniform float u_environmentFogMaxOpacity;
|
|
370
|
-
in vec3 v_normal;
|
|
371
|
-
in vec3 v_worldPosition;
|
|
372
|
-
in vec4 v_vertexColor;
|
|
373
|
-
out vec4 outColor;
|
|
374
|
-
float a3dEnvironmentFogFactor(vec3 worldPosition) {
|
|
375
|
-
if (u_environmentFogEnabled < 0.5) return 0.0;
|
|
376
|
-
float distanceToCamera = length(u_cameraPosition - worldPosition);
|
|
377
|
-
float factor = 0.0;
|
|
378
|
-
if (u_environmentFogMode < 1.5) {
|
|
379
|
-
factor = (distanceToCamera - u_environmentFogNear) / max(u_environmentFogFar - u_environmentFogNear, 0.000001);
|
|
380
|
-
} else if (u_environmentFogMode < 2.5) {
|
|
381
|
-
factor = 1.0 - exp(-max(u_environmentFogDensity, 0.0) * distanceToCamera);
|
|
382
|
-
} else {
|
|
383
|
-
float scaledDensity = max(u_environmentFogDensity, 0.0) * distanceToCamera;
|
|
384
|
-
factor = 1.0 - exp(-(scaledDensity * scaledDensity));
|
|
385
|
-
}
|
|
386
|
-
float heightMultiplier = u_environmentFogHeightFalloff > 0.0
|
|
387
|
-
? exp(-max(0.0, worldPosition.y - u_environmentFogHeightReference) * u_environmentFogHeightFalloff)
|
|
388
|
-
: 1.0;
|
|
389
|
-
return clamp(factor * heightMultiplier, 0.0, 1.0) * clamp(u_environmentFogMaxOpacity, 0.0, 1.0);
|
|
390
|
-
}
|
|
391
|
-
vec3 a3dApplyEnvironmentFog(vec3 linearColor, vec3 worldPosition) {
|
|
392
|
-
float fogFactor = a3dEnvironmentFogFactor(worldPosition);
|
|
393
|
-
return mix(linearColor, u_environmentFogColor, fogFactor);
|
|
394
|
-
}
|
|
395
|
-
vec2 a3dEnvironmentEquirectUv(vec3 direction, float rotation) {
|
|
396
|
-
vec3 d = normalize(direction);
|
|
397
|
-
float u = atan(d.z, d.x) / 6.28318530718 + 0.5 + rotation;
|
|
398
|
-
float v = acos(clamp(d.y, -1.0, 1.0)) / 3.14159265359;
|
|
399
|
-
return vec2(fract(u), clamp(v, 0.0, 1.0));
|
|
400
|
-
}
|
|
401
|
-
vec3 a3dEnvironmentCubeDirection(vec3 direction, float rotation) {
|
|
402
|
-
float angle = rotation * 6.28318530718;
|
|
403
|
-
float c = cos(angle);
|
|
404
|
-
float s = sin(angle);
|
|
405
|
-
vec3 d = normalize(direction);
|
|
406
|
-
return normalize(vec3(c * d.x - s * d.z, d.y, s * d.x + c * d.z));
|
|
407
|
-
}
|
|
408
|
-
vec3 a3dPbrDecodeEnvironmentSrgb(vec3 encodedColor) {
|
|
409
|
-
return max(encodedColor, vec3(0.0));
|
|
410
|
-
}
|
|
411
|
-
vec3 a3dPbrDecodeEnvironmentRgbe(vec4 encodedSample) {
|
|
412
|
-
float exponent = encodedSample.a * 255.0;
|
|
413
|
-
float scale = exponent <= 0.0 ? 0.0 : exp2(exponent - 128.0) * (255.0 / 256.0);
|
|
414
|
-
return max(encodedSample.rgb * scale, vec3(0.0));
|
|
415
|
-
}
|
|
416
|
-
vec3 a3dPbrDecodeEnvironmentSample(vec4 encodedSample) {
|
|
417
|
-
if (u_environmentMapTextureEncoding > 1.5) return max(encodedSample.rgb, vec3(0.0));
|
|
418
|
-
if (u_environmentMapTextureEncoding > 0.5) return a3dPbrDecodeEnvironmentRgbe(encodedSample);
|
|
419
|
-
return a3dPbrDecodeEnvironmentSrgb(encodedSample.rgb);
|
|
420
|
-
}
|
|
421
|
-
vec3 a3dPbrBoundHdrTransmissionRadiance(vec3 radiance) {
|
|
422
|
-
vec3 nonNegative = max(radiance, vec3(0.0));
|
|
423
|
-
return nonNegative / (vec3(1.0) + max(nonNegative - vec3(1.0), vec3(0.0)));
|
|
424
|
-
}
|
|
425
|
-
vec3 a3dPbrBoundHdrSpecularRadiance(vec3 radiance) {
|
|
426
|
-
vec3 nonNegative = max(radiance, vec3(0.0));
|
|
427
|
-
vec3 softKnee = nonNegative / (vec3(1.0) + max(nonNegative - vec3(1.0), vec3(0.0)) * 0.58);
|
|
428
|
-
float maxChannel = max(max(softKnee.r, softKnee.g), softKnee.b);
|
|
429
|
-
return maxChannel > 1.65 ? softKnee * (1.65 / maxChannel) : softKnee;
|
|
430
|
-
}
|
|
431
|
-
vec3 a3dPbrClampSampledSpecularEdgeEnergy(vec3 radiance, float nDotV, float roughness) {
|
|
432
|
-
float faceOn = smoothstep(0.12, 0.55, clamp(nDotV, 0.0, 1.0));
|
|
433
|
-
float roughEnergy = mix(0.6, 1.0, clamp(roughness, 0.0, 1.0));
|
|
434
|
-
float edgeCap = mix(0.12, 1.2, faceOn) * roughEnergy;
|
|
435
|
-
float edgeScale = mix(0.14, 0.92, faceOn);
|
|
436
|
-
vec3 bounded = min(radiance * edgeScale, vec3(edgeCap));
|
|
437
|
-
return max(bounded, vec3(0.0));
|
|
438
|
-
}
|
|
439
|
-
vec4 a3dPbrEnvironmentSampleRaw(vec3 direction, float lod) {
|
|
440
|
-
vec4 equirectSample = textureLod(u_environmentMapTexture, a3dEnvironmentEquirectUv(direction, u_environmentMapTextureRotation), lod);
|
|
441
|
-
vec4 cubeSample = textureLod(u_environmentCubeMapTexture, a3dEnvironmentCubeDirection(direction, u_environmentMapTextureRotation), lod);
|
|
442
|
-
return mix(equirectSample, cubeSample, step(0.5, u_environmentCubeMapTextureEnabled));
|
|
443
|
-
}
|
|
444
|
-
vec3 a3dPbrBoxProjectedDirection(vec3 worldPosition, vec3 direction, vec3 boxMin, vec3 boxMax) {
|
|
445
|
-
vec3 safeDirection = normalize(direction);
|
|
446
|
-
vec3 invDirection = 1.0 / max(abs(safeDirection), vec3(0.0001)) * sign(safeDirection);
|
|
447
|
-
vec3 firstPlane = mix(boxMin, boxMax, step(vec3(0.0), safeDirection));
|
|
448
|
-
vec3 distances = (firstPlane - worldPosition) * invDirection;
|
|
449
|
-
float travel = min(min(
|
|
450
|
-
distances.x > 0.0 ? distances.x : 100000.0,
|
|
451
|
-
distances.y > 0.0 ? distances.y : 100000.0
|
|
452
|
-
), distances.z > 0.0 ? distances.z : 100000.0);
|
|
453
|
-
vec3 hitPosition = worldPosition + safeDirection * travel;
|
|
454
|
-
vec3 boxCenter = (boxMin + boxMax) * 0.5;
|
|
455
|
-
return normalize(hitPosition - boxCenter);
|
|
456
|
-
}
|
|
457
|
-
float a3dForwardShadowFactor(vec3 worldPosition, vec3 normal, vec3 lightDirection) {
|
|
458
|
-
if (u_shadowMapEnabled < 0.5) return 1.0;
|
|
459
|
-
vec4 lightPosition = u_shadowMapMatrix * vec4(worldPosition, 1.0);
|
|
460
|
-
vec3 projected = lightPosition.xyz / max(lightPosition.w, 0.0001);
|
|
461
|
-
vec2 uv = projected.xy * 0.5 + 0.5;
|
|
462
|
-
if (uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0) return 1.0;
|
|
463
|
-
vec3 receiverNormal = normalize(normal);
|
|
464
|
-
vec3 receiverLightDirection = lightDirection / max(length(lightDirection), 0.0001);
|
|
465
|
-
float normalDotLight = clamp(abs(dot(receiverNormal, receiverLightDirection)), 0.0, 1.0);
|
|
466
|
-
float slopeReceiverBias = (1.0 - normalDotLight) * u_shadowMapSlopeBias * max(u_shadowMapTexelSize.x, u_shadowMapTexelSize.y);
|
|
467
|
-
float receiverDepth = projected.z * 0.5 + 0.5 - u_shadowMapBias - slopeReceiverBias;
|
|
468
|
-
float shadowed = 0.0;
|
|
469
|
-
float totalWeight = 0.0;
|
|
470
|
-
int sampleCount = clamp(int(u_shadowPcfSampleCount), 1, 32);
|
|
471
|
-
for (int i = 0; i < 32; ++i) {
|
|
472
|
-
if (i >= sampleCount) break;
|
|
473
|
-
vec4 sampleData = u_shadowPcfSamples[i];
|
|
474
|
-
float weight = max(sampleData.z, 0.0);
|
|
475
|
-
vec2 offset = sampleData.xy * u_shadowMapTexelSize;
|
|
476
|
-
float storedDepth = texture(u_shadowMapTexture, uv + offset).r;
|
|
477
|
-
shadowed += (receiverDepth > storedDepth ? 1.0 : 0.0) * weight;
|
|
478
|
-
totalWeight += weight;
|
|
479
|
-
}
|
|
480
|
-
float occlusion = totalWeight > 0.0 ? shadowed / totalWeight : 0.0;
|
|
481
|
-
return mix(1.0, 1.0 - occlusion, clamp(u_shadowMapStrength, 0.0, 1.0));
|
|
482
|
-
}
|
|
483
|
-
float a3dPointShadowFaceIndex(vec3 direction) {
|
|
484
|
-
vec3 absoluteDirection = abs(direction);
|
|
485
|
-
if (absoluteDirection.x >= absoluteDirection.y && absoluteDirection.x >= absoluteDirection.z) return direction.x >= 0.0 ? 0.0 : 1.0;
|
|
486
|
-
if (absoluteDirection.y >= absoluteDirection.x && absoluteDirection.y >= absoluteDirection.z) return direction.y >= 0.0 ? 2.0 : 3.0;
|
|
487
|
-
return direction.z >= 0.0 ? 4.0 : 5.0;
|
|
488
|
-
}
|
|
489
|
-
float a3dPointShadowFactor(vec3 worldPosition, vec3 normal, vec3 lightDirection) {
|
|
490
|
-
if (u_pointShadowMapEnabled < 0.5) return 1.0;
|
|
491
|
-
vec3 lightToFragment = worldPosition - u_pointShadowLightPosition;
|
|
492
|
-
float distanceToLight = length(lightToFragment);
|
|
493
|
-
if (distanceToLight > u_pointShadowRange) return 1.0;
|
|
494
|
-
int faceIndex = int(a3dPointShadowFaceIndex(lightToFragment));
|
|
495
|
-
vec4 lightPosition = u_pointShadowFaceMatrices[faceIndex] * vec4(worldPosition, 1.0);
|
|
496
|
-
vec3 projected = lightPosition.xyz / max(lightPosition.w, 0.0001);
|
|
497
|
-
vec2 localUv = projected.xy * 0.5 + 0.5;
|
|
498
|
-
if (localUv.x < 0.0 || localUv.x > 1.0 || localUv.y < 0.0 || localUv.y > 1.0) return 1.0;
|
|
499
|
-
vec4 rect = u_pointShadowFaceRects[faceIndex];
|
|
500
|
-
vec2 uv = rect.xy + localUv * rect.zw;
|
|
501
|
-
vec3 receiverNormal = normalize(normal);
|
|
502
|
-
vec3 receiverLightDirection = lightDirection / max(length(lightDirection), 0.0001);
|
|
503
|
-
float normalDotLight = clamp(abs(dot(receiverNormal, receiverLightDirection)), 0.0, 1.0);
|
|
504
|
-
float slopeReceiverBias = (1.0 - normalDotLight) * u_pointShadowSlopeBias * max(u_pointShadowTexelSize.x, u_pointShadowTexelSize.y);
|
|
505
|
-
float receiverDepth = projected.z * 0.5 + 0.5 - u_pointShadowBias - slopeReceiverBias;
|
|
506
|
-
float shadowed = 0.0;
|
|
507
|
-
float totalWeight = 0.0;
|
|
508
|
-
int sampleCount = clamp(int(u_pointShadowPcfSampleCount), 1, 32);
|
|
509
|
-
for (int i = 0; i < 32; ++i) {
|
|
510
|
-
if (i >= sampleCount) break;
|
|
511
|
-
vec4 sampleData = u_pointShadowPcfSamples[i];
|
|
512
|
-
float weight = max(sampleData.z, 0.0);
|
|
513
|
-
vec2 offset = sampleData.xy * u_pointShadowTexelSize;
|
|
514
|
-
float storedDepth = texture(u_pointShadowMapTexture, uv + offset).r;
|
|
515
|
-
shadowed += (receiverDepth > storedDepth ? 1.0 : 0.0) * weight;
|
|
516
|
-
totalWeight += weight;
|
|
517
|
-
}
|
|
518
|
-
float occlusion = totalWeight > 0.0 ? shadowed / totalWeight : 0.0;
|
|
519
|
-
return mix(1.0, 1.0 - occlusion, clamp(u_pointShadowStrength, 0.0, 1.0));
|
|
520
|
-
}
|
|
521
|
-
vec3 a3dPbrEncodeOutput(vec3 linearColor) {
|
|
522
|
-
vec3 color = max(linearColor, vec3(0.0));
|
|
523
|
-
vec3 filmic = clamp((color * (2.51 * color + 0.03)) / (color * (2.43 * color + 0.59) + 0.14), vec3(0.0), vec3(1.0));
|
|
524
|
-
vec3 srgb = pow(filmic, vec3(1.0 / 2.2));
|
|
525
|
-
return mix(color, srgb, step(0.5, u_outputColorSpace));
|
|
526
|
-
}
|
|
527
|
-
void main() {
|
|
528
|
-
vec3 normal = normalize(v_normal);
|
|
529
|
-
if (!gl_FrontFacing) normal = -normal;
|
|
530
|
-
vec3 viewDirection = normalize(u_cameraPosition - v_worldPosition);
|
|
531
|
-
vec3 materialBase = a3dApplyAdvancedPbrLobes(
|
|
532
|
-
u_baseColor.rgb * v_vertexColor.rgb,
|
|
533
|
-
u_clearcoatFactor,
|
|
534
|
-
u_clearcoatRoughnessFactor,
|
|
535
|
-
u_transmissionFactor,
|
|
536
|
-
u_diffuseTransmissionFactor,
|
|
537
|
-
u_diffuseTransmissionColorFactor,
|
|
538
|
-
u_transmissionFallbackEnergy,
|
|
539
|
-
u_volumeThicknessFactor,
|
|
540
|
-
u_volumeAttenuationDistance,
|
|
541
|
-
u_volumeAttenuationColor,
|
|
542
|
-
u_ior,
|
|
543
|
-
u_specularFactor,
|
|
544
|
-
u_specularColorFactor,
|
|
545
|
-
u_sheenColorFactor,
|
|
546
|
-
u_sheenRoughnessFactor,
|
|
547
|
-
u_anisotropyStrength,
|
|
548
|
-
u_anisotropyRotation,
|
|
549
|
-
u_iridescenceFactor,
|
|
550
|
-
u_iridescenceIor,
|
|
551
|
-
u_iridescenceThicknessMinimum,
|
|
552
|
-
u_iridescenceThicknessMaximum,
|
|
553
|
-
u_dispersion
|
|
554
|
-
);
|
|
555
|
-
float environmentHemi = mix(0.35, 1.0, clamp(normal.y * 0.5 + 0.5, 0.0, 1.0));
|
|
556
|
-
vec3 ambientEnvironment = u_environmentColor * u_environmentIntensity * environmentHemi;
|
|
557
|
-
float proceduralEnvironmentWeight = step(0.0001, u_environmentMapIntensity);
|
|
558
|
-
float skyBlend = clamp(normal.y * 0.5 + 0.5, 0.0, 1.0);
|
|
559
|
-
float horizonBlend = 1.0 - abs(normal.y);
|
|
560
|
-
vec3 proceduralDiffuse = mix(u_environmentGroundColor, u_environmentSkyColor, skyBlend);
|
|
561
|
-
proceduralDiffuse = mix(proceduralDiffuse, u_environmentHorizonColor, clamp(horizonBlend, 0.0, 1.0) * 0.55);
|
|
562
|
-
vec3 environmentDiffuse = mix(ambientEnvironment, proceduralDiffuse * u_environmentMapIntensity, proceduralEnvironmentWeight);
|
|
563
|
-
float sampledEnvironmentWeight = step(0.0001, u_environmentMapTextureEnabled * u_environmentMapTextureIntensity);
|
|
564
|
-
float diffuseEnvironmentLod = max(u_environmentMapTextureMipCount - 1.0, 0.0);
|
|
565
|
-
vec3 sampledDiffuse = a3dPbrDecodeEnvironmentSample(a3dPbrEnvironmentSampleRaw(normal, diffuseEnvironmentLod));
|
|
566
|
-
environmentDiffuse = mix(environmentDiffuse, environmentDiffuse * 0.18 + sampledDiffuse * u_environmentMapTextureIntensity * 0.92, sampledEnvironmentWeight);
|
|
567
|
-
vec3 reflectionDirection = reflect(-viewDirection, normal);
|
|
568
|
-
float roughness = clamp(u_roughness, 0.0, 1.0);
|
|
569
|
-
float reflectionBand = pow(clamp(reflectionDirection.y * 0.5 + 0.5, 0.0, 1.0), mix(18.0, 2.0, roughness));
|
|
570
|
-
float roughEnvironmentFloor = mix(0.04, 0.38, roughness);
|
|
571
|
-
float proceduralSpecularResponse = max(reflectionBand, roughEnvironmentFloor);
|
|
572
|
-
vec3 proceduralSpecular = u_environmentSpecularColor * u_environmentSpecularIntensity * proceduralSpecularResponse * proceduralEnvironmentWeight;
|
|
573
|
-
float environmentLod = roughness * max(u_environmentMapTextureMipCount - 1.0, 0.0);
|
|
574
|
-
vec3 sampledSpecular = a3dPbrBoundHdrSpecularRadiance(a3dPbrDecodeEnvironmentSample(a3dPbrEnvironmentSampleRaw(reflectionDirection, environmentLod)));
|
|
575
|
-
float nDotV = clamp(dot(normal, viewDirection), 0.0, 1.0);
|
|
576
|
-
vec2 brdfLut = texture(u_environmentBrdfLutTexture, vec2(nDotV, roughness)).rg;
|
|
577
|
-
sampledSpecular = a3dPbrClampSampledSpecularEdgeEnergy(sampledSpecular, nDotV, roughness);
|
|
578
|
-
sampledSpecular *= u_environmentMapTextureSpecularIntensity * sampledEnvironmentWeight * mix(1.1, 0.85, roughness);
|
|
579
|
-
vec3 shaded = a3dPbrEnvironmentLightSplitSum(
|
|
580
|
-
normal,
|
|
581
|
-
viewDirection,
|
|
582
|
-
environmentDiffuse,
|
|
583
|
-
proceduralSpecular + sampledSpecular,
|
|
584
|
-
mix(vec2(1.0, 0.0), brdfLut, step(0.0001, u_environmentBrdfLutEnabled)),
|
|
585
|
-
materialBase,
|
|
586
|
-
u_metallic,
|
|
587
|
-
u_roughness,
|
|
588
|
-
u_specularFactor,
|
|
589
|
-
u_specularColorFactor
|
|
590
|
-
) + u_emissiveColor * u_emissiveStrength;
|
|
591
|
-
shaded += a3dPbrExtensionEnvironmentLight(
|
|
592
|
-
normal,
|
|
593
|
-
viewDirection,
|
|
594
|
-
proceduralSpecular + sampledSpecular,
|
|
595
|
-
u_clearcoatFactor,
|
|
596
|
-
u_clearcoatRoughnessFactor,
|
|
597
|
-
u_sheenColorFactor,
|
|
598
|
-
u_sheenRoughnessFactor,
|
|
599
|
-
u_anisotropyStrength,
|
|
600
|
-
u_anisotropyRotation,
|
|
601
|
-
u_iridescenceFactor,
|
|
602
|
-
u_iridescenceIor,
|
|
603
|
-
u_iridescenceThicknessMinimum,
|
|
604
|
-
u_iridescenceThicknessMaximum
|
|
605
|
-
);
|
|
606
|
-
float transmissionAmount = clamp(max(u_transmissionFactor, u_diffuseTransmissionFactor), 0.0, 1.0);
|
|
607
|
-
if (transmissionAmount > 0.0001 && sampledEnvironmentWeight > 0.0001) {
|
|
608
|
-
vec3 refractionDirection = refract(-viewDirection, normal, 1.0 / max(u_ior, 1.0));
|
|
609
|
-
refractionDirection = length(refractionDirection) > 0.0001 ? normalize(refractionDirection) : -reflectionDirection;
|
|
610
|
-
float parallaxStrength = clamp(u_transmissionParallaxStrength, 0.0, 1.0);
|
|
611
|
-
if (parallaxStrength > 0.0001) {
|
|
612
|
-
vec3 parallaxDirection = a3dPbrBoxProjectedDirection(v_worldPosition, refractionDirection, u_transmissionParallaxBoxMin, u_transmissionParallaxBoxMax);
|
|
613
|
-
refractionDirection = normalize(mix(refractionDirection, parallaxDirection, parallaxStrength));
|
|
614
|
-
}
|
|
615
|
-
float bounceCount = clamp(u_transmissionBounceCount, 0.0, 4.0);
|
|
616
|
-
float refractionLod = clamp(roughness + u_volumeThicknessFactor * 0.12 + bounceCount * 0.04 * parallaxStrength, 0.0, 1.0) * max(u_environmentMapTextureMipCount - 1.0, 0.0);
|
|
617
|
-
vec3 refractedEnvironment = a3dPbrBoundHdrTransmissionRadiance(a3dPbrDecodeEnvironmentSample(a3dPbrEnvironmentSampleRaw(refractionDirection, refractionLod)));
|
|
618
|
-
float volumeTravel = clamp((max(u_volumeThicknessFactor, 0.0) * (1.0 + bounceCount * 0.18 * parallaxStrength)) / max(u_volumeAttenuationDistance, 0.0001), 0.0, 16.0);
|
|
619
|
-
vec3 volumeTint = pow(clamp(u_volumeAttenuationColor, vec3(0.0001), vec3(1.0)), vec3(volumeTravel));
|
|
620
|
-
float causticEnergy = u_transmissionCausticStrength * parallaxStrength * transmissionAmount * pow(1.0 - roughness, 2.0) / (1.0 + bounceCount * 0.35);
|
|
621
|
-
float roughVolumeIorLift = mix(1.0, 1.45, clamp((u_ior - 1.0) / 1.5, 0.0, 1.0) * smoothstep(0.35, 0.95, roughness + u_volumeThicknessFactor * 0.2));
|
|
622
|
-
float fallbackEnvironmentTransmissionEnergy = mix(1.0, clamp(u_transmissionFallbackEnergy, 0.0, 1.0), transmissionAmount);
|
|
623
|
-
vec3 refractionRadiance = (refractedEnvironment + vec3(causticEnergy)) * volumeTint * u_environmentMapTextureIntensity * transmissionAmount * fallbackEnvironmentTransmissionEnergy * mix(0.9, 0.55, roughness) * roughVolumeIorLift;
|
|
624
|
-
shaded = mix(shaded, shaded * 0.72 + refractionRadiance, transmissionAmount * mix(0.08, 0.58, fallbackEnvironmentTransmissionEnergy));
|
|
625
|
-
}
|
|
626
|
-
int count = min(int(u_lightCount), 16);
|
|
627
|
-
for (int i = 0; i < count; ++i) {
|
|
628
|
-
int baseIndex = i * 4;
|
|
629
|
-
vec4 colorIntensity = u_lightData[baseIndex];
|
|
630
|
-
vec4 positionRange = u_lightData[baseIndex + 1];
|
|
631
|
-
vec4 directionKind = u_lightData[baseIndex + 2];
|
|
632
|
-
vec4 spotShadowLayer = u_lightData[baseIndex + 3];
|
|
633
|
-
float kind = directionKind.w;
|
|
634
|
-
vec3 lightDirection = -directionKind.xyz;
|
|
635
|
-
float attenuation = 1.0;
|
|
636
|
-
if (kind > 0.5) {
|
|
637
|
-
vec3 toLight = positionRange.xyz - v_worldPosition;
|
|
638
|
-
float distanceToLight = length(toLight);
|
|
639
|
-
lightDirection = distanceToLight > 0.0001 ? toLight / distanceToLight : -directionKind.xyz;
|
|
640
|
-
float range = max(positionRange.w, 0.0001);
|
|
641
|
-
float rangeFalloff = clamp(1.0 - pow(distanceToLight / range, 4.0), 0.0, 1.0);
|
|
642
|
-
rangeFalloff *= rangeFalloff;
|
|
643
|
-
attenuation = rangeFalloff / max(distanceToLight * distanceToLight, 1.0);
|
|
644
|
-
}
|
|
645
|
-
if (kind > 1.5) {
|
|
646
|
-
vec3 lightToFragment = normalize(v_worldPosition - positionRange.xyz);
|
|
647
|
-
float cone = dot(normalize(directionKind.xyz), lightToFragment);
|
|
648
|
-
float outer = cos(spotShadowLayer.x);
|
|
649
|
-
float inner = cos(spotShadowLayer.x * max(1.0 - spotShadowLayer.y, 0.001));
|
|
650
|
-
attenuation *= smoothstep(outer, inner, cone);
|
|
651
|
-
}
|
|
652
|
-
float directLightIntensity = colorIntensity.a * attenuation * mix(1.0, kind > 0.5 && kind < 1.5 ? a3dPointShadowFactor(v_worldPosition, normal, lightDirection) : a3dForwardShadowFactor(v_worldPosition, normal, lightDirection), step(0.5, spotShadowLayer.z));
|
|
653
|
-
shaded += a3dPbrDirectLight(
|
|
654
|
-
normal,
|
|
655
|
-
viewDirection,
|
|
656
|
-
lightDirection,
|
|
657
|
-
colorIntensity.rgb,
|
|
658
|
-
directLightIntensity,
|
|
659
|
-
materialBase,
|
|
660
|
-
u_metallic,
|
|
661
|
-
u_roughness,
|
|
662
|
-
u_specularFactor,
|
|
663
|
-
u_specularColorFactor
|
|
664
|
-
);
|
|
665
|
-
shaded += a3dPbrExtensionDirectLight(
|
|
666
|
-
normal,
|
|
667
|
-
viewDirection,
|
|
668
|
-
lightDirection,
|
|
669
|
-
colorIntensity.rgb,
|
|
670
|
-
directLightIntensity,
|
|
671
|
-
u_clearcoatFactor,
|
|
672
|
-
u_clearcoatRoughnessFactor,
|
|
673
|
-
u_sheenColorFactor,
|
|
674
|
-
u_sheenRoughnessFactor,
|
|
675
|
-
u_anisotropyStrength,
|
|
676
|
-
u_anisotropyRotation,
|
|
677
|
-
u_iridescenceFactor,
|
|
678
|
-
u_iridescenceIor,
|
|
679
|
-
u_iridescenceThicknessMinimum,
|
|
680
|
-
u_iridescenceThicknessMaximum
|
|
681
|
-
);
|
|
682
|
-
}
|
|
683
|
-
float alpha = u_baseColor.a * v_vertexColor.a;
|
|
684
|
-
if (alpha < u_alphaCutoff) discard;
|
|
685
|
-
vec3 fogged = a3dApplyEnvironmentFog(max(shaded, vec3(0.0)), v_worldPosition);
|
|
686
|
-
outColor = vec4(a3dPbrEncodeOutput(fogged), alpha);
|
|
687
|
-
}
|