UNPKG

@webviz/subsurface-viewer

Version:

3D visualization component for subsurface reservoir data

3 lines (2 loc) 4.52 kB
declare const _default: "#version 300 es\n#define SHADER_NAME colormap-fragment-shader\n\nin vec2 vTexCoord;\n\nout vec4 fragColor;\n\nuniform sampler2D bitmapTexture; // Property map\nuniform sampler2D colormapTexture;\nuniform sampler2D heightMapTexture; // Height map texture, if defined.\n\n// Compute the normal value for every pixel, based on the current value and two values aroud it.\nvec3 normal(float val) {\n vec2 dr = 1.0 / map.bitmapResolution;\n\n if (map.isHeightMapTextureDefined) {\n float valueRangeSize = map.heightValueRangeMax - map.heightValueRangeMin;\n float p0 = valueRangeSize * val;\n float px = valueRangeSize * decode_rgb2float(texture(heightMapTexture, vTexCoord + vec2(1.0, 0.0) / map.bitmapResolution).rgb);\n float py = valueRangeSize * decode_rgb2float(texture(heightMapTexture, vTexCoord + vec2(0.0, 1.0) / map.bitmapResolution).rgb);\n vec3 dx = vec3(1.0, 0.0, px - p0);\n vec3 dy = vec3(0.0, 1.0, py - p0);\n return normalize(cross(dx, dy));\n }\n else {\n float valueRangeSize = map.valueRangeMax - map.valueRangeMin;\n float p0 = valueRangeSize * val;\n float px = valueRangeSize * decode_rgb2float(texture(bitmapTexture, vTexCoord + vec2(1.0, 0.0) / map.bitmapResolution).rgb);\n float py = valueRangeSize * decode_rgb2float(texture(bitmapTexture, vTexCoord + vec2(0.0, 1.0) / map.bitmapResolution).rgb);\n vec3 dx = vec3(1.0, 0.0, px - p0);\n vec3 dy = vec3(0.0, 1.0, py - p0);\n return normalize(cross(dx, dy));\n }\n}\n\n// Compute how much a pixel is in the shadow based on its normal and where the light comes from.\nfloat shadow(vec3 normal) {\n vec3 lightDirection = vec3(1.0, 1.0, 1.0);\n float ambientLightIntensity = 0.5;\n float diffuseLightIntensity = 0.5;\n float diffuse = diffuseLightIntensity * dot(normal, normalize(lightDirection));\n return clamp(ambientLightIntensity + diffuse, 0.0, 1.0);\n}\n\nvoid main(void) {\n vec4 bitmapColor = texture(bitmapTexture, vTexCoord);\n\n // If it's a picking pass, we just return the raw property map value.\n if (picking.isActive > 0.5) {\n fragColor = bitmapColor;\n return;\n }\n\n // Decode the RGB value into a float. See decoder.fs.glsl for more details.\n float val = decode_rgb2float(bitmapColor.rgb); // The resulting val will be in [0, 1] interval.\n float property = val * (map.valueRangeMax - map.valueRangeMin) + map.valueRangeMin;\n\n // Compute the color from the colormap.\n vec4 color = vec4(1.0, 1.0, 1.0, 1.0);\n float x = (property - map.colormapRangeMin) / (map.colormapRangeMax - map.colormapRangeMin);\n if (x < 0.0 || x > 1.0) {\n // Out of range. Use clampcolor.\n if (map.isClampColor) {\n color = vec4(map.colormapClampColor.rgb, 1.0);\n }\n else if (map.isColormapClampColorTransparent) {\n discard;\n return;\n }\n else {\n // Use min/max color to clamp.\n x = max(0.0, x);\n x = min(1.0, x);\n\n color = texture(colormapTexture, vec2(x, 0.5));\n }\n }\n else {\n color = texture(colormapTexture, vec2(x, 0.5));\n }\n fragColor = vec4(color.rgb, color.a * bitmapColor.a * layer.opacity);\n\n // Hillshading.\n if (map.hillshading) {\n vec4 texture_val = map.isHeightMapTextureDefined ? texture(heightMapTexture, vTexCoord)\n : texture(bitmapTexture, vTexCoord);\n float val = decode_rgb2float(texture_val.rgb);\n\n // Compute the shadow value, how dark a pixel will be, 1 is in complete shadow, 0 is in complete light.\n float shadow = shadow(normal(val));\n fragColor = vec4(fragColor.rgb * shadow, fragColor.a);\n }\n\n // Contour lines.\n if (map.contours) {\n vec4 texture_val = map.isHeightMapTextureDefined ? texture(heightMapTexture, vTexCoord)\n : texture(bitmapTexture, vTexCoord);\n float val = decode_rgb2float(texture_val.rgb);\n float property = val * (map.heightValueRangeMax - map.heightValueRangeMin) + map.heightValueRangeMin;\n\n float x = (property - map.contourReferencePoint) / map.contourInterval; \n float f = fract(x);\n float df = fwidth(x);\n float c = smoothstep(df * 1.0, df * 2.0, f); // smootstep from/to no of pixels distance from contour line. // keep: \n fragColor = fragColor * vec4(c, c, c, layer.opacity);\n }\n\n geometry.uv = vTexCoord;\n DECKGL_FILTER_COLOR(fragColor, geometry);\n}\n"; export default _default;