UNPKG

speck-renderer

Version:

Browser-based WebGL molecule renderer with the goal of producing figures that are as attractive as they are practical.

8 lines (6 loc) 1.51 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var aoShader = "#version 100\nprecision highp float;\n\nattribute vec3 aPosition;\n\nvoid main() {\n gl_Position = vec4(aPosition, 1);\n}\n\n\n// __split__\n\n\n#version 100\nprecision highp float;\n\nuniform sampler2D uSceneColor;\nuniform sampler2D uSceneDepth;\nuniform sampler2D uAccumulatorOut;\nuniform float uRes;\nuniform float uAO;\nuniform float uBrightness;\nuniform float uOutlineStrength;\n\nvoid main() {\n vec2 p = gl_FragCoord.xy/uRes;\n vec4 sceneColor = texture2D(uSceneColor, p);\n if (uOutlineStrength > 0.0) {\n float depth = texture2D(uSceneDepth, p).r;\n float r = 1.0/511.0;\n float d0 = abs(texture2D(uSceneDepth, p + vec2(-r, 0)).r - depth);\n float d1 = abs(texture2D(uSceneDepth, p + vec2( r, 0)).r - depth);\n float d2 = abs(texture2D(uSceneDepth, p + vec2( 0, -r)).r - depth);\n float d3 = abs(texture2D(uSceneDepth, p + vec2( 0, r)).r - depth);\n float d = max(d0, d1);\n d = max(d, d2);\n d = max(d, d3);\n sceneColor.rgb *= pow(1.0 - d, uOutlineStrength * 32.0);\n sceneColor.a = max(step(0.003, d), sceneColor.a);\n }\n vec4 dAccum = texture2D(uAccumulatorOut, p);\n float shade = max(0.0, 1.0 - (dAccum.r + dAccum.g + dAccum.b + dAccum.a) * 0.25 * uAO);\n shade = pow(shade, 2.0);\n gl_FragColor = vec4(uBrightness * sceneColor.rgb * shade, sceneColor.a);\n}"; exports.default = aoShader;