mdx-m3-viewer
Version:
A browser WebGL model viewer. Mainly focused on models of the games Warcraft 3 and Starcraft 2.
3 lines (2 loc) • 1.54 kB
TypeScript
declare const shader = "\nuniform mat4 u_VP;\nuniform sampler2D u_heightMap;\nuniform sampler2D u_waterHeightMap;\nuniform vec2 u_size;\nuniform vec2 u_offset;\nuniform float u_offsetHeight;\nuniform vec4 u_minDeepColor;\nuniform vec4 u_maxDeepColor;\nuniform vec4 u_minShallowColor;\nuniform vec4 u_maxShallowColor;\n\nattribute vec2 a_position;\nattribute float a_InstanceID;\nattribute float a_isWater;\n\nvarying vec2 v_uv;\nvarying vec4 v_color;\n\nconst float minDepth = 10.0 / 128.0;\nconst float deepLevel = 64.0 / 128.0;\nconst float maxDepth = 72.0 / 128.0;\n\nvoid main() {\n if (a_isWater > 0.5) {\n v_uv = a_position;\n\n vec2 corner = vec2(mod(a_InstanceID, u_size.x), floor(a_InstanceID / u_size.x));\n vec2 base = corner + a_position;\n float height = texture2D(u_heightMap, base / u_size).a;\n float waterHeight = texture2D(u_waterHeightMap, base / u_size).a + u_offsetHeight;\n float value = clamp(waterHeight - height, 0.0, 1.0);\n\n if (value <= deepLevel) {\n value = max(0.0, value - minDepth) / (deepLevel - minDepth);\n v_color = mix(u_minShallowColor, u_maxShallowColor, value) / 255.0;\n } else {\n value = clamp(value - deepLevel, 0.0, maxDepth - deepLevel) / (maxDepth - deepLevel);\n v_color = mix(u_minDeepColor, u_maxDeepColor, value) / 255.0;\n }\n\n gl_Position = u_VP * vec4(base * 128.0 + u_offset, waterHeight * 128.0, 1.0);\n } else {\n v_uv = vec2(0.0);\n v_color = vec4(0.0);\n\n gl_Position = vec4(0.0);\n }\n}\n";
export default shader;