Skip to content
Snippets Groups Projects
mesh.vert.ts 1.38 KiB
Newer Older
Alexander Rose's avatar
Alexander Rose committed
/**
 * Copyright (c) 2018-2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
Alexander Rose's avatar
Alexander Rose committed
 *
 * @author Alexander Rose <alexander.rose@weirdbyte.de>
 */

Alexander Rose's avatar
Alexander Rose committed
precision highp float;
Alexander Rose's avatar
Alexander Rose committed
precision highp int;
#include common
#include read_from_texture
#include common_vert_params
#include color_vert_params
#ifdef dGeoTexture
    uniform vec2 uGeoTexDim;
Alexander Rose's avatar
Alexander Rose committed
    uniform sampler2D tPositionGroup;
#else
    attribute vec3 aPosition;
#endif
attribute mat4 aTransform;
attribute float aInstance;
attribute float aGroup;
Alexander Rose's avatar
Alexander Rose committed

    #ifdef dGeoTexture
        uniform sampler2D tNormal;
    #else
        attribute vec3 aNormal;
    #endif
    varying vec3 vNormal;
#endif
Alexander Rose's avatar
Alexander Rose committed

Alexander Rose's avatar
Alexander Rose committed
void main(){
    #include assign_group
    #include assign_color_varying
    #include assign_marker_varying
    #include assign_position
        #ifdef dGeoTexture
            vec3 normal = readFromTexture(tNormal, aGroup, uGeoTexDim).xyz;
        #else
            vec3 normal = aNormal;
        #endif
        mat3 normalMatrix = transpose3(inverse3(mat3(modelView)));
        vec3 transformedNormal = normalize(normalMatrix * normalize(normal));
        #if defined(dFlipSided) && !defined(dDoubleSided) // TODO checking dDoubleSided should not be required, ASR
            transformedNormal = -transformedNormal;
        #endif
        vNormal = transformedNormal;