Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Three.js 仅用于方向灯的自定义材质_Three.js - Fatal编程技术网

Three.js 仅用于方向灯的自定义材质

Three.js 仅用于方向灯的自定义材质,three.js,Three.js,基本组件取自ShaderLib['lambert'], 但是在片段着色器中,我没有找到Lambert的照明计算 此外,在当前着色器中,获取一个错误: three.js:22433 WebGL:无效的_值:uniform3fv:无数组 我在顶点着色器中遗漏了什么?除此之外,还需要指定什么?添加灯光:为参数材质设置true,如下所示: 新三点材质{ fragmentShader:fragmentShader, vertexShader:vertexShader, 制服:制服, 三面,双面, 灯光:是

基本组件取自ShaderLib['lambert'], 但是在片段着色器中,我没有找到Lambert的照明计算 此外,在当前着色器中,获取一个错误: three.js:22433 WebGL:无效的_值:uniform3fv:无数组

我在顶点着色器中遗漏了什么?除此之外,还需要指定什么?

添加灯光:为参数材质设置true,如下所示:

新三点材质{ fragmentShader:fragmentShader, vertexShader:vertexShader, 制服:制服, 三面,双面, 灯光:是的//
 this.uniforms= {
                    "directionalLightDirection" : { type: "fv", value: [] },
                    "directionalLightColor" : { type: "fv", value: [] },
                    "opacity":{type:'f', value:1},
                    "map" : { type: "t", value: params.map }
            };

this.vertexShader=[
            varying vec2 vUv;',
            "varying vec3 vLightFront;",

            THREE.ShaderChunk[ 'logdepthbuf_pars_vertex'],


            "#if MAX_DIR_LIGHTS > 0",

            "   uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];",
            "   uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];",

            "#endif",

            'void main()',
            '{',

                'vUv = uv;',
                'vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );',
                'gl_Position = projectionMatrix * mvPosition;',
                THREE.ShaderChunk[ 'logdepthbuf_vertex'],



            "#ifdef USE_SKINNING",
            "   vec3 objectNormal = skinnedNormal.xyz;", 
            "#elif defined( USE_MORPHNORMALS )",
            "   vec3 objectNormal = morphedNormal;",
            "#else",
            "   vec3 objectNormal = normal;", 
            "#endif",

            "#ifdef FLIP_SIDED", 
            "   objectNormal = -objectNormal;", 
            "#endif",

            "vec3 transformedNormal = normalMatrix * objectNormal;",


    "#if MAX_DIR_LIGHTS > 0",

        "transformedNormal = normalize( transformedNormal );",

        "for( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {",

        "   vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );",
        "   vec3 dirVector = normalize( lDirection.xyz );",

        "   float dotProduct = dot( transformedNormal, dirVector );",
        "   vec3 directionalLightWeighting = vec3( max( dotProduct, 0.0 ) );",

        "   #ifdef DOUBLE_SIDED",

        "       vec3 directionalLightWeightingBack = vec3( max( -dotProduct, 0.0 ) );",

        "       #ifdef WRAP_AROUND",

        "           vec3 directionalLightWeightingHalfBack = vec3( max( -0.5 * dotProduct + 0.5, 0.0 ) );",

        "       #endif",

        "   #endif",

        "   #ifdef WRAP_AROUND",

        "       vec3 directionalLightWeightingHalf = vec3( max( 0.5 * dotProduct + 0.5, 0.0 ) );",
        "       directionalLightWeighting = mix( directionalLightWeighting, directionalLightWeightingHalf, wrapRGB );",

        "       #ifdef DOUBLE_SIDED",

        "           directionalLightWeightingBack = mix( directionalLightWeightingBack, directionalLightWeightingHalfBack, wrapRGB );",

        "       #endif",

        "   #endif",

        "   vLightFront += directionalLightColor[ i ] * directionalLightWeighting;",

        "   #ifdef DOUBLE_SIDED",

        "       vLightBack += directionalLightColor[ i ] * directionalLightWeightingBack;",

        "   #endif",

        "}",
        "   #endif",    *
            '}'].join('\n');


this.fragmentShader=[
            THREE.ShaderChunk[ 'logdepthbuf_pars_fragment'],
            'varying vec2 vUv;',
            'uniform float opacity;',
            'uniform sampler2D map;',   



            'void main()',
            '{',

                'gl_FragColor = vec4( 0.0,0.0,0.0, opacity );',
                'gl_FragColor+=texture2D(map,vUv);',
                THREE.ShaderChunk[ 'logdepthbuf_fragment'],

            '}'
].join('\n');