SpaceToast

Members
  • Content count

    24
  • Joined

  • Last visited

  1. SpaceToast

    Ideas: Best Way to Extend the StandardMaterial?

    That's not a drawback in this case. Unfortunately, after 6 hours trying to understand the source code, I'm no closer to figuring how to inject a new uniform into the StandardMaterial object at runtime. It's just too amazingly complicated. Afraid I'll have to go back to my previous method. 😔
  2. SpaceToast

    Ideas: Best Way to Extend the StandardMaterial?

    I was 100% wrong about that last comment. Replacing the StandardMaterial's shaders is as simple as: BABYLON.Effect.ShadersStore["defaultVertexShader"] = ` //Copy the StandardMaterial's vertex shader code in here, and modify away. //Template literals are your friend. `; BABYLON.Effect.ShadersStore["defaultPixelShader"] = ` //Copy the StandardMaterial's pixel shader code in here, and modify away. `;
  3. SpaceToast

    Ideas: Best Way to Extend the StandardMaterial?

    Thanks @Pryme8, @Sebavan and @NasimiAsl. CustomMaterial looks like exactly what I need. Unfortunately, it doesn't seem to be production-ready just yet, based on the other forum threads. I could see saving a bit of trouble by replacing the StandardMaterial object with a custom version at runtime--one containing my changes. I'm not really familiar with JavaScript modules, however: They seem to be designed specifically to prevent code from tinkering around inside their scope.
  4. I'm picking up an older project again, and moving it to the current version of BJS. This is a pain, though, because I'd been extending the StandardMaterial shader within a copy of the BJS framework itself. The project made extensive use of noise and shape functions to simulate textures within the GPU by altering the diffuse, specular and normal values of the StandardMaterial, based on a flag hacked into the framework. The advantage of this method vs. ShaderMaterial was getting unlimited resolution textures at no bandwidth cost without having to reimplement all the goodies in the StandardMaterial--SSAO2, fog, shadows, etc. The disadvantage: Lack of portability, and having to find a way to re-minify everything myself before deployment. (My kingdom for uglify.js to support the `` multiline literal...) Before I start migrating my hacks, I wanted to ask this of the smart people around the water cooler: Can anyone suggest a more elegent way to do this, without modifying BJS itself?
  5. SpaceToast

    Getting the Results of SceneLoader.Append()

    I'll migrate over to the 3.2 preview and experiment with it! Looks like a great tool.
  6. What is the best way to get the results--the appended bits--from BABYLON.SceneLoader.Append() ? The function for a single model, BABYLON.SceneLoader.ImportMesh(), and the function to load a new scene BABYLON.SceneLoader.Load(), both return their result, but Append() seems to only return the existing scene. I believe I understand the concept in this thread--mark everything that's already loaded before calling BABYLON.SceneLoader.Append(), at which point everything that's not marked can be assumed to come from the file load. The trouble is, if multiple files are being loaded, there's no guarantee that all of the new meshes, lights and cameras in the scene come from the same file when onSuccess fires. (This is assuming file loading happens async.) I suppose it would be possible to use BABYLON.SceneLoader.Load() to instead put the results into a new (hidden) scene, loot that scene for parts to the main scene, then delete it. That feels like a lot of overhead though. Any better ideas? [Peeling this out into its own topic, as Q&A threads don't "bump" anyway!]
  7. SpaceToast

    Babylon Scene vs some Model

    Sorry to "bump" an old topic, but is there a better way to get the results--the appended bits--from BABYLON.SceneLoader.Append() ? I believe I understand the concept above--mark everything that's already loaded before calling BABYLON.SceneLoader.Append(), at which point everything that's not marked can be assumed to come from the file load. The trouble is, if multiple files are being loaded, there's no guarantee that all of the new meshes, lights and cameras came from the same file when this append's onSuccess fires. (This is assuming file loading happens async.) I suppose it would be possible to use BABYLON.SceneLoader.Load() to instead put the results into a new (hidden) scene, loot that scene for parts, then delete it. That feels like a lot of overhead though. Any ideas?
  8. (Edited out into its own post, because, messiness.) A further discovery I'd love to have verified: It appears that the uniforms above do not need to be declared when creating a shaderMaterial -- Babylon.js supplies them for you. So rather than declaring: var shaderMaterial = new BABYLON.ShaderMaterial("shader", scene, {vertex: "custom", fragment: "custom"}, {attributes: ["position", "normal", "uv"], uniforms: ["world", "worldView", "worldViewProjection", "view", "projection"]} ); You can omit the attributes section, unless supplying your own custom data to the shader: var shaderMaterial = new BABYLON.ShaderMaterial("shader", scene, {vertex: "custom", fragment: "custom"}, {attributes: ["position", "normal", "uv"], uniforms: ["capybaras"]} );
  9. Kosh's link. Based on the CYOS examples, I can verify that the following are available: // Attributes attribute vec3 position; //vertex x,y,z attribute vec3 normal; //normal x,y,z attribute vec2 uv; //uv (texture map) 2d coordinates // Uniforms uniform mat4 world; //convert from model space to world space uniform mat4 view; //convert world space to camera-relative space uniform mat4 projection; //flatten camera space to frame view uniform mat4 worldView; //world and view, pre-multiplied for you uniform mat4 worldViewProjection; //world, view & projection pre-multiplied uniform sampler2D textureSampler; //texture data uniform vec3 cameraPosition; //camera x,y,z uniform float time; //time Are there any predefined shader attributes or uniforms that I'm missing?
  10. Dead link. Has this been added to the documentation? I wasn't able to find it. If not, maybe someone wouldn't mind pasting the relevent information into this thread for posterity's sake?
  11. SpaceToast

    What's next?

    I'd love to see any of the following: LOD enhancements: LOD blending. Not sure what the "cheapest" method to reduce pop-in is. 1-bit pattern masks? Load and dispose at LOD. A "set it and forget it" method to load a model/scene file into the current scene when needed, then dispose of it when no longer needed. This would be quite helpful for building large/streaming type worlds, but useful even for small scenes to reduce load times. (Everyone hates a loading screen!) More user-friendly shaders: Built-in primitives. Rather than Road, Fire, Brick, etc. a set of option-heavy primitives like SimplexNoise, CellTurb, Gradient, Tiles, SphereMap, PlanarMap, etc. Primitive combiners. In prerendered 3d, nesting nodes like gradients, noise patterns and falloff types allows for the creation of extremely rich non-repeating textures from very short descriptors. Could something similar be done to generate pixel shaders? A simpler method to remap keys and other input methods (as opposed to just adding and removing keys). (On background, I'm working on a virtual museum of Earth history, in which every step you take represents a million years. So, a mesh-heavy scene that's almost 2 miles long. I'm an old hat at animation, but new to realtime 3D. What I'm mainly finding is that the bottleneck isn't the amount of content to be rendered, but getting that content to the user's browser in the first place.)
  12. SpaceToast

    Altering the Vertices of an Imported Mesh

    Ahh! Good point, Kosh. Object.setVerticesData() does not update normals. Unless that's desirable (or you're also creating a normals array manually), object.updateMeshPositions() may still be the best way to go. I'll leave my four-step answer alone.
  13. SpaceToast

    Altering the Vertices of an Imported Mesh

    Appreciate the help, crew. (And yeah, my Float32 conclusion came from a coding typo on my part!) What I'm really trying to do is map out the "gotchas" around editing vertex data in bjs. What I'm mostly finding is that the better-documented updateMeshPositions() method is rather delicate and unnecessarily complex--at least in my specific case of using a webworker to generate the new vertex arrays. Possibly in most cases.
  14. SpaceToast

    Altering the Vertices of an Imported Mesh

    Thanks, JC. In other words--to surface the lede from your code--you can replace vertex data directly with object.setVerticesData(), but only if your new data is in an [explicitly created] Float32 array. Is there any advantage to using an object.setVerticesData() function?
  15. SpaceToast

    Altering the Vertices of an Imported Mesh

    Hmm. Might be a bug. In Chrome and Firefox, at least, only editing the values of the position array in situ appears to work. Regardless, for anyone using this thread for future reference, you'll need to take the following steps to alter an imported mesh. (Here's a working playground to follow along.) Kosh (All Kosh?) Thanks again! Rip out the mesh's vertex position data & stuff it back in, with updateable set to true: var pos = bb.getVerticesData(BABYLON.VertexBuffer.PositionKind); bb.setVerticesData(BABYLON.VertexBuffer.PositionKind, pos, true); Rip out the mesh's vertex normals & stuff them back in, with updateable set to true: var nm = bb.getVerticesData(BABYLON.VertexBuffer.NormalKind); bb.setVerticesData(BABYLON.VertexBuffer.NormalKind, nm, true); Call updateMeshPositions() on the mesh: bb.updateMeshPositions(positionFunction, true); Create a function to edit the vertex positions, for updateMeshPositions() to trigger. Note that updateMeshPositions() automatically passes the vertex position array of the mesh that calls it as an argument to your position function: var positionFunction = function(positions) { var numberOfVertices = positions.length/3; for (var i = 0; i < numberOfVertices; i++) { positions[i*3] = Math.random(); positions[i*3+1] = Math.random(); positions[i*3+2] = Math.random(); }; };