Hello,
i’ve have a simple shader that i wanted to add to a loaded glb-object.
Loading works and all but the object stays black. (When i set a Color in the shader it Shows it in that Color).
Now… i was looking around on this page too to find a solution. And i found this thread:
Unable to apply texture to shader material
But i also only see a black square here!
I even copied it locally to my pc and tried it in case the Image didn’t load or something.
So my Questions are:
First: Is there a Problem with my browser or something?
(I get a diffrent result in white with some flickering colors on it, if i just give a random Name to the uniform that is not declared).
2nd: If i load a GLB and want to add a custom shader, does it load all the textures into the new shader(if the uniform names are correct). See JS-Code below. If that is not the case what would be te correct strategy?
3rd: What is the fastest and best way to replace the “Standard”-Shader for everything? This is actually the main goal. There is some stuff i have to remove or at least change.
If someone can help me with this i will be forever grateful!
JS-Code:
var stdShader = THREE.ShaderLib[ 'standard' ];
var uniforms = THREE.UniformsUtils.clone( stdShader.uniforms );
var vS =
`varying vec2 vUv;
void main()
{
vUv = uv;
gl_Position = projectionMatrix * modelViewMatrix * vec4(position,1.0);
}`;
var fS =
`uniform sampler2D map;
varying vec2 vUv;
void main()
{
gl_FragColor = texture2D(map, vUv) + vec4(0.5, 0.5, 0.5, 1.0);
}`;
var material = new THREE.ShaderMaterial({
uniforms: uniforms,
vertexShader: vS,
fragmentShader: fS
});
var leObj;
loader.load( './LeObject.glb', function (gltf)
{
leObj = gltf.scene.children[2];
leObj.material = material;
leObj.material.lights = true;
leObj.material.needsUpdate = true;
leObj.material.aoMapIntensity = 0;
leObj.material.needsUpdate = true;
leObj.castShadow = true;
leObj.receiveShadow = true;
leObj.position.x = 1;
leObj.position.z = -1;
scene.add(gltf.scene);
});