Search Unity

Static batching wouldn't kick in

Discussion in 'General Graphics' started by whitexroft, Dec 1, 2019.

  1. whitexroft

    whitexroft

    Joined:
    Oct 22, 2012
    Posts:
    48
    Apologies for bringing the ancient topic up, but over the years i cant yet figure out what supposed to be straightforward. Extra apologies for the duplicate topic that I made in a wrong section.

    Assuming i have a bunch of simple geometries and a forward (or vertex lit) camera.
    The geometries are static and have the same one-pass material, with only emission color. Some of them do however hold 2 material ids.
    Besides geometries there is a collection of spot lights, that are causing the headache. The spotlights are needed for the main renderer, which is in Deferred mode. The problematic camera is a reflection camera, where I am re-rendering all the geometries with simple replacement shader.

    The issue is that I cannot get it batched on the reflection camera. It is either "Objects are affected by different forward lights.", or pitch black screen. Ideally, I would rather have the reflection camera rendered in Deferred as well, but it happens to be impossible due to the custom projection, that drops the renderer into forward mode. In forward, obviously, I cant batch due to the spot lights.But only because the reflection effect is very subtle, I thought only emission, without any lighting, would be sufficient. And everything batched of course.

    So I tried the following cases:

    These cause "Objects are affected by different forward lights."
    (forward or vertex lit camera) + LightMode = "ForwardBase"
    (forward or vertex lit camera) + LightMode = "Always" (or not mentioned)
    (forward or vertex lit camera) + fixed shader with "Lighting off"

    This cause black screen:
    (forward or vertex lit camera) + LightMode = "Vertex"

    The shader Im trying to replace with is this (nothing in it):
    Code (CSharp):
    1.      
    2.             Pass
    3.             {
    4.                 CGPROGRAM
    5.                 #pragma vertex vert
    6.                 #pragma fragment frag
    7.  
    8.                 half4 _BaseColor;
    9.                 half4 _EmissionColor;
    10.        
    11.                 float4 vert(float4 vertex : POSITION) : SV_POSITION
    12.                 {
    13.                     return UnityObjectToClipPos(vertex);
    14.                 }
    15.        
    16.                 fixed4 frag(float4 vertex : SV_POSITION) : SV_Target
    17.                 {
    18.                     return _BaseColor +_EmissionColor;
    19.                 }
    20.                 ENDCG
    21.             }
    22.  
    Any help will be appreciated
     
    Last edited: Dec 2, 2019