Jump to content

[SOLVED] - Replace Mesh Vertex Data


MackeyK24
 Share

Recommended Posts

2 hours ago, adam said:

I'm not sure why you aren't getting any love NasimiAsi.  This was perfect.

edit:  I guess it could be the dependency.

@NasimiAsl No disrespect ... was not ignoring your suggestion. Its just that i a C# Unity exporter to dynamically create mesh colliders based on the Unity Collider component values... I was only pushing off the procedural creating of the mesh to the client because i DIDNT know how to create a Capsulemanually creating the vertices and cvs and ultimately the triangles by hand so i was using the client VertextData.CreateXXX functions... I ran into an issue with no built in create capsule function... Now at this point i really would not want to have have an additional dependency on library (Geometry Builder) just to create a capsule... so native would always be better for something that small... that being said... I finally figured out (found and copied/tweaked some code) how capsules can be made manually in c# unity:

//------------------------------//
//  ProceduralCapsule.cs        //
//  Written by Jay Kay          //
//  2016/05/27                  //
//------------------------------//

Thank You Jay Kay... Whoever you are :)

 I appreciate your suggestions :)

 Looking for all the help i can get to understand something so i can re-create that functionality in the toolkit... Everything i do in here... Every question i ask in here... is ALWAYS so i can get a BETTER understanding of something that END UP in the toolkit :)

Yeah... Look at all my Smiley faces... Im stoked i finally got this shot all running smoothly for TOTAL BabylonJS Game Development using the IDE... At no point in any video from start to finish and final publishing to internet ... did i make a traditional html page and setup script tags and all the other standard web development stuff with visual studio and IIS or IIS Express or WAMP , MAMP none of that...

Just 1... 2... 3... Game Development

1... Create and standard unity project with the BabylonJS Toolkit...

2... Add scripts and content to your scene in the stand unity style using BabylonJS components and shaders

3... HIT PLAY (Or Export & Preview Button Really)

I think is FXXXXX awesome ... I WILL NEVER NEVER NEVER create a BabylonJS the traditional web page way... As a matter a fact... THIS ENTIRE TOOLKIT  API was written in the Unity Project that just started off with Assets->Create->BabylonJS->Typescript Class

 Another Smiley Face :)

Thanks again @Deltakosh and especially you @Sebavan it was REALLY good talking things over with that night... I really appreciate your help in helping FULLY understand all my special heightmap pixel value PACKING / UNPACK so i don't loose ANY precision on my NATIVE UNITY RAW HEIGHTMAP VALUES... Thanks Bro.

 

EDIT: 

I will USE the scenes created in the toolkit in a LARGER web project... But again... I will ALWAYS create the game, whether its a single game scene or multilevel game... whether i making a game or a 3d visualization with for my medical software (My Day Job :)) with full scriptable control from the larger project because the toolkit generates project.d.ts files so you can consume your game and control (attach or whatever you want) from your larger web project :)

 

Link to comment
Share on other sites

Oh yeah... and once i port that VertexData.CreateCapsule ... That native code for create capsule right in vertex data... using only vertices and building the triangles with that WELL put together code by Jay Kay... That has got to be the better solution for something that small as just 1 capsule creation.

Besides... We could use a light weight Mesh.CreateCapsule :)

 

Link to comment
Share on other sites

On 12/14/2016 at 9:27 AM, MrVR said:

I cant wait to put my hands on your code., if you need any type of help you can PM me, I have lots of spare time and Im willing to put it here

Yo @MrVR ... Does that offer still stand. I am just have a the hella of time with my light baking system (Im still so new, i guess I'm not understanding all the options available for full light map baking).

 Now i have seen 'PLENTY' of little snippets here and there with 1 or 2 lines of code that says something vague like 'Use Ambient Texture' to provide light maps ... But NOT the complete details ... I can't write a solution that is supposed to be a dev toolkit and not not ALL the options i need to be settings... 1 line of code the say material.blahblahblah is no where enough info i need to make something like flowing code... Take a look i need to be able set everything on the material (OR NOT SET) that has to do with full light baking.. Now this currently my code for dumping a material use a "fullBaking" boolean value to set things up if you in fullBaking mode(emissive) or regular material mode (diffuse or albedo)... Whether lightmapTexture SHOULD be used if i am using emissiveTexture... I can't tell... So i am really JUST GUESSING... Anyways take at look at this code to see what i am trying to do:

 

private BabylonMaterial DumpStandardMaterial(Material material, int lightmapIndex = -1, Vector4 lightmapScaleOffset = default(Vector4), int lightmapCoordIndex = -1)
{
    var materialNotSupported = false;
    if (!materialsDictionary.ContainsKey(material.name)) {
        var bMat = new BabylonStandardMaterial {
            name = material.name,
            id = Guid.NewGuid().ToString(),
            diffuse = new float[4],
            specular = new float[4]
        };

        ExporterWindow.ReportProgress(1, "Exporting std material: " + material.name);
        bool fullbaking = (exportationOptions.DefaultShadowBaking == (int)BabylonLightmapOptions.FullBaking);
        if (fullbaking) SceneBuilder.Metadata.bakedMaterials.Add(bMat.id);

        bMat.diffuse[0] = 1.0f;
        bMat.diffuse[1] = 1.0f;
        bMat.diffuse[2] = 1.0f;
        bMat.diffuse[3] = 1.0f;

        bMat.specular[0] = 0.0f;
        bMat.specular[1] = 0.0f;
        bMat.specular[2] = 0.0f;
        bMat.specular[3] = 1.0f;

        if (material.HasProperty("_Shininess")) {
            var specShininess = material.GetFloat("_Shininess");
            bMat.specularPower = specShininess * 128;
        }

        if (material.mainTexture && material.mainTexture.GetType().FullName == "UnityEngine.ProceduralTexture") {
            materialNotSupported = true;
            Debug.LogWarning("ProceduralTexture: " + material.mainTexture.name + " not supported by Babylon.js");
        }

        if (material.mainTexture && !(materialNotSupported)) {
            var mainTexture2D = material.mainTexture as Texture2D;
            var mainTexturePath = AssetDatabase.GetAssetPath(mainTexture2D);
            var alphaCuttOff = 0f;
            if (material.HasProperty("_Cutoff")) {
                alphaCuttOff = material.GetFloat("_Cutoff");
            }
            if (fullbaking) {
                ExporterWindow.ReportProgress(1, "Baking std material lighting: " + material.name);
                bMat.diffuse[0] = 1.0f;
                bMat.diffuse[1] = 1.0f;
                bMat.diffuse[2] = 1.0f;
                bMat.diffuse[3] = 1.0f;
                bMat.specular[0] = 0.0f;
                bMat.specular[1] = 0.0f;
                bMat.specular[2] = 0.0f;
                bMat.specular[3] = 1.0f;
                // Emissive
                if (material.HasProperty("_Color")) {
                    bMat.emissive = material.color.ToFloat();
                }
                bMat.emissiveTexture = new BabylonTexture {
                    uScale = material.mainTextureScale.x,
                    vScale = material.mainTextureScale.y,
                    uOffset = material.mainTextureOffset.x,
                    vOffset = material.mainTextureOffset.y
                };
                CopyTexture(mainTexturePath, mainTexture2D, bMat.emissiveTexture);
                if ((mainTexture2D && mainTexture2D.alphaIsTransparency) || alphaCuttOff > 0) {
                    bMat.emissiveTexture.hasAlpha = true;
                    bMat.backFaceCulling = false;
                }
                // Diffuse
                bMat.diffuseTexture = null;
            } else {
                // Diffuse
                if (material.HasProperty("_Color")) {
                    bMat.diffuse = material.color.ToFloat();
                }
                if (material.HasProperty("_SpecColor")) {
                    var specColor = material.GetColor("_SpecColor");
                    bMat.specular = specColor.ToFloat();
                }
                bMat.diffuseTexture = new BabylonTexture {
                    uScale = material.mainTextureScale.x,
                    vScale = material.mainTextureScale.y,
                    uOffset = material.mainTextureOffset.x,
                    vOffset = material.mainTextureOffset.y
                };
                CopyTexture(mainTexturePath, mainTexture2D, bMat.diffuseTexture);
                if ((mainTexture2D && mainTexture2D.alphaIsTransparency) || alphaCuttOff > 0) {
                    bMat.diffuseTexture.hasAlpha = true;
                    bMat.backFaceCulling = false;
                }
                // Emissive
                bMat.emissiveTexture = DumpTextureFromMaterial(material, "_Illum");
                if (material.HasProperty("_Emission")) {
                    var emissiveColor = material.GetColor("_Emission");
                    bMat.emissive = emissiveColor.ToFloat();
                }
            }
        }

        bMat.bumpTexture = DumpTextureFromMaterial(material, "_BumpMap");
        bMat.ambientTexture = DumpTextureFromMaterial(material, "_LightMap");
        bMat.reflectionTexture = DumpTextureFromMaterial(material, "_Cube");

        // If no ambient texture already (ambientTexture manually set for lightmaps on standard material)
        bool hasLightmap = (exportationOptions.ExportLightmaps && bMat.ambientTexture == null && lightmapIndex >= 0 && lightmapIndex != 65535 && LightmapSettings.lightmaps.Length > lightmapIndex);
        if (exportationOptions.DefaultShadowBaking != (int)BabylonLightmapOptions.Realtime && hasLightmap && bMat.ambientTexture == null) {
            var lightmap = LightmapSettings.lightmaps[lightmapIndex].lightmapLight;
            var texturePath = AssetDatabase.GetAssetPath(lightmap);
            if (!String.IsNullOrEmpty(texturePath)) {
                ExporterWindow.ReportProgress(1, "Dumping std material lightmap: " + lightmap.name);
                bMat.lightmapTexture = DumpTexture(lightmap, isLightmap: true);
                bMat.lightmapTexture.coordinatesIndex = (lightmapCoordIndex >= 0) ? lightmapCoordIndex : exportationOptions.DefaultCoordinatesIndex;
                bMat.useLightmapAsShadowmap = !fullbaking;

                bMat.lightmapTexture.uScale = lightmapScaleOffset.x;
                bMat.lightmapTexture.vScale = lightmapScaleOffset.y;

                bMat.lightmapTexture.uOffset = lightmapScaleOffset.z;
                bMat.lightmapTexture.vOffset = lightmapScaleOffset.w;
            }
        }
        materialsDictionary.Add(bMat.name, bMat);
        return bMat;
    }
    return materialsDictionary[material.name];
}

And that does even get into using a PBR material to do the same thing :(

 

Link to comment
Share on other sites

20 hours ago, MackeyK24 said:

Yo @MrVR ... Does that offer still stand. I am just have a the hella of time with my light baking system (Im still so new, i guess I'm not understanding all the options available for full light map baking).

 Now i have seen 'PLENTY' of little snippets here and there with 1 or 2 lines of code that says something vague like 'Use Ambient Texture' to provide light maps ... But NOT the complete details ... I can't write a solution that is supposed to be a dev toolkit and not not ALL the options i need to be settings... 1 line of code the say material.blahblahblah is no where enough info i need to make something like flowing code... Take a look i need to be able set everything on the material (OR NOT SET) that has to do with full light baking.. Now this currently my code for dumping a material use a "fullBaking" boolean value to set things up if you in fullBaking mode(emissive) or regular material mode (diffuse or albedo)... Whether lightmapTexture SHOULD be used if i am using emissiveTexture... I can't tell... So i am really JUST GUESSING... Anyways take at look at this code to see what i am trying to do:

 

Hello  @MackeyK24, Base on a recent research I made, light map baking is data structure storage where light data of a surface is cache on a texture map, (please correct me if i'm wrong), so the properties for fully baking we should store 

  • Lighting
  • Diffuse color  
  • Specular color
  • Reflections
  • Shadows
  • Ambient color
  • Self-illumination color   
  • Refractions

For light maps I have seen options such render shadows or not, direct light or indirect light (with specular or not and  from 3Ds- max options), that may help to create the class,

also found more information from unity manual with all the light maps parameters  that are support below I post link and the table.

 

Please let me know if this information is helpful , other wise please point me in the right direction to help you better,

COMPLETE GUIDE OF OPTIONS

 

newLightmapParameters.png

 

Property: Function:
Precomputed Realtime GI  
Resolution This value scales the Realtime Resolution value in the Scene tab to give the final resolution of the lightmap in texels per unit of distance.
Cluster Resolution The ratio of the “cluster” resolution (ie, the resolution to which the light bounces are calculated internally) to the final lightmap resolution.
Irradiance Budget This value determines the precision with which incoming light data is used to light each texel in the lightmap. Essentially, each texel’s lighting is obtained by taking a “view” of the scene from its position (ie, recording the pattern of incoming light). Lower values of irradiance budget will result in a more blurred view that measures the pattern of light less precisely; higher values increase the sharpness of the view. A higher irradiance budget will improve the lighting but at the expense of increased memory usage and possibly some extra CPU overhead.
Irradiance Quality The quality of the transfer of internal light bounce data to the final lightmap texture. Higher values offer visual improvements in the lightmap but at the expense of increased precomputing time in the editor; the value does not affect runtime performance. This property actually refers to the number of rays that are used internally to evaluate the internal data for each lightmap texel.
Backface Tolerance The structure of a mesh can sometimes cause some texels to have a “view” that includes backfaces. Since incoming light from a backface is meaningless, this property lets you select a percentage threshold of that light that must come from front facing geometry in order for a texel to be considered valid. Invalid texels have their lighting approximated from neighbours’ values.
Modelling Tolerance The maximum size of gaps in mesh geometry that can be ignored for GI purposes.
Edge Stitching If enabled, this property indicates that UV “charts” in the lightmap should be joined together seamlessly so as to avoid visual artifacts.
Is Transparent If enabled, the object will appear transparent during the Global Illumination calculations. Backfaces are not contributing and light travels through the surface. This is useful for emissive invisible surfaces.
System Tag A group of objects whose lightmap textures are combined in the same lightmap atlas is known as a “system”. Unity will automatically define additional systems and their accompanying atlases if all the lightmaps can’t be fitted into a single atlas. However, it is sometimes useful to define separate systems yourself, to create dynamically loaded levels, say. By changing the System Tag number, you will force a new system and lightmap to be created. The exact numeric sequence values of the tag are not significant.
Baked GI  
Blur Radius The radius (in texels) of the blur filter that is applied to direct lighting during postprocessing. The radius is essentially the distance over which neighbouring texels are averaged out; a larger radius gives a more blurred effect. Higher levels of blur tend to reduce visual artifacts but also soften the edges of shadows.
Antialiasing Samples The degree of antialiasing (ie, reduction of “blocky” texel artifacts) that is applied.
Direct Light Quality The number of rays used to evaluate direct lighting. A higher number of rays tends to produce more accurate soft shadows.
Baked Tag Similar to the System Tag property described above, this number lets you group specific sets of objects together in their own baked lightmaps. As with the System Tag, the exact numeric value is not significant; objects use the same baked lightmap if they have the same Baked Tag value. You don’t have to set this when using the multi scene bake API; grouping is done automatically.
Pushoff The amount to push off geometry for ray tracing, in modelling units. It is applied to all baked lightmaps, so it will affect direct light, indirect light and AO. It is useful for getting rid of unwanted AO or shadowing. It can also be used to remove artefacts on huge objects where floating point precision isn’t high enough to accurately ray trace.
Baked AO  
Quality The number of rays that are cast when evaluating ambient occlusion (AO). Higher numbers of rays increase the AO quality.
Antialiasing Samples The degree of antialiasing (ie, reduction of “blocky” texel artifacts) that is applied.

 

Bake

Global bake settings.

Property: Function:
Mode Controls both offline lightmap baking and runtime lightmap rendering modes. In Dual Lightmaps mode both near and far lightmaps will be baked; only deferred rendering path supports rendering dual lightmaps. Single Lightmaps mode results in only the far lightmap being baked; can also be used to force single lightmaps mode for the deferred rendering path.
Use in forward rendering (Dual lightmaps only) Enables dual lightmaps in forward rendering. Note that this will require you to create your own shaders for the purpose.
Quality Presets for high (good-looking) and low (but fast) quality bakes. They affect the number of final gather rays, contrast threshold and some other final gather and anti-aliasing settings.
Bounces The number of light bounces in the Global Illumination simulation. At least one bounce is needed to give a soft, realistic indirect lighting. 0 means only direct light will be computed.
Sky Light Color Sky light simulates light emitted from the sky from all the directions - great for outdoor scenes.
Sky Light Intensity The intensity of the sky light - a value of 0 disables the sky light.
Bounce Boost Allows to exaggerate light bouncing in dark scenes. If a scene is authored with dark materials, it’s easy to compensate with strong direct lighting. Indirect lighting will be very subtle though, as the bounced light will fade out quickly. Setting bounce boost to a value larger than 1 will compensate for this by pushing the albedo color towards 1 for GI computations. Note that values between 0 and 1 will decrease the light bounce. The actual computation taking place is a per component pow(colorComponent, (1.0/bounceBoost)).
Bounce Intensity A multiplier to the intensity of the indirect light.
Final Gather Rays The number of rays shot from every final gather point - higher values give better quality.
Contrast Threshold The threshold above which new final gather points will be created by the adaptive sampling algorithm. Higher values make Beast be more tolerant about illumination changes on the surface, thus producing smoother but less-detailed lightmaps. A low number of final gather rays gives noise, which is local contrast. It might need higher contrast threshold values not to force additional final gather points to be created.
Interpolation Controls the way the color from final gather points will be interpolated. 0 for linear interpolation, 1 for advanced, gradient-based interpolation. In some cases the latter might introduce artifacts.
Interpolation Points The number of final gather points to interpolate between. Higher values give more smooth results, but can also smooth out details in the lighting.
Ambient Occlusion The amount of ambient occlusion to be baked into the lightmaps. Ambient occlusion is the visibility function integrated over the local hemisphere of size Max Distance, so doesn’t take into account any lighting information.
Lock Atlas When Lock Atlas is enabled, automatic atlasing won’t be run and lightmap index, tiling and offset on the objects won’t be modified.
Resolution The resolution of the lightmaps in texels per world unit. A value of 50 and a 10x10 unit plane will result in the plane occupying 500x500 texels in the lightmap.
Padding The space between individual objects in the atlas, given in texels.

 

~ Ref : https://en.wikipedia.org/wiki/Lightmap

~ Ref : https://knowledge.autodesk.com/support/3ds-max/learn-explore/caas/CloudHelp/cloudhelp/2015/ENU/3DSMax/files/GUID-B1597F7A-EAF4-4197-BB7C-42A90C12BBCB-htm.html 

~ Ref: unity https://docs.unity3d.com/Manual/LightmapParameters.html

Link to comment
Share on other sites

HI @MackeyK24 The info below explain pretty well how the baking is done by unity, the document below explains the global illumination options (so many options, I'm not sure if this is what you looking for) 

Lightmap resolution and padding

Ambient Occlusion

Indirect Intensity  ... 

This is pretty much how a simple scene with a plane, cube, and directional light looks without any lighting baked in.

Blog-LightBake_04

Default Unity scene with a plane and a cube


In order to bake your lighting information into a light-map you need to tell Unity at least two things.

Which light is going to have its information baked in, and which objects are going to remain static in the scene.

Step 1: Mark your objects as static

Blog-LightBake_02

Object set to static

Step 2: Set your scene light to baked instead of realtime

Blog-LightBake_01

Lighting baking mode set to baked

Finally, with Baked GI checked in the Lighting tab you should see the lighting baked into this little testing scene. In the bottom right of the lighting tab you will see how many lightmaps have been baked, at what resolution, and what the file size of the lightmap(s) is. Now that the basics are out of the way, let’s look at some of the knobs, dials, and options that can give us some control over this.

Blog-LightBake_03

Simple scene set up to bake lightmaps

Lightmapping custom objects with ‘Generate Lightmap UVs’

A 3D object can have several UV channels. Normally, objects store their texture location information into the UV0 channel. By default, Unity will bake lighting information using the UV0 channel which usually does not give desirable results if you have overlapping UVs. With a 3D package such as Maya or 3ds Max you can create a set of UVs in the UV1 channel that Unity will reference when baking lighting information. You can also have Unity automatically generate information in the UV1 channel by checking the ‘Generate Lightmap UVs’ box in the .fbx importer settings.

Blog-LightBake_05

Generate Lightmap UVs

On non-organic objects it’s pretty useful to generate these lightmap UVs automatically. On organic objects I recommend creating a custom UV1 channel as the automatically generated results usually put the lightmap seams in rather visible places.

Continuous/Auto Baking

This is a checkbox that can be found at the bottom of the Lighting panel. When left on, any changes in the scene or in the lighting settings will automatically be calculated in the background as you continue working. Unless you have a beast of a machine or working on a really small scene, I recommend you leave this off and only Build your lightmaps when you need to. Additionally, when manually baking lightmaps Unity will store the lightmaps in a folder with the same name as your scene in same folder as your scene.

Blog-LightBake_06

Continuous/auto baking

Baked Global Illumination settings

Lightmap resolution and padding

The way to increase the resolution in your lightmaps is to increase the texels (texture pixels) per unit in your lightmap, higher values will create larger maps. If you notice that some of the light information starts to blend or bleed into the wrong surfaces of your objects you can try increasing the padding so that there will be more space on the lightmap between the UV islands. If you notice compression artifacts on gradients you can try unchecking ‘Compressed’ at the expense of lightmap file size. Lastly, the indirect resolution will determine the resolution of the bounce light in texels per unit. As you may notice from the images below, pushing this value much further past 2 did not have much of a noticeable effect.

Blog-LightBake_26

Indirect resolution at close to 0

Blog-LightBake_27

Indirect lighting at 2

Blog-LightBake_28

Indirect lighting at 4

Ambient Occlusion

To make your objects feel more grounded in the environment it is common to add what is called ambient occlusion. Ambient occlusion is basically a phenomenon where areas appear darker when surfaces get close to each other. The Ambient Occlusion value in the Lighting tab determines the intensity of this effect and the ‘Max Distance’ is the distance along the surface after which this effect is no longer visible. The cube I used for the examples below is 1 cubic unit. With a max distance of 0.5, the falloff of this effect therefore travels halfway up this cube. With an Ambient Occlusion intensity of 5 it now becomes pretty clear how this works.

Blog-LightBake_13

No Baked GI, no Ambient Occlusion

Blog-LightBake_14

Baked GI, Ambient Occlusion at 1 with Max Distance at 1

Blog-LightBake_15

Baked GI, Ambient Occlusion at 5, Max Distance at 0.5

Final Gather

As for the last option in the Baked GI section of the Lighting tab. I’m not quite sure what kind of noticeable added benefit Final Gather has to justify the extra baking time but if someone is out there that knows and can show me, then that would be great.

General Global Illumination settings

This section in Unity’s lighting tab contains settings shared between precomputed realtime GI and baked GI. I’m not going into the directional mode as it’s pretty well explained in this blog post on the Unity forum: http://forum.unity3d.com/threads/directional-lightmaps.280716/. Further along in the Lighting tab, Unity’s tooltips can shed some light on what Indirect Intensity and Bounce Boost do exactly.

Indirect Intensity

Blog-LightBake_16

Indirect Intensity tooltip

 Bounce Boost

Blog-LightBake_17

Bounce Boost tooltip

The Default Parameters in Unity’s Lighting tab affect the quality of the bake. I usually set this to ‘Default-VeryLowResolution’ in the initial stages of of the baking process in order to make me aware of problems sooner without having to wait very long for a bake to finish. Then, when I’m reasonably certain there are no big lighting problems, I set the Default Parameters to higher resolutions.

Atlas size

This value determines the dimensions of the lightmap in pixels. When using large surfaces such as floors or ceilings you may notice that an atlas size of 1024 probably isn’t enough. In this case you could cut up your mesh so that the lightmap can be distributed over more texture maps. Another option is to increase the atlas size of your lightmap so that there is more space to put the information onto. Try to keep your target platform in mind when considering very large texture maps. Something you might encounter is that when dialing the Atlas Size up to 4096 or higher is that the Lighting tab will still say the lightmap is set to 2048px. This will occur when you manually initiate your lightmap bake and the lightmap will appear in your project as a texture. The texture import settings of the lightmap will be set to 2048px by default. Change this to this to the Atlas Size you entered and you are good to go.

Blog-LightBake_18

Atlas Size set to 4096 with continuous baking disabled. Manually punch in the Max Size of the texture

Tips and tricks

Advanced Generate Lightmap UVs

This section in the FBX import settings allows you to determine how the UV1 channel for that object is automatically generated. This can be useful for problems in automatically generating UVs for objects that don’t have perfect 90 degree angles.

Blog-LightBake_19

Generate Lightmap UVs Advanced options

Preview Texel Density

In the top left of your scene view you can find a dropdown that allows you to change how you see the scene. In the bottom of this dropdown you can find preview options for Global Illumination. The last option in that list should say ‘Baked’. This allows you to preview the texel resolution of your lightmap. Smaller squares represent more resolution in texels per unit in your lightmap.

Blog-LightBake_20

Preview Texel Density

Scale in Lightmap

In the Lighting tab, under the Object section, you can find object specific lighting settings. One of which is the ‘Scale In Lightmap’. This value determines how much space this object will take up in your lightmap. Combined with the Texel Density Preview, you can see how this translates in resolution when you hit that bake button. This can be useful when determining the Scale In Lightmap to make the most use out of your lightmap textures for static objects at various distances from the camera.

Blog-LightBake_21

Scale In Lightmap

Bake only an object’s shadow

Sometimes it is useful for an object to cast a shadow in the lightmap, but not to receive any lightmap information itself. When this is the case you can set the ‘Scale In Lightmap’ to 0.

Blog-LightBake_22

Scale In Lightmap set to 0

This object will still be influenced by lightprobes if this is enabled in the object’s Mesh Renderer component. One of the benefits I found using this for is parked cars. Due to the details and curved nature of the cars in one of our scenes it became pretty costly to get a good result out of baking these objects. The solution was to not bake the cars but just their shadows and ambient occlusion.

Blog-LightBake_23

No lightmap, casting shadows, affected by lightprobes

Consider which lights to bake and which to keep realtime and when

As of this writing, the Mixed Shadows setting on lights is not yet working as it should in Unity 5.0. The Mixed Shadows setting normally allows for baking lights into an environment while also supporting near lights to cast realtime shadows. This is great in cases where, for example, a character walks past a light and casts pretty shadows while having ambient occlusion and environment shadows baked in to be enjoyed at larger distances from the camera. Unity is aware of the Mixed Shadows issue and I can’t wait for it to be fixed. In the meanwhile, we would still like to have realtime shadows in our game. One way to do it is to only have the important lights cast the shadows you need in an environment.

Blog-LightBake_25

Manually mixing realtime and baked lighting

Hopefully you got something useful out of this blog and perhaps it helps you either get started with lightbaking in Unity or maybe it expands on what you already knew. Regardless, If you want to follow up with some questions or you have a trick or two to teach me about Unity then you can always hook me up on Twitter @tinovdk. Consider sharing this with people that can benefit from it. Thank you for reading through to the end. ^^

 

~ I took this from http://sassybot.com/blog/lightmapping-in-unity-5/

Link to comment
Share on other sites

@MrVR WOW... great research... I actually am NOT having ANY trouble from the unity side (although you found quite a few things i didn't know about the unity side). Here is my last message to @Deltakosh

I will... But my problem is not with unity... It knowing what i should in babylonjs to implement a fully baked scene... I think this is what should happen in the babylonjs part... but not sure if this what i should be doing one a have a light map and textures... no matter if it came from unity or not.

1... Everywhere that you would normally stick your texture image in 'diffuseTexture' ... put in emmisiveTexture instead. while settings the 'diffuse' color white and specular to black.

2... Since i have a light map... i stick that in lightmapTexture (since there is NO ambientTexture providing shadows via the shader computing values from the ambientTexture.. I also set useLightmapAsShadow to true... always true if i am using lightmaptexture to give shadows... I THINK)

3... NO THIS REALLY WHAT IM UNSURE ABOUT... Say i throw a mix of real time lights as well... I get this effect of double the light appearing on the already baked materials... I can only assume i need to exclude those meshes using baked materials already from ANY other lights (maybe unless i want to stick a semi light to give a little more ambient light to baked material)...

I THINK THIS IS RIGHT... but not sure... i can't to seem find anything that says all the steps i need to do in babylonjs to implement a fully baked scene. Just a few lines here and there that say "just use lightmapTextue or something like that... Well i am using lightmapTexture... But i don't know what ELSE should SET or NOT SET (as in don't set diffuseTexture)... DO I HAVE TO EXCLUDE those meshes from light (is the normal process or am i just making up shit).



I think you saw... i was really frustrated yesterday.... Im better today... Will try again 

 

With that being said... LET TAKE UNITY OUT OF PICTURE TOTALLY...

Now just say you had a few textures and lightmap (no matter where the lightmap came from... unity, 3dsmax, maya... anything)

Now you wanna make a BabylonJS scene with NO LIGHTS... What is EVERYTHING that you need to take into account in BabylonJS to create scene with fully baked lighting...

Again... NOT just 1 or 2 lines that say "I would just use a lightmapTexture or use ambientTexture ... THAT IS OF NOW REAL USE TO ME... Its much more you to take into account ... And just saying 'use lightmapTexture' DOES NOT TELL ME ANYTHING USEFUL... I GET THAT ... USE lightmapTexture. But what ARE the properties that need to be set on NOT ONLY the lightmapTexture but anything that will be influenced by the scene... For example... Set emissiveTexture but not diffuseTexture and also set useLightmapAsShadowmap = true... Now these i gathered from searching around... Every little piece a code i see take a DIFFERENT approach and show 1 or 2 line of code for actually setting the texture on light map or diffuse... but nothing explaining the WHOLE theory of everything you would need to implement in BabylonJS to make a fully baked scene (NO UNITY... just forget UNITY and use the light map... that happen to come from unity)

Then to really cap things off...This statement from @Deltakosh has really got me confused:

On 12/15/2016 at 5:49 AM, Deltakosh said:

So use either EmissiveTexture (additive) or LightMapTexture (multiplicative)

This is REALLY confusing... 

IF i am using baked lighting ... I HAVE to use emissiveTexture... thats where the light comes from for that material.. is emitting its own light...

IF i want shadows... I HAVE to use lightmapTexture (or ambientTexture for shader computed shadows)

SO HOW CAN THIS STATEMENT BE TRUE... How can you EITHER use emissiveTexture OR lightmapTexture.

Again... All my confusion is on the BabylonJS side... Now since i don't see a real guide line to go by... i am just making shit up...

But i don't know if its right... And don't wanna put SHITTY code out ... Especially if that code is TOTALLY WRONG and it should NOT be done that way...

Please take a look at my last Video... As you can see i have "MacGuyver" together what I THINK should be going on... JUST get this double light effect when mixing baked and realtime... Now i don't know if the double lighting IS SUPPOSED to happen and i need to account for that by excluding baked meshes from all lights... Or if what i did was totally wrong and that is output ... BECASE IM WRONG.

My baking issues

I am trying to get a hold of @Sebavan ... I know with just 5 mins explaining what should be done in babylon js if wanna a fully baked scene... with a little realtime shadows mixed in... NOTHING TO DO WITH UNITY... 

Just make a straight hand coded babylonjs scene made for fully baked lighting.

WOW .. that was a lot again ...

Thanks @MrVR for all your excellent unity research :)

 

 

 

Link to comment
Share on other sites

On 12/16/2016 at 4:16 PM, MackeyK24 said:

@MrVR WOW... great research... I actually am NOT having ANY trouble from the unity side (although you found quite a few things i didn't know about the unity side). Here is my last message to @Deltakosh


I will... But my problem is not with unity... It knowing what i should in babylonjs to implement a fully baked scene... I think this is what should happen in the babylonjs part... but not sure if this what i should be doing one a have a light map and textures... no matter if it came from unity or not.

1... Everywhere that you would normally stick your texture image in 'diffuseTexture' ... put in emmisiveTexture instead. while settings the 'diffuse' color white and specular to black.

2... Since i have a light map... i stick that in lightmapTexture (since there is NO ambientTexture providing shadows via the shader computing values from the ambientTexture.. I also set useLightmapAsShadow to true... always true if i am using lightmaptexture to give shadows... I THINK)

3... NO THIS REALLY WHAT IM UNSURE ABOUT... Say i throw a mix of real time lights as well... I get this effect of double the light appearing on the already baked materials... I can only assume i need to exclude those meshes using baked materials already from ANY other lights (maybe unless i want to stick a semi light to give a little more ambient light to baked material)...

I THINK THIS IS RIGHT... but not sure... i can't to seem find anything that says all the steps i need to do in babylonjs to implement a fully baked scene. Just a few lines here and there that say "just use lightmapTextue or something like that... Well i am using lightmapTexture... But i don't know what ELSE should SET or NOT SET (as in don't set diffuseTexture)... DO I HAVE TO EXCLUDE those meshes from light (is the normal process or am i just making up shit).



I think you saw... i was really frustrated yesterday.... Im better today... Will try again 

 

With that being said... LET TAKE UNITY OUT OF PICTURE TOTALLY...

Now just say you had a few textures and lightmap (no matter where the lightmap came from... unity, 3dsmax, maya... anything)

Now you wanna make a BabylonJS scene with NO LIGHTS... What is EVERYTHING that you need to take into account in BabylonJS to create scene with fully baked lighting...

Again... NOT just 1 or 2 lines that say "I would just use a lightmapTexture or use ambientTexture ... THAT IS OF NOW REAL USE TO ME... Its much more you to take into account ... And just saying 'use lightmapTexture' DOES NOT TELL ME ANYTHING USEFUL... I GET THAT ... USE lightmapTexture. But what ARE the properties that need to be set on NOT ONLY the lightmapTexture but anything that will be influenced by the scene... For example... Set emissiveTexture but not diffuseTexture and also set useLightmapAsShadowmap = true... Now these i gathered from searching around... Every little piece a code i see take a DIFFERENT approach and show 1 or 2 line of code for actually setting the texture on light map or diffuse... but nothing explaining the WHOLE theory of everything you would need to implement in BabylonJS to make a fully baked scene (NO UNITY... just forget UNITY and use the light map... that happen to come from unity)

Then to really cap things off...This statement from @Deltakosh has really got me confused:

This is REALLY confusing... 

IF i am using baked lighting ... I HAVE to use emissiveTexture... thats where the light comes from for that material.. is emitting its own light...

IF i want shadows... I HAVE to use lightmapTexture (or ambientTexture for shader computed shadows)

SO HOW CAN THIS STATEMENT BE TRUE... How can you EITHER use emissiveTexture OR lightmapTexture.

Again... All my confusion is on the BabylonJS side... Now since i don't see a real guide line to go by... i am just making shit up...

But i don't know if its right... And don't wanna put SHITTY code out ... Especially if that code is TOTALLY WRONG and it should NOT be done that way...

Please take a look at my last Video... As you can see i have "MacGuyver" together what I THINK should be going on... JUST get this double light effect when mixing baked and realtime... Now i don't know if the double lighting IS SUPPOSED to happen and i need to account for that by excluding baked meshes from all lights... Or if what i did was totally wrong and that is output ... BECASE IM WRONG.

My baking issues

I am trying to get a hold of @Sebavan ... I know with just 5 mins explaining what should be done in babylon js if wanna a fully baked scene... with a little realtime shadows mixed in... NOTHING TO DO WITH UNITY... 

Just make a straight hand coded babylonjs scene made for fully baked lighting.

WOW .. that was a lot again ...

Thanks @MrVR for all your excellent unity research :)

 

 

 

No problem @MackeyK24 I'm glad the research info was useful , I'm currently testing the PR along with your videos.

 I will post my comments later when I'm done going trough the features.

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...