Jump to content

How to Access Unity3D to BabylonJS's ShadowGeneratorList


JBlack_UTD
 Share

Recommended Posts

Hello,

I'd like to access the babylonScene.ShadowGeneratorsList that SceneBuilder.Lights.cs uses, but I can't seem to find any variable that doesn't come up as undefined after I've called the SceneLoader.Load

private void GenerateShadowsGenerator(Light light)
        {
            var generator = new BabylonShadowGenerator
            {
                lightId = GetID(light.gameObject),
                usePoissonSampling = light.shadows == LightShadows.Soft,
                mapSize = 256 + 256 * QualitySettings.GetQualityLevel(),
                bias = light.shadowBias / 10.0f,
                useBlurVarianceShadowMap = light.shadows == LightShadows.Soft
            };

            var renderList = new List<string>();
            foreach (var gameObject in gameObjects)
            {
                //why not deliver the boolean to the scene? I could use that boolean to manually create shadows inside babylon.
                var meshFilter = gameObject.GetComponent<MeshFilter>();
                var renderer = gameObject.GetComponent<Renderer>();
                if (meshFilter != null && renderer.shadowCastingMode != ShadowCastingMode.Off)
                {
                    renderList.Add(GetID(gameObject));
                    continue;
                }

                var skinnedMesh = gameObject.GetComponent<SkinnedMeshRenderer>();
                if (skinnedMesh != null && renderer.shadowCastingMode != ShadowCastingMode.Off)
                {
                    renderList.Add(GetID(gameObject));
                }
            }

            generator.renderList = renderList.ToArray();

            babylonScene.ShadowGeneratorsList.Add(generator); //***How do i access this list in babylon?***
        }

The end goal here would be to emulate the Unity mesh renderer option to cast shadows or not. The exporter does this, but if I can't access the shadow generator list, I can't determine which meshes to push into the wanted shadow generators.

That's my understanding of the problem at least.

As an aside, I've created shadow generators for two point lights (manually), and I'm importing one spot light which I've positively determined has a shadow generator created for it somewhere.

"shadowGenerators":[{"mapSize":1536,"bias":0.005,"lightId":"c21fd6a4-701a-4377-86b9-868b221c1c96","useVarianceShadowMap":false,"usePoissonSampling":true,"useBlurVarianceShadowMap":true,"blurScale":0,"blurBoxOffset":0,"renderList":["f808b945-1605-4e8f-8233-f75b89e55c71","0cc9fd1e-1a23-4c9e-9cef-5b0c87faf717","36d7e455-a32f-490a-b837-3043d6f30691","5091d4f8-2767-4e7e-acb6-a7c179b33583","c5313fc0-4edd-43d7-8dcf-85f76e83905f","d3d119e6-37f5-4725-af03-f470a755ac93","d5d11567-f959-4291-b784-ffb07089e6bd","9141800a-91a8-4d51-bceb-85df54d49e39","acce9ece-cd8f-42fb-98e7-53ff7de56315","cd22cc1d-07f7-4845-9de2-967f42eabf5b","0ad378ab-6f73-4861-91a9-bc649ffd4759","a8e8b351-71a2-4bb9-a995-736b637615a6","385b2d6a-a789-4a2a-ba99-73c45f096c8a","d056b786-d3d8-45dc-ae61-509a34b17f1a","0bf62911-a3cf-4bd8-a0b4-96fd20a89fd2","fdfc93be-5a6c-4049-80de-c6912168f1c8","25efb981-7f78-4c5c-8e28-cfde40b304f5","1bf1b3b6-b0fe-4fe5-a5af-1509ed156dbc","673a7d44-10c1-47e4-9d12-2c55322f3b28","aa4d1889-0951-4d43-81d8-5d774a7012d2","157582a5-5887-4661-bbf8-29aaa6da108c","7b3f2c8d-447b-41fa-9366-d007137e6a3c","c4860f5e-d38e-4285-a098-3a158564dd8e","f5e3a43a-4475-4c67-941d-bab8a377290e","49374c28-a289-471b-83df-2af6773d18b2","d8511075-b08c-47ea-a779-7720c91351ae","e2807f9b-3807-4ae0-bdff-86ab12195672","d730e55a-948c-4ac5-beef-a9eb8ae12479"]}],"skeletons":[],"actions":null}

The only thing left I have to do is determine which meshes can cast shadows, and then push those meshes into the shadow generator render lists.

Thank you for your time.

 

Link to comment
Share on other sites

That seems to have done the trick! Thanks.

for (var i = 0; i < newScene.lights.length; i++){

    if(newScene.lights[i].getShadowGenerator()){
      console.log("dingdingding.");
      newScene.meshes.forEach(function(mesh) {
        newScene.lights[i].getShadowGenerator().getShadowMap().renderList.push(mesh);
      });
      continue;
    }
    ...
}

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...