自定义phong着色器envMap翻转

时间:2016-01-26 11:39:30

标签: three.js glsl shader

我使用ShaderMaterial,它是默认Phong着色器的完整副本(我使用shaderChunks)。

我的问题是envMap翻过X ......

这是我得到的:

what I get

我想要的是什么:

what I want

我尝试访问cubeCamera.renderTarget.texture以使用repeat.x = -1wrapS = THREERepeatWrapping.RepeatWrapping,但它绝对没有...

var cubeCamera = new THREE.CubeCamera(0.01, 500, 256);
scene.add(cubeCamera);

var sphereMaterial = new THREE.ShaderMaterial({
    uniforms: THREE.UniformsUtils.merge([
        THREE.UniformsLib.common,
        THREE.UniformsLib.aomap,
        THREE.UniformsLib.lightmap,
        THREE.UniformsLib.emissivemap,
        THREE.UniformsLib.bumpmap,
        THREE.UniformsLib.normalmap,
        THREE.UniformsLib.displacementmap,
        THREE.UniformsLib.fog,
        THREE.UniformsLib.lights,
        THREE.UniformsLib.shadowmap,
        {
            emissive: {
                type: "c",
                value: new THREE.Color(0x000000)
            },
            specular: {
                type: "c",
                value: new THREE.Color(0x111111)
            },
            shininess: {
                type: "f",
                value: 30
            },
            envMap: {
                type: "t",
                value: cubeCamera.renderTarget
            }
        }
    ]),
    vertexShader: require("../../shaders/phong.vert.glsl"),
    fragmentShader: require("../../shaders/phong.frag.glsl"),
    blending: THREE.AdditiveBlending,
    depthWrite: false,
    transparent: true,
    opacity: 1,
    lights: true
});

sphereMaterial.envMap = true;

修改

JSFIDDLE example

1 个答案:

答案 0 :(得分:2)

要获得您所追求的反射,请设置

sphereShaderMaterial.uniforms.flipEnvMap.value = 1;

我不确定何时在MeshPhongMaterial上实际设置了这个,我怀疑WebGLRenderer中的某个位置会进行一些检查并设置它。 WebGLRenderer对不同类型的材料做了很多事情,这使得它们很难轻易扩展。