Baking light increasing the batches in my scene - performance

I am new with light baking and trying to bake my scene in order to increase performance and graphics mainly targeting mobile devices.
The issue is that before baking my scene total batches were 100 , but after baking my scene batches increase to like 400 - 500. Also I would like to reduce the size which i have achieved somehow with playing with settings. Am I doing something wrong with settings?
see my settings here

If I were you I would remove the static option of the terrain. This will increase your performance significantly.

Related

Unity Rigidbody angular speed

I'm working on a phisics based game and I have a question
Is it possible to make almost real phisics inside Unity engine??
Because when I put a rolling sphere at top of a ramp and let it roll... it moves very slow... and when I do it in real life... obviously the ball rolls with certain speed depending on the angle of the ramp... less angle = less speed... more angle = more speed
I tried:
Removing drag
Removing angular drag
Changing the values in interpolate and collision detection
Changing the mass value
Any help will be apreciated
Thanks in advance
Be sure to check the scale of your objects, it is very easy to set up a scene at the wrong scale because there's no easy frame of reference!
Unity's units map to 1 meter, so if your objects are extremely large, they will appear to move more slowly because the physics engine is set up to respect this scale by default.
A marble should have a diameter of roughly 0.025 units, and a person should be around 1.7 units tall!
I think your error is the scale objects. I found this link that may can help you: http://gamedevelopment.tutsplus.com/articles/how-to-fix-common-physics-problems-in-your-game--cms-21418

How to handle many light sources on the scene?

I have a map definition with plenty of light sources (about 350). When I'm trying to create THREE.PointLight objects and add them to the scene, I'm getting the following error along with low FPS:
three.js:29438 THREE.WebGLProgram: shader error: 0 gl.VALIDATE_STATUS false gl.getProgramInfoLog Fragment shader active uniforms exceed MAX_FRAGMENT_UNIFORM_VECTORS (1024).
What does it mean? Is there some limit of THREE.PointLight objects on the scene? Are there any good practices to keep high performance when you have many light sources?
For now the only idea that comes to mind is somehow reduce the number of light sources and leaving only those that I really need.
This error means you've exceeded the maximum number of uniforms in your fragment shader. This limit is determined by your graphics card and/or driver. You can check by going to http://webglreport.com/.
Looks like on your system the limit is 1024. A Three.js light typically uses 6-10 uniforms depending on the type of light and the material. Given you're using ~350 lights, it makes sense that you're blowing way past this limit.
Generally speaking, 350 discrete lights is a lot, probably way more than you need. Using more lights is also computationally intensive. A typical WebGL scene has no more than a handful. You might want to consider other techniques to achieve what you want.

Which is the best way to render large number of geometries in three js?

Initially when I start my three.js based application there are very few cubes (less than 50) and they are rendered withing no time. But as number of cubes increase the rendering time increases.
When I reach 150 cubes with each having texture on all six sides.
It takes long time (3 to 5 minutes) to render the scene.
Once the scene is rendered I want to add/remove individual cubes, without rendering the whole scene again.
I have gone through similar question here.
But using this technique has following disadvantage:
It won’t be possible to move the merged objects independently from each other. Or you can no more remove or add a object without recomputing the whole geometry.
How do I solve this issue ?
Note : I am using WebGL Renderer
This seems to work well, no?
http://threejs.org/examples/webgl_interactive_draggablecubes.html
Code seemed sane too, has the cubes as separate objects. Though perhaps you mean that need more..
I edited the example to do 1000 cubes for me now, am getting 40fps on this laptop with intel hd 4000 -- not bad I'd say!

WebGL scene does't render because of lost context

I have a 3d model of a road with textures and without.
When I load road without textures everything works fine ~ 60fps. But when I load road with textures there are 2 variants:
1) If 3D model is not big then it loads and works but with very low fps ~ 10-20
2) If 3D model is big it loads without any errors and warnings but after that I get this error:
WebGL: CONTEXT_LOST_WEBGL: loseContext: context lost
THREE.WebGLShader: gl.getShaderInfoLog() null
This error here:
animate = function() {
renderer.render(scene, camera); <--- error occurs here
stats.update();
controls.update(clock.getDelta());
return requestAnimationFrame(animate);
};
I've read that this error means: 'browser or the OS decides to reset the GPU to get control back' but how can I solve this problem?
1. The reason
It's exactly happening what you already said.
Your browser is hanging while rendering the WebGL scene and loses its context because the browser has effectively lost control on your GPU.
Either you have a huge memory leak in your application or your machine does not have enough power to run your texturized model on a WebGL scene. Squeezing too much by trying to render a heavy object with a really big texture resolution, can lead to a context loss.
2. Diagnosis
If 3D model is not big then it loads and works but with very low fps ~ 10-20
makes me think your machine actually can't handle 3D on a browser very well.
3. Troubleshooting
The first advice is to decrease the resolution of your scene, you can do this halving by 2 or 3 the setSize of your renderer object.
For performance intensive games, you can also give setSize smaller values, like window.innerWidth/2 and window.innerHeight/2, for half the resolution. This does not mean that the game will only fill half the window, but rather look a bit blurry and scaled up.
This means you need to add this to your renderer:
renderer.setSize( window.innerWidth/2, window.innerHeight/2 );
Also tweaking the far distance rendering of your camera helps to gain some performance too. Generally those are the most used values: new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );, if you bring down the far to 800 or 700 you can squeeze extra FPS from your scene (at the price of rendering distance, of course.)
If your application after these tweaks then start running fine then you're actually facing resource-starving problems, which means your computer is not fit to run WebGL or you have a huge memory leak
You can also test your application on another, better computer and see how it performs and how smooth it runs.
If your computer is cutting edge high-end monster gaming machine then the only thing I can suggest you is to start also looking at the resolution of your texture and scale it a bit down.
I'll leave also this link: WebGL - HandlingContextLost (probably you have already seen this), which provides some troubleshooting and ways to recover a crashed instance of WebGL.
4. Solution (to this specific answer)
After a quick chat with Eugene, the problem at the root of his project was Ram usage, his 3D model wasted a lot of Ram that Chrome was taking up to 1.6GB.
The blue bumps are when his WebGL app is running.
After flagging this to him he came back with his solution:
I’ve solved my problem. I’ve concatenated roads to one file and changed renderer size

setTexture in three.js performance issues

When I am changing the texture of my mesh, on some computers, the application freeze for like half a second. I do that on 100 different mesh. On the Chrome profiler I see that the Three.js method setTexture is on top of the CPU usage.
The method I use to apply the next texture is the simplest:
this.materials.map = this.nextTexture;
This is working but I have no idea how to optimize this.
If use a particle system instead, would it improve something?
Thanks a lot
Are you really using 100 different textures?
Try sorting your objects according to texture, to minimize texture swapping.
Texture-change is one of the more expensive GPU operations.

Resources