mache

Members
  • Content Count

    31
  • Joined

  • Last visited

  1. Helo guys, Thanks for your reply @jellix Directional light in babylon.js are using shadow mapping so as said Deltakosh it's possible to define a position. Nevertheless I am still a beginner in 3D, the directional light don't seem to be the right choice. What would be an adapted indoor light to fit a scene such as my playground? @Wingnut Yeah I also notice some fun things with the sampling : @Deltakosh Ok I'll give a try to see what can I get.
  2. Hello, I am having trouble with the shadow generator, this playground illustrate my problem => http://www.babylonjs-playground.com/#DAKLR#4 I made a room with a window. Then I add two lights with a shadowgenerator for each one, the two sphere show their position into the scene. The one outside the room act properly (you can see light pass through the window), but the one inside the room light nothing. If you comment line 97 -> 104 (remove the roof) the light inside act properly. Thanks
  3. I can't use photoshop because everything is made at the runtime, I apply it using shaders, now it's looking nice !
  4. Hi thanks for your reply, So I try all the sampling mode: the nearest one cancel the interpolation which is nice I can't redo my unwrap because this is automatically generated by an algo...however in the example, the padding of my atlas can be reduce. The background is already transparent this is why seams are transparent. Seams are due to uv2 which are round to the the texel transparent on the border and not the one coloured, so I think dilatation is the only way to fix it. Thanks again
  5. Hello, I am applying texture using my own uv2. This is the texture applied on a sphere (normal map): And this is the texture: So my problem is that on border of each parts there are seams due to the interpolation between one texel colored and another one at Color4(0,0,0,0). This is causing void then black till the right one value. I could expand the border of one texel (dilatation) to fix that but this is increasing padding in my texture... So first I would like to know if there is another way to cancel this interpolation. Thanks !
  6. I scaled by 5 my scene and it's fitting my needs !
  7. Contour are more smooth, but some thin meshes are not detected (such as cubes at the bottom right or spheres on the floor). I'll try to scale my scene bigger. Thanks again.
  8. Nice it's working, but shadows quality is less good. Thanks a lot
  9. Hello, I am trying to generate shadows for a 3D scene with the ShadowGenerator of Babylon. My problem is the following : a mesh can't create shadows and receiving shadows at the same time. Here is a playground where this is illustrated : http://playground.babylonjs.com/#1R4XE8#1 Let's focus on lines 47 & 48 : torus.receiveShadows = true; shadowGenerator.getShadowMap().renderList.push(torus); If the first one is commented the torus doesn't receive shadow and when it pass into the cube shadow, it is still highlight. If the second one is commented the torus doesn't create shadow but when it pass into the cube shadow, it act well. Finally if the both are uncommented the torus is constantly shadowed (like it is occluding by itself...) Thanks for any help !
  10. ok, I joined my .fx files. debug.fragment.fx debug.vertex.fx
  11. Hello, I tried a for loop into the effect function. Here are main changes into the code: BABYLON.ShaderMaterial.prototype.setTextures = function(name, textures) { if (this._options.samplers.indexOf(name) === -1) { this._options.samplers.push(name); for (let i = 1; i < textures.length; i++) { this._options.samplers.push(name + i);//to match texture unit when binding } } this._textureArrays[name] = textures; return this; }; BABYLON.Effect.prototype.setTextures = function(channel, textures) { var textureUnits = []; for (let i = 0; i < textures.length; i++) { textureUnits.push(this._samplers.indexOf(channel) + i); } var location = this._engine._gl.getUniformLocation(this._program, channel); this._engine._gl.uniform1iv(location, textureUnits); for (let i = 0; i < textures.length; i++) { this._engine.setTexture(textureUnits[i], textures[i]); } }; //part of code added into ShaderMaterial.prototype.bind for (name in this._textureArrays) { this._effect.setTextures(name, this._textureArrays[name]); } this code works fine when I only use setTextures function on a material, but not when I am using in addition a setTexture function. This is caused by : this._samplers.indexOf(channel) When I only use setTextures this.samplers is ok so I got the right one index of nameOfMyArray (0). If I used setTexture in addition this.samplers don't index my array (so I get -1) and texture unit are not well manage. I tested to replace "this._samplers.indexOf(channel)" by the right index hard coded (if i added a single texture then my array index should be 1) and it's working. Any ideas of why setTexture erase nameOfMyArray in this.samplers into Effect ?
  12. Hi, So I took a look at the babylon code. It looks like setTexture and the hypothetic setTextures are going to be in conflict since they share texture units. For now I don't really know how to do it without breaking everything :p. Here is the part which stuck me Engine.prototype.setTexture = function (channel, texture) { if (channel < 0) { return; } // Not ready? if (!texture || !texture.isReady()) { if (this._activeTexturesCache[channel] != null) { this._gl.activeTexture(this._gl["TEXTURE" + channel]); this._gl.bindTexture(this._gl.TEXTURE_2D, null); this._gl.bindTexture(this._gl.TEXTURE_CUBE_MAP, null); this._activeTexturesCache[channel] = null; } return; } // Video var alreadyActivated = false; if (texture instanceof BABYLON.VideoTexture) { this._gl.activeTexture(this._gl["TEXTURE" + channel]); alreadyActivated = true; texture.update(); } else if (texture.delayLoadState === Engine.DELAYLOADSTATE_NOTLOADED) { texture.delayLoad(); return; } if (this._activeTexturesCache[channel] === texture) { return; } this._activeTexturesCache[channel] = texture; var internalTexture = texture.getInternalTexture(); if (!alreadyActivated) { this._gl.activeTexture(this._gl["TEXTURE" + channel]); } if (internalTexture.isCube) { this._gl.bindTexture(this._gl.TEXTURE_CUBE_MAP, internalTexture); if (internalTexture._cachedCoordinatesMode !== texture.coordinatesMode) { internalTexture._cachedCoordinatesMode = texture.coordinatesMode; // CUBIC_MODE and SKYBOX_MODE both require CLAMP_TO_EDGE. All other modes use REPEAT. var textureWrapMode = (texture.coordinatesMode !== BABYLON.Texture.CUBIC_MODE && texture.coordinatesMode !== BABYLON.Texture.SKYBOX_MODE) ? this._gl.REPEAT : this._gl.CLAMP_TO_EDGE; this._gl.texParameteri(this._gl.TEXTURE_CUBE_MAP, this._gl.TEXTURE_WRAP_S, textureWrapMode); this._gl.texParameteri(this._gl.TEXTURE_CUBE_MAP, this._gl.TEXTURE_WRAP_T, textureWrapMode); } this._setAnisotropicLevel(this._gl.TEXTURE_CUBE_MAP, texture); } else { this._gl.bindTexture(this._gl.TEXTURE_2D, internalTexture); if (internalTexture._cachedWrapU !== texture.wrapU) { internalTexture._cachedWrapU = texture.wrapU; switch (texture.wrapU) { case BABYLON.Texture.WRAP_ADDRESSMODE: this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_WRAP_S, this._gl.REPEAT); break; case BABYLON.Texture.CLAMP_ADDRESSMODE: this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_WRAP_S, this._gl.CLAMP_TO_EDGE); break; case BABYLON.Texture.MIRROR_ADDRESSMODE: this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_WRAP_S, this._gl.MIRRORED_REPEAT); break; } } if (internalTexture._cachedWrapV !== texture.wrapV) { internalTexture._cachedWrapV = texture.wrapV; switch (texture.wrapV) { case BABYLON.Texture.WRAP_ADDRESSMODE: this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_WRAP_T, this._gl.REPEAT); break; case BABYLON.Texture.CLAMP_ADDRESSMODE: this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_WRAP_T, this._gl.CLAMP_TO_EDGE); break; case BABYLON.Texture.MIRROR_ADDRESSMODE: this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_WRAP_T, this._gl.MIRRORED_REPEAT); break; } } this._setAnisotropicLevel(this._gl.TEXTURE_2D, texture); } }; This is where texture are binded, so this part of code need to know if there is array of textures as Engine.prototype.setTextures need to know how many single texture are binded. The shaderMaterial which is calling effect function which is calling this function (engine) could know these informations, but I feel that to pass it as parameter is not the right way to do it... How do you think it should be done ? Have a nice weekend
  13. Hello, Yes Iam using ShaderMaterial (you could do the same with an Effect as long you can get the WebGlProgram), finally I did it this way: //this._nbIndexTextures = length of each array for (let i = 0; i < this._nbIndexTextures + 1; i++) { //ini texture units textureUnitsId.push(i); textureUnitsNormal.push(i + this._nbIndexTextures + 1); textureUnitsPosition.push(i + 2 * (this._nbIndexTextures + 1)); } var program = materialBuffer._effect.getProgram(); this._gl.useProgram(program); var idLocation = this._gl.getUniformLocation(program, "idSamplers[0]"); var normalLocation = this._gl.getUniformLocation(program, "normalSamplers[0]"); var positionLocation = this._gl.getUniformLocation(program, "positionSamplers[0]"); this._gl.uniform1iv(idLocation, textureUnitsId); for (let i = 0; i < this._nbIndexTextures + 1; i++) { //id this._gl.activeTexture(this._gl.TEXTURE0 + i); this._gl.bindTexture(this._gl.TEXTURE_2D, this._idTextures[i]._texture); } this._gl.uniform1iv(normalLocation, textureUnitsNormal); for (let i = this._nbIndexTextures + 1; i < 2 * (this._nbIndexTextures + 1); i++) { var index = i - (this._nbIndexTextures + 1); //normal this._gl.activeTexture(this._gl.TEXTURE0 + i); this._gl.bindTexture(this._gl.TEXTURE_2D, this._normalTextures[index]._texture); } this._gl.uniform1iv(positionLocation, textureUnitsPosition); for (let i = 2 * (this._nbIndexTextures + 1); i < 3 * (this._nbIndexTextures + 1); i++) { var index = i - 2 * (this._nbIndexTextures + 1); //position this._gl.activeTexture(this._gl.TEXTURE0 + i); this._gl.bindTexture(this._gl.TEXTURE_2D, this._positionTextures[index]._texture); } Since iam not using babylon js to set my uniforms textures I had bug when using setTexture function, so I also set other single texture this way. (texture unit were not well allocated i guess). this function could just looks like this => setTextureArray(name, textures) each time before binding babylon check textures.length and manage texture units.