Skip to content
Snippets Groups Projects
Select Git revision
  • df9efd05e6dc8abd67def6c39ed2ae180521af9f
  • master default protected
  • rednatco-v2
  • base-pairs-ladder
  • rednatco
  • test
  • ntc-tube-uniform-color
  • ntc-tube-missing-atoms
  • restore-vertex-array-per-program
  • watlas2
  • dnatco_new
  • cleanup-old-nodejs
  • webmmb
  • fix_auth_seq_id
  • update_deps
  • ext_dev
  • ntc_balls
  • nci-2
  • plugin
  • bugfix-0.4.5
  • nci
  • v0.5.0-dev.1
  • v0.4.5
  • v0.4.4
  • v0.4.3
  • v0.4.2
  • v0.4.1
  • v0.4.0
  • v0.3.12
  • v0.3.11
  • v0.3.10
  • v0.3.9
  • v0.3.8
  • v0.3.7
  • v0.3.6
  • v0.3.5
  • v0.3.4
  • v0.3.3
  • v0.3.2
  • v0.3.1
  • v0.3.0
41 results

image.frag.ts

Blame
  • image.frag.ts 3.89 KiB
    /**
     * Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
     *
     * @author Alexander Rose <alexander.rose@weirdbyte.de>
     */
    export default `
    precision highp float;
    precision highp int;
    
    #include common
    #include common_frag_params
    
    uniform vec2 uImageTexDim;
    uniform sampler2D tImageTex;
    uniform sampler2D tGroupTex;
    
    varying vec2 vUv;
    varying float vInstance;
    
    #if defined(dInterpolation_catmulrom) || defined(dInterpolation_mitchell) || defined(dInterpolation_bspline)
        #define dInterpolation_cubic
    #endif
    
    #if defined(dInterpolation_cubic)
        #if defined(dInterpolation_catmulrom) || defined(dInterpolation_mitchell)
            #if defined(dInterpolation_catmulrom)
                const float B = 0.0;
                const float C = 0.5;
            #elif defined(dInterpolation_mitchell)
                const float B = 0.333;
                const float C = 0.333;
            #endif
    
            float cubicFilter( float x ){
                float f = x;
                if( f < 0.0 ){
                    f = -f;
                }
                if( f < 1.0 ){
                    return ( ( 12.0 - 9.0 * B - 6.0 * C ) * ( f * f * f ) +
                        ( -18.0 + 12.0 * B + 6.0 *C ) * ( f * f ) +
                        ( 6.0 - 2.0 * B ) ) / 6.0;
                }else if( f >= 1.0 && f < 2.0 ){
                    return ( ( -B - 6.0 * C ) * ( f * f * f )
                        + ( 6.0 * B + 30.0 * C ) * ( f *f ) +
                        ( - ( 12.0 * B ) - 48.0 * C  ) * f +
                        8.0 * B + 24.0 * C ) / 6.0;
                }else{
                    return 0.0;
                }
            }
        #elif defined(dInterpolation_bspline)
            float cubicFilter(float x) {
                float f = x;
                if (f < 0.0) {
                    f = -f;
                }
                if (f >= 0.0 && f <= 1.0){
                    return (2.0 / 3.0) + (0.5) * (f * f * f) - (f * f);
                } else if (f > 1.0 && f <= 2.0) {
                    return 1.0 / 6.0 * pow((2.0 - f), 3.0);
                }
                return 1.0;
            }
        #endif
    
        vec4 biCubic(sampler2D tex, vec2 texCoord) {
            vec2 texelSize = 1.0 / uImageTexDim;
            texCoord -= texelSize / 2.0;
            vec4 nSum = vec4(0.0);
            float nDenom = 0.0;
            vec2 cell = fract(texCoord * uImageTexDim);
            for (float m = -1.0; m <= 2.0; ++m) {
                for (float n = -1.0; n <= 2.0; ++n) {
                    vec4 vecData = texture2D(tex, texCoord + texelSize * vec2(m, n));
                    float c = cubicFilter(m - cell.x) * cubicFilter(-n + cell.y);
                    nSum += vecData * c;
                    nDenom += c;
                }
            }
            return nSum / nDenom;
        }
    #endif
    
    void main() {
        #if defined(dInterpolation_cubic)
            vec4 imageData = biCubic(tImageTex, vUv);
        #else
            vec4 imageData = texture2D(tImageTex, vUv);
        #endif
    
        #if defined(dRenderVariant_pick)
            if (imageData.a < 0.3)
                discard;
    
            if (uPickable == 1) {
                #if defined(dRenderVariant_pickObject)
                    gl_FragColor = vec4(encodeFloatRGB(float(uObjectId)), 1.0);
                #elif defined(dRenderVariant_pickInstance)
                    gl_FragColor = vec4(encodeFloatRGB(vInstance), 1.0);
                #elif defined(dRenderVariant_pickGroup)
                    float group = texture2D(tGroupTex, vUv).a;
                    gl_FragColor = vec4(encodeFloatRGB(group), 1.0);
                #endif
            } else {
                gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0); // set to empty picking id
            }
        #elif defined(dRenderVariant_depth)
            if (imageData.a < 0.01)
                discard;
    
            #ifdef enabledFragDepth
                gl_FragColor = packDepthToRGBA(gl_FragDepthEXT);
            #else
                gl_FragColor = packDepthToRGBA(gl_FragCoord.z);
            #endif
        #elif defined(dRenderVariant_color)
            if (imageData.a < 0.01)
                discard;
    
            gl_FragColor = imageData;
            gl_FragColor.a *= uAlpha;
    
            #include apply_fog
        #endif
    }
    `;