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.75 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var accumulatorShader = "#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 uSceneDepth;\nuniform sampler2D uSceneNormal;\nuniform sampler2D uRandRotDepth;\nuniform sampler2D uAccumulator;\nuniform mat4 uRot;\nuniform mat4 uInvRot;\nuniform vec2 uSceneBottomLeft;\nuniform vec2 uSceneTopRight;\nuniform vec2 uRotBottomLeft;\nuniform vec2 uRotTopRight;\nuniform float uDepth;\nuniform float uRes;\nuniform int uSampleCount;\n\nvoid main() {\n\n float dScene = texture2D(uSceneDepth, gl_FragCoord.xy/uRes).r;\n\n vec3 r = vec3(uSceneBottomLeft + (gl_FragCoord.xy/uRes) * (uSceneTopRight - uSceneBottomLeft), 0.0);\n\n r.z = -(dScene - 0.5) * uDepth;\n r = vec3(uRot * vec4(r, 1));\n float depth = -r.z/uDepth + 0.5;\n\n vec2 p = (r.xy - uRotBottomLeft)/(uRotTopRight - uRotBottomLeft);\n\n float dRandRot = texture2D(uRandRotDepth, p).r;\n\n float ao = step(dRandRot, depth * 0.99);\n\n vec3 normal = texture2D(uSceneNormal, gl_FragCoord.xy/uRes).rgb * 2.0 - 1.0;\n vec3 dir = vec3(uInvRot * vec4(0, 0, 1, 0));\n float mag = dot(dir, normal);\n float sampled = step(0.0, mag);\n\n ao *= sampled;\n\n vec4 acc = texture2D(uAccumulator, gl_FragCoord.xy/uRes);\n\n if (uSampleCount < 256) {\n acc.r += ao/255.0;\n } else if (uSampleCount < 512) {\n acc.g += ao/255.0;\n } else if (uSampleCount < 768) {\n acc.b += ao/255.0;\n } else {\n acc.a += ao/255.0;\n }\n\n gl_FragColor = acc;\n\n}";
exports.default = accumulatorShader;