AlexB

Members
  • Content Count

    84
  • Joined

  • Last visited

  • Days Won

    1

AlexB last won the day on August 16 2014

AlexB had the most liked content!

About AlexB

  • Rank
    Advanced Member

Recent Profile Visitors

670 profile views
  1. This seems to be working, but only intermittently. Sometimes I will see my texture, but then I change some arbitrary code someone else and it'll stop working. It seems as though there is a race condition somewhere. When I inspect the scene using Spector, I don't always see the uniforms. I know for a fact that the material creator method is happening before the uniform setting method. I can also re-trigger the setter function so I don't think it's a race condition in my code.
  2. No, what's the syntax for that?
  3. I'm having a really hard time figuring this out. I'm creating this material. this.material = new BABYLON.ShaderMaterial( part.url, this.viewService.scene, { vertex: '/shaders/v', fragment: '/shaders/f', }, { needAlphaBlending: true, needAlphaTesting: true, defines: [ '#extension GL_OES_standard_derivatives : enable', '#define IS_CLOWN_PASS 0', '#define IS_TRANSLUCENT false', '#define IS_METAL false', ], attributes: ['position', 'uv', 'normal'], uniforms: [ 'world', 'worldView', 'worldViewProjection', 'view', 'viewProjection', 'u_combinedTextures', 'texArr', ], } ); Then a few seconds later, in a totally different function, I'm attempting to update a uniform. this.material.setTextureArray('texArr', [ // red BABYLON.RawTexture.CreateRGBATexture(new Uint8Array([255, 0, 0, 255]), 1, 1, this.viewService.scene), // blue BABYLON.RawTexture.CreateRGBATexture(new Uint8Array([0, 0, 255, 255]), 1, 1, this.viewService.scene), ]); this.material.isReady(mesh); mesh.material = this.material; This works if I paste this code right below where I create the material. Otherwise it seems to not set the values (I use SpectorJS to inspect the uniforms). Some questions: Is there another command I need to call to get the material to update? Does every uniform need to be in the initial uniforms array? How does setting the uniforms directly differ from scene.registerBeforeRender and doing it there?
  4. Can you give an example of how to use a uniform buffer object with Babylon? Our user base will all be on WebGL2 browsers.
  5. AlexB

    Using Arrays With ShaderMaterial

    Thank you, this helps a lot!
  6. I notice that there's a setTextureArray method, but I don't see any corresponding methods for vec2s, vec3s, etc. As an example, if I want something like: (Typescript) const offsets: Vector2[] = [ new Vector2(1, 1), new Vector2(2, 1), new Vector2(3, 1), new Vector2(4, 1), ] And I want to be able to use this in my shader, like this: (GLSL) uniform offsets vec2[4]; for (int i = 0; i < 4; i++) { vec3 tex = texture2D(sampler, uv * offsets[i]); // do something awesome here } I don't see any easy way to do it. Any clues?
  7. https://github.com/BabylonJS/Babylon.js/issues/4520
  8. I was hoping that adding support for structures would be faster than re-wiring my shader, but I think it'll be faster to just use arrays. But I'd still love to have support for structs at some point. They make the shaders way more readable, IMO. Thanks for your help!
  9. It turns out this is a harder problem than I thought. There is no low level method on the GL object to set structures, so what the ThreeJS implementation is doing is looping through a structure and discovering each type in a recursive loop. Then it applies each struct property one by one. I'm not sure I have time to figure it out. I got a good start on it if anyone wants to give it a try. I can push up a branch.
  10. Gotcha. I'll look into adding support for that. Would it just affect ShaderMaterial and the _checkUniform method? I don't quite understand all your code yet. It's changed a lot since I last used it 🙂
  11. I was referring to this bit of code in ShaderMaterial where it lists all the uniform types: private _textureArrays: { [name: string]: Texture[] } = {}; private _floats: { [name: string]: number } = {}; private _ints: { [name: string]: number } = {}; private _floatsArrays: { [name: string]: number[] } = {}; private _colors3: { [name: string]: Color3 } = {}; private _colors3Arrays: { [name: string]: number[] } = {}; private _colors4: { [name: string]: Color4 } = {}; private _vectors2: { [name: string]: Vector2 } = {}; private _vectors3: { [name: string]: Vector3 } = {}; private _vectors4: { [name: string]: Vector4 } = {}; private _matrices: { [name: string]: Matrix } = {}; private _matrices3x3: { [name: string]: Float32Array } = {}; private _matrices2x2: { [name: string]: Float32Array } = {}; private _vectors2Arrays: { [name: string]: number[] } = {}; private _vectors3Arrays: { [name: string]: number[] } = {}; It doesn't appear that I can set a Struct type, like so: https://www.babylonjs-playground.com/#ATDL99#1 * Note that I'm trying to use a myColor.color vec3 instead of fogColor
  12. @Deltakosh am I right that Babylon does not support GLSL struct objects?
  13. So by defines, you mean having conditional code in the same shader, but omitting one by setting a flag? #ifdef HAS_METALROUGHNESSMAP uniform sampler2D u_MetallicRoughnessSampler; #endif
  14. Update: I have a shader loading using the ShadersStore array. BABYLON.Effect.ShadersStore[`${part.url}FragmentShader`] = ` precision highp float; varying vec2 vUV; struct Color { vec3 color } Color myColor; void main(void) { gl_FragColor = vec4(1., 0., 0., 1.); } `; This works, and I can update the fragment shader. But it appears that Babylon doesn't support GLSL structures? Is there a way to access the shader uniforms directly?
  15. I think I'll be posting a lot as we port from ThreeJS over to Babylon, so apologies. Our application allows user input to affect the appears of a 3D object. A user can change out a material on an object. Sometimes, this means that the uniforms should change. For instance, we may want to use a structure like: struct Graphic { vec2 flip; vec2 offset; float rotation; vec2 scale; sampler2D texture; sampler2D normal; }; However, if the graphic does not have a normal texture, we don't need that texture slot so I'll write the structure on the fly like this: struct Graphic { vec2 flip; vec2 offset; float rotation; vec2 scale; sampler2D texture; vec3 normal; }; So when I create a ShaderMaterial, it allows me to send in a frag shader and a vertex shader as string, like so: const material: any = new BABYLON.ShaderMaterial( name, scene, { vertex: 'some vertex', fragment: 'some fragment', }, { // options } ); But how can I later update that frag shader with new text? Something like: material.fragmentShader = newFrag; Thanks! EDIT: It also looks like I can't just set the frag and vertex code as a string. Does it have to be wrapped somehow?