Skip to main content

Variable: emissiveMaterial

const emissiveMaterial: object

Defined in: modules/engine/src/materials/emissive-material.ts:100

Portable emissive surface shading with a controllable camera-facing rim.

Type Declaration​

defaultUniforms​

readonly defaultUniforms: object

defaultUniforms.intensity​

readonly intensity: 1 = 1

defaultUniforms.rimStrength​

readonly rimStrength: 0.35 = 0.35

dependencies​

readonly dependencies: [{ fs: "vec3 opticalLighting_faceNormal(vec3 normal, vec3 viewDirection) {\n return dot(normal, viewDirection) >= 0.0 ? normal : -normal;\n}\n\nfloat opticalLighting_getFresnel(float viewAlignment, float baseReflectance, float exponent) {\n return baseReflectance + (1.0 - baseReflectance) *\n pow(1.0 - clamp(viewAlignment, 0.0, 1.0), exponent);\n}\n\nfloat opticalLighting_getFilteredRoughness(vec3 normal, float roughness) {\n vec3 normalDerivativeX = dFdx(normal);\n vec3 normalDerivativeY = dFdy(normal);\n float normalVariance = dot(normalDerivativeX, normalDerivativeX) +\n dot(normalDerivativeY, normalDerivativeY);\n float kernelRoughnessSquared = min(2.0 * normalVariance, 1.0);\n return clamp(sqrt(roughness * roughness + kernelRoughnessSquared), 0.04, 1.0);\n}\n\nfloat opticalLighting_getMicrofacetSpecular(\n vec3 normal,\n vec3 viewDirection,\n vec3 lightDirection,\n float roughness\n) {\n vec3 halfDirection = normalize(viewDirection + lightDirection);\n float normalAlignment = max(dot(normal, viewDirection), 0.001);\n float lightAlignment = max(dot(normal, lightDirection), 0.0);\n float halfAlignment = max(dot(normal, halfDirection), 0.0);\n float alpha = max(roughness * roughness, 0.045);\n float alphaSquared = alpha * alpha;\n float distributionDenominator = halfAlignment * halfAlignment * (alphaSquared - 1.0) + 1.0;\n float distribution = alphaSquared /\n max(3.14159265 * distributionDenominator * distributionDenominator, 0.001);\n float visibilityFactor = pow(roughness + 1.0, 2.0) * 0.125;\n float viewVisibility = normalAlignment /\n (normalAlignment * (1.0 - visibilityFactor) + visibilityFactor);\n float lightVisibility = lightAlignment /\n (lightAlignment * (1.0 - visibilityFactor) + visibilityFactor);\n return distribution * viewVisibility * lightVisibility * lightAlignment /\n max(4.0 * normalAlignment * lightAlignment, 0.001);\n}\n\nvec3 opticalLighting_getKeyLight() {\n return normalize(vec3(-0.45, 0.82, 0.34));\n}\n\nvec3 opticalLighting_getFillLight() {\n return normalize(vec3(0.62, 0.35, -0.7));\n}\n\nvec3 opticalLighting_sampleEnvironment(\n vec3 reflectionDirection,\n vec3 shadowColor,\n vec3 highlightColor,\n float horizonStrength\n) {\n float horizon = pow(1.0 - abs(reflectionDirection.y), 4.0);\n return mix(\n shadowColor,\n highlightColor,\n clamp(reflectionDirection.y * 0.5 + 0.5 + horizon * horizonStrength, 0.0, 1.0)\n );\n}\n"; name: "opticalLighting"; source: "fn opticalLighting_faceNormal(normal: vec3<f32>, viewDirection: vec3<f32>) -> vec3<f32> {\n return select(-normal, normal, dot(normal, viewDirection) >= 0.0);\n}\n\nfn opticalLighting_getFresnel(\n viewAlignment: f32,\n baseReflectance: f32,\n exponent: f32\n) -> f32 {\n return baseReflectance + (1.0 - baseReflectance) *\n pow(1.0 - clamp(viewAlignment, 0.0, 1.0), exponent);\n}\n\nfn opticalLighting_getFilteredRoughness(normal: vec3<f32>, roughness: f32) -> f32 {\n let normalDerivativeX = dpdx(normal);\n let normalDerivativeY = dpdy(normal);\n let normalVariance = dot(normalDerivativeX, normalDerivativeX) +\n dot(normalDerivativeY, normalDerivativeY);\n let kernelRoughnessSquared = min(2.0 * normalVariance, 1.0);\n return clamp(sqrt(roughness * roughness + kernelRoughnessSquared), 0.04, 1.0);\n}\n\nfn opticalLighting_getMicrofacetSpecular(\n normal: vec3<f32>,\n viewDirection: vec3<f32>,\n lightDirection: vec3<f32>,\n roughness: f32\n) -> f32 {\n let halfDirection = normalize(viewDirection + lightDirection);\n let normalAlignment = max(dot(normal, viewDirection), 0.001);\n let lightAlignment = max(dot(normal, lightDirection), 0.0);\n let halfAlignment = max(dot(normal, halfDirection), 0.0);\n let alpha = max(roughness * roughness, 0.045);\n let alphaSquared = alpha * alpha;\n let distributionDenominator = halfAlignment * halfAlignment * (alphaSquared - 1.0) + 1.0;\n let distribution = alphaSquared /\n max(3.14159265 * distributionDenominator * distributionDenominator, 0.001);\n let visibilityFactor = pow(roughness + 1.0, 2.0) * 0.125;\n let viewVisibility = normalAlignment /\n (normalAlignment * (1.0 - visibilityFactor) + visibilityFactor);\n let lightVisibility = lightAlignment /\n (lightAlignment * (1.0 - visibilityFactor) + visibilityFactor);\n return distribution * viewVisibility * lightVisibility * lightAlignment /\n max(4.0 * normalAlignment * lightAlignment, 0.001);\n}\n\nfn opticalLighting_getKeyLight() -> vec3<f32> {\n return normalize(vec3<f32>(-0.45, 0.82, 0.34));\n}\n\nfn opticalLighting_getFillLight() -> vec3<f32> {\n return normalize(vec3<f32>(0.62, 0.35, -0.7));\n}\n\nfn opticalLighting_sampleEnvironment(\n reflectionDirection: vec3<f32>,\n shadowColor: vec3<f32>,\n highlightColor: vec3<f32>,\n horizonStrength: f32\n) -> vec3<f32> {\n let horizon = pow(1.0 - abs(reflectionDirection.y), 4.0);\n return mix(\n shadowColor,\n highlightColor,\n clamp(reflectionDirection.y * 0.5 + 0.5 + horizon * horizonStrength, 0.0, 1.0)\n );\n}\n"; }]

fs​

readonly fs: "layout(std140) uniform emissiveMaterialUniforms {\n float intensity;\n float rimStrength;\n} emissiveMaterial;\n\nvec4 emissiveMaterial_getColor(\n vec3 normal,\n vec3 worldPosition,\n vec4 baseColor,\n vec3 cameraPosition\n) {\n vec3 viewDirection = normalize(cameraPosition - worldPosition);\n vec3 normalFacingCamera = opticalLighting_faceNormal(normalize(normal), viewDirection);\n float viewAlignment = clamp(dot(normalFacingCamera, viewDirection), 0.0, 1.0);\n float rim = pow(1.0 - viewAlignment, 2.0);\n float emission = emissiveMaterial.intensity * (1.0 + emissiveMaterial.rimStrength * rim);\n return vec4(baseColor.rgb * emission, baseColor.a);\n}\n\nvec4 emissiveMaterial_getTrailColor(\n vec3 normal,\n vec3 worldPosition,\n vec4 baseColor,\n vec3 cameraPosition,\n float trailProgress,\n float trailStrength\n) {\n vec4 emission = emissiveMaterial_getColor(normal, worldPosition, baseColor, cameraPosition);\n float fade = pow(smoothstep(0.0, 1.0, trailProgress), 1.5);\n return vec4(emission.rgb * fade * trailStrength, emission.a * fade);\n}\n" = EMISSIVE_MATERIAL_GLSL

getUniforms​

readonly getUniforms: (props, previousUniforms?) => EmissiveMaterialUniforms = getEmissiveMaterialUniforms

Parameters​

props?​

Partial<EmissiveMaterialProps> = {}

previousUniforms?​

Required<EmissiveMaterialProps>

Returns​

EmissiveMaterialUniforms

name​

readonly name: "emissiveMaterial" = 'emissiveMaterial'

source​

readonly source: "struct emissiveMaterialUniforms {\n intensity: f32,\n rimStrength: f32,\n};\n\n@group(0) @binding(auto) var<uniform> emissiveMaterial: emissiveMaterialUniforms;\n\nfn emissiveMaterial_getColor(\n normal: vec3<f32>,\n worldPosition: vec3<f32>,\n baseColor: vec4<f32>,\n cameraPosition: vec3<f32>\n) -> vec4<f32> {\n let viewDirection = normalize(cameraPosition - worldPosition);\n let normalFacingCamera = opticalLighting_faceNormal(normalize(normal), viewDirection);\n let viewAlignment = clamp(dot(normalFacingCamera, viewDirection), 0.0, 1.0);\n let rim = pow(1.0 - viewAlignment, 2.0);\n let emission = emissiveMaterial.intensity * (1.0 + emissiveMaterial.rimStrength * rim);\n return vec4<f32>(baseColor.rgb * emission, baseColor.a);\n}\n\nfn emissiveMaterial_getTrailColor(\n normal: vec3<f32>,\n worldPosition: vec3<f32>,\n baseColor: vec4<f32>,\n cameraPosition: vec3<f32>,\n trailProgress: f32,\n trailStrength: f32\n) -> vec4<f32> {\n let emission = emissiveMaterial_getColor(normal, worldPosition, baseColor, cameraPosition);\n let fade = pow(smoothstep(0.0, 1.0, trailProgress), 1.5);\n return vec4<f32>(emission.rgb * fade * trailStrength, emission.a * fade);\n}\n" = EMISSIVE_MATERIAL_WGSL

uniformTypes​

readonly uniformTypes: object

uniformTypes.intensity​

readonly intensity: "f32" = 'f32'

uniformTypes.rimStrength​

readonly rimStrength: "f32" = 'f32'