MackeyK24

Members
  • Content Count

    1165
  • Joined

  • Last visited

  • Days Won

    8

Everything posted by MackeyK24

  1. Thats weird that 0.0005 work from code but not from the .babylon file. Anyways... The unity exporter has the bias tied to Light.ShadowBias / 100.0f... So i just adjust the Direction Light Component -> Shadow Bias -> 0.01 Seems to work in sandbox now
  2. Just to be sure... i added shadows.blurScale = 0... Here is the console.log(shadows)... Everything matches whats in the .babylon file... Shadows still disappear on sandbox: ShadowGenerator _bias: 0.00005 _blurBoxOffset: 0 _cachedDefines: "#define FULLFLOAT↵#define NUM_BONE_INFLUENCERS 0" _cachedDirection: Vector3 {x: -0.32139380162218123, y: -0.7660444418664807, z: 0.5566704028097004, toString: function, getClassName: function, …} _cachedPosition: Vector3 {x: 0, y: 0, z: 0, toString: function, getClassName: function, …} _currentFaceIndex: 0 _currentFaceIndexCache: 0 _currentRenderID: 1916 _darkness: 0 _effect: Effect {_isReady: true, _compilationError: "", _valueCache: Object, _engine: Engine, name: "shadowMap", …} _filter: 2 _light: DirectionalLight {state: "", metadata: Object, animations: [], _ranges: {}, _childrenFlag: -1, …} _lightDirection: Vector3 {x: -0.32139380162218123, y: -0.7660444418664807, z: 0.5566704028097004, toString: function, getClassName: function, …} _mapSize: 2048 _projectionMatrix: Matrix {m: Float32Array, isIdentity: function, determinant: function, toArray: function, asArray: function, …} _scene: Scene {autoClear: true, clearColor: Color3, ambientColor: Color3, forceWireframe: false, forcePointsCloud: false, …} _shadowMap: RenderTargetTexture {hasAlpha: false, getAlphaFromRGB: false, level: 1, coordinatesIndex: 0, coordinatesMode: 4, …} _transformMatrix: Matrix {m: Float32Array, isIdentity: function, determinant: function, toArray: function, asArray: function, …} _transparencyShadow: false _useFullFloat: true _viewMatrix: Matrix {m: Float32Array, isIdentity: function, determinant: function, toArray: function, asArray: function, …} _worldViewProjection: Matrix {m: Float32Array, isIdentity: function, determinant: function, toArray: function, asArray: function, …} blurScale: 0 forceBackFacesOnly: false
  3. What are all the babylon possible shader attributes and uniforms: // Attributes attribute vec3 position; attribute vec3 normal; attribute vec2 uv; // Uniforms uniform mat4 worldViewProjection; i assume they will all be equiv to some webgl attribute (if you had to do in strait webgl). So i assume: position = gl_Vertex -> To vec3 normal = gl_Normal -> To vec3 uv = gl_MultiTexCoord0 - To vec2 and worldViewProjection = gl_ProjectionMatrix * gl_ModelViewMatrix and so on... What are all the other possible attributes and uniforms, and most importantly what do they equal in regular GLSL. A... I just would to really understand where each attribute and uniform comes from. B... I am trying to make a 'Universal Unity Babylon GLSL Shader Template' for use directly in the Unity for creating Babylon shaders. Minimal Example Shader For Unity: Shader "BabylonJS/Sample basic shader" { // defines the name of the shader SubShader { // Unity chooses the subshader that fits the GPU best Pass { // some shaders require multiple passes GLSLPROGRAM // here begins the part in Unity's GLSL #ifdef VERTEX // here begins the vertex shader void main() // all vertex shaders define a main() function { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; // this line transforms the predefined attribute // gl_Vertex of type vec4 with the predefined // uniform gl_ModelViewProjectionMatrix of type mat4 // and stores the result in the predefined output // variable gl_Position of type vec4. } #endif // here ends the definition of the vertex shader #ifdef FRAGMENT // here begins the fragment shader void main() // all fragment shaders define a main() function { gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); // this fragment shader just sets the output color // to opaque red (red = 1.0, green = 0.0, blue = 0.0, // alpha = 1.0) } #endif // here ends the definition of the fragment shader ENDGLSL // here ends the part in GLSL } } } My intent was to parse the shader text blocks for the vertex and fragment sections during export. Then do some kind 'key text replace' in the vertex part that reads all the attributes and uniforms replace with babylon.js equivalent at export. I would also love to base64 encode this vertex and fragment program right in the ShaderMaterial section of the .babylon son file. I posted a topic on this, hopefully others can see the benefits as well. Anyways... Any info on all the BUILT-IN attributes and uniforms that babylon.js exposes (and how they are calculated so i can duplicate that calculation when running in unity editor) THANK YOU VERY MUCH
  4. Did you take a look at the .babylon file in sandbox. Can you see why the shadows disappear. Is there something wrong with the .babylon file
  5. I don't know if you know about DuoCode. But i created almost exact matching Typescript API. Actually i created a TypeScript Syntax Tree Parser that actual uses the TypeScript Compiler API type COMPLETLY Parser Typescript declaration file and generate and XML file containing all the necessary info to create C# DuoCode BINDINGS to the Underlying JavaScript. The whole thing is on my github: My GitHub. And the Main BABYLON C# Plugin is up on nuget: Install-Package DuoCode.Plugins.Babylon If you know about .d.cs declaration files... Attached is the one i created to MIRROR the original TypeScript for BabylonJS 2.5... Take a look babylon.d.cs
  6. My Manual Code (Which works great) is in C#. I have create a C# web application framework fro creating html5 apps using C# and compiled with DuoCode/Roslyn Base Transpilers.. but there nothing wrong with code. Works great. If you take just the raw .babylon file, add some shadow generator stuff in and upload it to sandbox... Take one off the mesh and hover above ground... drop sphere with physics or something.. You will see the shadow disappear. Check out the .babylon file. Just normal file with this shadowGeneratorSection (Which works fine if i manually create shadow generator) with this at end: "shadowGenerators" : [ { "mapSize" : 1024, "bias" : 0.0005, "lightId" : "5fd822aa-70bf-48da-8da1-3021a5fe381c", "useVarianceShadowMap" : false, "usePoissonSampling" : true, "useBlurVarianceShadowMap" : false, "blurScale" : 0, "blurBoxOffset" : 0, "renderList" : [ "7a74ef4d-7046-4195-9ffb-100b88ce7341", "d87e092c-a207-43cd-9689-a9292e3f943d", "21a62f75-7343-4811-a1de-03a58e88db32" ], "forceBackFacesOnly" : false } ], If you wanna see what parts of the API i am manually using... Here is my C# GameView Controller Class: using System; using System.Threading.Tasks; using DuoCode.Dom; using DuoCode.Runtime; namespace BxGame.Duo { public class GameView : ViewController { public BABYLON.Engine GameEngine { get; set; } public HTMLCanvasElement GameCanvas { get; set; } public BABYLON.Color3 GameColor { get; set; } public GameView() { this.GameColor = new BABYLON.Color3(0.0, 255.0, 0.0); } protected override void OnInitialize(object parameter) { base.OnInitialize(parameter); this.element.style.backgroundColor = this.GameColor.toRgbString(); // Initialize content view this.GameCanvas = Root.create<HTMLCanvasElement>("canvas"); this.GameCanvas.style.width = "100%"; this.GameCanvas.style.height = "100%"; this.GameCanvas.style.touchAction = "none"; this.element.appendChild(this.GameCanvas); this.GameEngine = new BABYLON.Engine(this.GameCanvas, true); this.GameEngine.clear(this.GameColor, true, true); // Initialize resize window event Global.window.onresize += (UIEvent arg1) => { this.GameEngine.resize(); return true; }; // Initialize main game scene BABYLON.SceneLoader.Load("Scenes/Test1/", "MiniGame.babylon", this.GameEngine, (scene) => { var sunlight = new BABYLON.HemisphericLight("hemi", new BABYLON.Vector3(0, 1, 0), scene); var skybox = BABYLON.Mesh.CreateBox("skyBox", 400.0, scene); var skyboxMaterial = new BABYLON.StandardMaterial("skyBox", scene); skyboxMaterial.backFaceCulling = false; skyboxMaterial.reflectionTexture = new BABYLON.CubeTexture("Scenes/Test1/TropicalSunnyDay", scene); skyboxMaterial.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE; skyboxMaterial.diffuseColor = new BABYLON.Color3(0, 0, 0); skyboxMaterial.specularColor = new BABYLON.Color3(0, 0, 0); skybox.material = skyboxMaterial; // Wait for textures and shaders to be ready scene.clearColor = this.GameColor; scene.executeWhenReady(() => { scene.activeCamera.attachControl(this.GameCanvas); Root.log(scene); Trace.Info("Physics Enabled: {0}", scene.isPhysicsEnabled()); BABYLON.DirectionalLight light = scene.getLightByName("Directional Light").As<BABYLON.DirectionalLight>(); light.intensity = light.intensity * 1.5; BABYLON.AbstractMesh cube = scene.getMeshByName("Cube"); BABYLON.AbstractMesh sphere = scene.getMeshByName("Sphere"); BABYLON.AbstractMesh capsule = scene.getMeshByName("Capsule"); BABYLON.AbstractMesh ground = scene.getMeshByName("Ground"); //var shadows = light.getShadowGenerator(); var shadows = new BABYLON.ShadowGenerator(2048, light); shadows.usePoissonSampling = true; Root.log(shadows); cube.receiveShadows = true; sphere.receiveShadows = true; capsule.receiveShadows = true; ground.receiveShadows = true; shadows.getShadowMap().renderList.push(sphere.As<dynamic>(), cube.As<dynamic>(), capsule.As<dynamic>()); //UnityMetaData data = (sphere.metadata != null) ? sphere.metadata.As<UnityMetaData>() : null; //Trace.Info("===> Mesh Metadata: {0} - {1} - {2} - {3}", data.tagName, data.layerIndex, data.layerName, data.parentId); // Once the scene is loaded, just register a render loop to render it this.GameEngine.runRenderLoop(() => { //var ratio = 1.0; //cube.rotation.x += 0.025 * ratio; //cube.rotation.y += 0.025 * ratio; scene.render(); }); }); }); } protected override void OnDispose() { base.OnDispose(); } } } SORRY NO JAVASCRIPT TO LOAD IN PLAYGROUND I am attaching the .babylon file MiniGame.babylon
  7. IF ITS NOT ALREADY IN BABYLON.JS (and i just don't see it) Can we embed vertex and fragment programs in the .babylon file on the 'materal' object of the material customType="BABYLON.ShaderMaterial" Example: { "customType" : "BABYLON.ShaderMaterial", "name" : "Items", "id" : "dadbe3ae-445f-4fe4-b83f-000b27b2b8d4", "backFaceCulling" : true, "wireframe" : false, "alpha" : 1, "shaderPath" : "Items", "options" : { "attributes" : [ "position", "uv" ], "uniforms" : [ "worldViewProjection" ], "needAlphaBlending" : false, "needAlphaTesting" : false, "samplers" : [], "defines" : [] }, "textures" : {}, "floats" : {}, "floatArrays" : {}, "colors3" : {}, "colors4" : {}, "vectors2" : {}, "vectors3" : {}, "vectors4" : {}, "matrices" : {}, "matrices2x2" : {}, "matrices3x3" : {} }, Can we add somewhere in a 'base64' encoded string for the shader programs... Something like: "vertexBase64" : "*** BASE64 ENCODED VERTEX PROGRAM ***", "fragmentBase64" : "*** BASE64 ENCODED FRAGMENT PROGRAM ***", Then in the client side Material parser... If we got base64 parsdedMaterial data with our programs already there... no need to make TWO separate server trips to get our shader programs... plus the shader programs are then cached when storing .babylon files in indexedDB. Also it can easily work with sandbox and just drag that single .babylon file to sandbox (ONCE sandbox get the PR fix to use BABYLON.ShaderMaterial vertexBase64 and fragmentBase64) then folks custom shaders will work on the sandbox... Right now if you have BABYLON.ShaderMaterial defined in your .babylon file (and don't use a qualified path) the server will never find or use them (unless you know where those files end up after posting to server and are available ... still would hard code sandbox path to shader program in your .babylon file.).. For some reason if don't use path and just name... it looks in '/src/Sharder/myShader.vertex.fx' Anyways I'm going to play with the github Material.Parse stuff to use material.vertexBase64 and fragmentBase63 IF PRESENT... After i had them to the ShaderMaterial class... Hope you guys like this idea ... That last one to get metadata added seems like a tough sell... I hope you consider this...
  8. BTW... Notice the physics state information in the .babylon file. So physics in working in the sandbox for meshes defined in the scene with unity and without having to do ANY client side setPhysicsState on every mesh, because they had the babylon physics state script attached to them in unity... So you can just drag that one .babylon file to sandbox with no EXTRA client side javascript to enable the physics Very Kool
  9. I think there may be a problem with the "lifecyle" of a exported shadow generator. If i create the shadow generator with the exporter (good bias and filter settings) the shadows show up IF the Y position is high enough off the ground. But if close to ground ... no shadows. If i create the shadows in the client scene.executeWhenReady the shadows are perfect... If i Console.log both shadows generators (the one created from unity exporter and the one manually created) they are the same. Its weird... Maybe something to do with "Where In The Scene Lifecycle" the shadow generator is being created of exported and the shadow generator info is in the .babyone scene file. I am attaching a test .babylon file exported from unity... The shadow generator part of the .babylon looks fine. but even in sandbox. With none of my babylon enhancements, the .babylon on load... Show the sphere above the ground... Shadows enabled and physics enabled... The balls starts to drop but when it gets close to ground, the shadow disappears. Its gotta be something in the way way is reading the shadow generator information and instantiates the BABYLON.ShadowGenerator... or maybe WHEN is instantiates the BABYLON.ShadowGenerator. Anyways take a look a the MiniGame.babylon file in SANDBOX MiniGame.babylon
  10. Hey David... Is there a way to either from the UnityExport Babylon classes or in Babylon JS client, to set the Default Physics Framework? I know about scene.enablePhysics()... BUT i have went ahead and implemented Unity Exporter Physics Option. The only problem is at the UnityExporter level i can't seem to find any api to set where the framework should use OIMO or CANNON. By default it seems to use CANNON. But i want to give the option on the Unity Exporter Window to specify which physics to use. Using my new exporter physics stuff you can now easily just add a 'BabylonPhysicsState' unity script component to your mesh in unity: using System; using UnityEngine; public sealed class BabylonPhysicsState : MonoBehaviour { public float mass = 0.0f; public float friction = 0.2f; public float restitution = 0.2f; public BabylonPhysicsImposter imposter = BabylonPhysicsImposter.None; } Then the SceneBuilder.Meshes ConvertUnityMeshToBabylon: // Babylon Physics if (exportationOptions.ExportPhysics) { var physics = gameObject.GetComponent<BabylonPhysicsState>(); if (physics != null) { babylonMesh.physicsMass = physics.mass; babylonMesh.physicsFriction = physics.friction; babylonMesh.physicsRestitution = physics.restitution; babylonMesh.physicsImpostor = (int)physics.imposter; } } Using 'BabylonPhysicsImposter' enums in the Unity Inspector: public enum BabylonPhysicsImposter { None = 0, Sphere = 1, Box = 2, Plane = 3, Mesh = 4, Cylinder = 7, Particle = 8, Heightmap = 9 } And is all kicked off from SceneBuilder ConvertFromUnity: // Babylon Physics if (exportationOptions.ExportPhysics) { babylonScene.physicsEnabled = true; babylonScene.physicsGravity = exportationOptions.Gravity.ToFloat(); } This works great... No need to manually call scene.enablePhysics from code OR mesh.setPhysicsState. But would be REAL NICE if i could do: babylonScene.physicsEngine = "oimo" at the UnityExporter level or at least a engine.setDefaultPhysicsEngine("oimo")... Or something like that. Right now, using my built-in unity exported physics will ONLY use cannon.js NOTE: I will be push all this to a github Pull Request after i done cleaning up a few things. So far i got: 1... Manifest export support 2... Unity Meta Data Support (including unity tags and layers) 3... Extended shadow export options 4... Babylon Physics State Script Component 5... Abstract base class 'BabylonGameComponent' to support custom babylon client side game components classes. public abstract class BabylonGameComponent : MonoBehaviour { internal const string DEFAULT_GAME_COMPONENT = "System.Default.Component"; [Unity3D2Babylon.ReadOnly] public string babylonClass; protected BabylonGameComponent() { this.babylonClass = BabylonGameComponent.DEFAULT_GAME_COMPONENT; } } You can them make custom scripts in unity and attach to components like normal, including Meshes, Cameras, Lights and Empty GameObjects: using UnityEngine; using System.Collections; public class MyRotator : BabylonGameComponent { public MyRotator() { this.babylonClass = "My.Custom.RotatorClass"; } [BabylonProperty] public float speed; } I think its SWEET
  11. Also i found the shadow generator on the light not the scene: var shadows = light.getShadowGenerator(); And i Added a field 'Map Size Factor' to the Shadow Export Section of the ExportWindow. Default ExportWindow.MapSizeFactor to '256' But now you can easily change your shadow map size from exporter by using mapSizeFactor instead of hard coding '256': var generator = new BabylonShadowGenerator { lightId = GetID(light.gameObject), usePoissonSampling = light.shadows == LightShadows.Soft, mapSize = mapSizeFactor + mapSizeFactor * QualitySettings.GetQualityLevel(), bias = light.shadowBias / 100.0f };
  12. If i am reading things right... The lower the shadow bias to 0 for it to show up... since the light shadow bias default to like 0.05... Then the shadow generator in the unity exporter should divide by 100 instead of 10... Like so: var generator = new BabylonShadowGenerator { lightId = GetID(light.gameObject), usePoissonSampling = light.shadows == LightShadows.Soft, mapSize = 256 + 256 * QualitySettings.GetQualityLevel(), bias = light.shadowBias / 100.0f };
  13. 1... So is there anything that needs to be done to 'Active' the shadows created by unity exporter? or is supposed to be automatic? 2... When you say play with shadow bias, are talking about adjusting the bias on the Unity Exporter side? var generator = new BabylonShadowGenerator { lightId = GetID(light.gameObject), usePoissonSampling = light.shadows == LightShadows.Soft, mapSize = 256 + 256 * QualitySettings.GetQualityLevel(), bias = light.shadowBias / 10.0f }; 3... How do i get a reference on client client javascript side after the scene has been loaded, to the ShadowGenerator created from UnityExporter, Is there some kind of scene.getShadowGenerator() or something... So far the only way i got shadows working is to manually create on client side javascript in the scene ready event like so: float quality = 1.0f; var shadows = new BABYLON.ShadowGenerator(256 + 256 * quality, light); shadows.useBlurVarianceShadowMap = true; shadows.getShadowMap().renderList.push(cube.As<dynamic>());
  14. Shadows from UnityExporter not showing. The export shadows options is on but i don't see any shadows... I can manually create shadows, but i thought the exporter was supposed to create shadows for you, if you have a 'Render' component on the game object along side the MeshFilter. Or is there something i have to do thru code to enable the shadows from UnityExporter?