UNPKG

@threlte/extras

Version:

Utilities, abstractions and plugins for your Threlte apps

29 lines (25 loc) 798 B
import { ShaderChunk } from 'three'; export const fragmentShader = ` uniform vec3 glowColor; uniform float falloffAmount; uniform float glowSharpness; uniform float glowInternalRadius; varying vec3 vPosition; varying vec3 vNormal; void main() { // Normal vec3 normal = normalize(vNormal); if(!gl_FrontFacing) normal *= - 1.0; vec3 viewDirection = normalize(cameraPosition - vPosition); float fresnel = dot(viewDirection, normal); fresnel = pow(fresnel, glowInternalRadius + 0.1); float falloff = smoothstep(0., falloffAmount, fresnel); float fakeGlow = fresnel; fakeGlow += fresnel * glowSharpness; fakeGlow *= falloff; gl_FragColor = vec4(clamp(glowColor * fresnel, 0., 1.0), clamp(fakeGlow, 0., 1.0)); ${ShaderChunk.tonemapping_fragment} ${ShaderChunk.colorspace_fragment} }`;