Displaying background colour through transparent PNG on material?

前端 未结 1 1892
野性不改
野性不改 2020-12-06 12:48

I\'m making a case builder using THREE.js, the basics are i want to be able to change the height/width/length of a box, rotate it around, and also

相关标签:
1条回答
  • 2020-12-06 13:35

    Three.js MeshBasicMaterial does not support what you are trying to do. In MeshBasicMaterial, if the PNG is partially transparent, then the material will be partially transparent.

    What you want, is the material to remain opaque, and the material color to show through instead.

    You can do this with a custom ShaderMaterial. In fact, it is pretty easy. Here is the fragment shader:

    uniform vec3 color;
    uniform sampler2D texture;
    
    varying vec2 vUv;
    
    void main() {
    
        vec4 tColor = texture2D( texture, vUv );
    
        gl_FragColor = vec4( mix( color, tColor.rgb, tColor.a ), 1.0 );
    
    }
    

    And here is a Fiddle: http://jsfiddle.net/g5btunz9/

    In the fiddle, the texture is a circle on a transparent background. You can see the red color of the material show through.

    three.js r.72

    0 讨论(0)
提交回复
热议问题