0

In two cases, I have a THREE.ShaderMaterial that doesn't doesn't correctly render an object, omitting its texture. On both examples, the middle object is a basic THREE.MeshPhongMaterial

Example1: http://jsfiddle.net/sG9MP/4/ The object that's closest to the screen never shows. On this one, it works with renderer.render(...) but not composer.render(...).

renderer.render( scene, camera );
//composer.render();  

Example2: http://jsfiddle.net/sG9MP/5/ Here I'm trying to duplicate the MeshPhongMaterial shader as a base so I can modify it. I tried to replicate it perfectly. I copied the uniform, vert, frag, and replicated what's in the object. I can't see anything different, so I don't get why it's not working the same as the standard Three.js phong shader.

So it's two cases where I'm using THREE.ShaderMaterial and it's not rendering the shader correctly, and I can't figure out why. On the second example(which is the one where I really need fixed. The first was an old test), in the webGL inspector I see the scene often looks fine until there is a "bindTexture(TEXTURE_2D, null);" call that happens under the hood by three.js. Though sometimes it just draws without it. In the first example, it's always drawing without it.

I feel like I must be missing some sort of flag in the renderer, or composer, or something. Or in my second example, where I'm trying to copy the Three.js phong shader, maybe I didn't copy something perfectly.

The goal here is just to copy the phong shader, so I can modify the uniform, vert, and frag on it. Sadly, I can't simply .clone() it since the vert and frag can't be modified after it's compiled.

1 Answer 1

0

It looks like while ShaderMaterial.map was being set, ShaderMaterial.uniforms.map.value was not consistently set.

I really don't understand this, though. In some cases I had issues not setting things at the top level under ShaderMaterial. Other cases I have issues not setting uniforms.

In my material, I just went and added this:

    for(var k in phongMat){
        if( typeof phongMat.uniforms[k] != 'undefined' ){
            phongMat.uniforms[k].value = phongMat[k];
        }
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.