So I have a Shader where I am loading an array of textureCubes.
for some reason I can not for the life of me get the texture to bind, here is what I have:
varying vec3 vPosition;
varying vec3 vNormal;
varying vec3 vCubeUV;
#if ACTIVE_LAYERS > 0
uniform samplerCube textureSampler[ACTIVE_LAYERS];
#endif
uniform int displayState;
void main() {
vec4 color = vec4(1.0,0.0,0.0,1.0);
#if ACTIVE_LAYERS > 0
for(int l=ACTIVE_LAYERS; l>0; l--){
color = textureCube(textureSampler[0], vPosition);
#endif
gl_FragColor = color;
}
It should grab the color of the cubeTexure at index 0 but instead I get the error that the texture is not bound.
here is the setter:
f(this.activeLayers > 0){
var aLayers = []
this.layers.forEach((l)=>{
aLayers.push(l)
})
shader.setTextureArray('textureSampler', aLayers)
}
Is there something special I have to do sense they are cubes?
mmmm you know what now that I think about it, I bet its because textureSamplers name is reserved in BJS ShaderMaterial…
UPDATE
hmmm nope… I changed it all to reference layerSampler as the name instead and am dropping the same error. I checked and it looks like on the javascript object for the shader material the array is bound correctly. I would use spector to debug but for some reason it wont get focus on my secondary scene.
ohhh Im dumb. its because they are on my main scenes scope. I need to pass them over to the other scene!
@Deltakosh
you will prolly know a quick fix, I tried:
var aLayers = []
this.layers.forEach((l)=>{
aLayers.push(BABYLON.CubeTexture.Parse(l.serialize(), this.scene))
})
but because I guess the 6 textures that comprise the cubeTexture are stored on the last scenes context and do not get passed with the serialize parse.
so I am guessing a cubeTexture.toRaw or something and then cubeTexture.fromRaw is prolly what I need to do but I’m not really sure how.
UPDATE
dang, I hate tagging someone then figuring it out… my bad D.
this.layers.forEach((l)=>{
var ct = BABYLON.CubeTexture.CreateFromImages(
l._files,
this.scene
)
ct.name = l.name
ct.uID = l.uID
aLayers.push(ct)
})
2 Likes