Using the ShaderForge plugin I have created a simple bubble shader. Within the bubble shader 2 “Scene Color” nodes are used in the emission variable. I have noticed that using the Scene Color nodes causes batching to break, which is very unfortunate because I need to have 100-200 bubbles per scene. I was able to reproduce a very simple shader that does this as well, what it seems like is that with using Scene Color it calls GrabPass, and that itself is what is causing batching to break. Anyone have any ideas as to why GrabPass would break batching since all the bubbles are using the same grab pass?
Simple shader that breaks batching
// Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
// Shader created with Shader Forge v1.28
// Shader Forge (c) Neat Corporation / Joachim Holmer - http://www.acegikmo.com/shaderforge/
// Note: Manually altering this data may prevent you from opening it in Shader Forge
/*SF_DATA;ver:1.28;sub:START;pass:START;ps:flbk:,iptp:0,cusa:False,bamd:0,lico:1,lgpr:1,limd:1,spmd:1,trmd:0,grmd:0,uamb:True,mssp:True,bkdf:False,hqlp:False,rprd:False,enco:False,rmgx:True,rpth:0,vtps:0,hqsc:True,nrmq:1,nrsp:0,vomd:0,spxs:False,tesm:0,olmd:1,culm:0,bsrc:0,bdst:1,dpts:2,wrdp:False,dith:0,rfrpo:False,rfrpn:Refraction,coma:15,ufog:True,aust:True,igpj:True,qofs:0,qpre:3,rntp:2,fgom:False,fgoc:False,fgod:False,fgor:False,fgmd:0,fgcr:0.5,fgcg:0.5,fgcb:0.5,fgca:1,fgde:0.01,fgrn:0,fgrf:300,stcl:False,stva:128,stmr:255,stmw:255,stcp:6,stps:0,stfa:0,stfz:0,ofsf:0,ofsu:0,f2p0:False,fnsp:False,fnfb:False;n:type:ShaderForge.SFN_Final,id:4013,x:32719,y:32712,varname:node_4013,prsc:2|diff-1304-RGB,emission-9191-OUT;n:type:ShaderForge.SFN_Color,id:1304,x:32443,y:32712,ptovrint:False,ptlb:Color,ptin:_Color,varname:node_1304,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,c1:1,c2:1,c3:1,c4:1;n:type:ShaderForge.SFN_SceneColor,id:9546,x:31929,y:32675,varname:node_9546,prsc:2;n:type:ShaderForge.SFN_SceneColor,id:5356,x:31929,y:32893,varname:node_5356,prsc:2;n:type:ShaderForge.SFN_Vector1,id:3316,x:31945,y:33061,varname:node_3316,prsc:2,v1:0.3;n:type:ShaderForge.SFN_Lerp,id:9191,x:32390,y:32902,varname:node_9191,prsc:2|A-9546-RGB,B-5356-RGB,T-3316-OUT;n:type:ShaderForge.SFN_Color,id:3921,x:32041,y:32527,ptovrint:False,ptlb:node_3921,ptin:_node_3921,varname:node_3921,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,c1:0.5,c2:0.5,c3:0.5,c4:1;n:type:ShaderForge.SFN_Color,id:3044,x:32225,y:32547,ptovrint:False,ptlb:node_3921_copy,ptin:_node_3921_copy,varname:_node_3921_copy,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,c1:0.5,c2:0.5,c3:0.5,c4:1;proporder:1304-3921-3044;pass:END;sub:END;*/
Shader "Shader Forge/testingbubble2" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_node_3921 ("node_3921", Color) = (0.5,0.5,0.5,1)
_node_3921_copy ("node_3921_copy", Color) = (0.5,0.5,0.5,1)
}
SubShader {
Tags {
"IgnoreProjector"="True"
"Queue"="Transparent"
"RenderType"="Transparent"
}
GrabPass{ "Refraction" }
Pass {
Name "FORWARD"
Tags {
"LightMode"="ForwardBase"
}
ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#define UNITY_PASS_FORWARDBASE
#include "UnityCG.cginc"
#pragma multi_compile_fwdbase
#pragma multi_compile_fog
#pragma exclude_renderers gles3 metal d3d11_9x xbox360 xboxone ps3 ps4 psp2
#pragma target 3.0
uniform float4 _LightColor0;
uniform sampler2D Refraction;
uniform float4 _Color;
struct VertexInput {
float4 vertex : POSITION;
float3 normal : NORMAL;
};
struct VertexOutput {
float4 pos : SV_POSITION;
float4 posWorld : TEXCOORD0;
float3 normalDir : TEXCOORD1;
float4 screenPos : TEXCOORD2;
UNITY_FOG_COORDS(3)
};
VertexOutput vert (VertexInput v) {
VertexOutput o = (VertexOutput)0;
o.normalDir = UnityObjectToWorldNormal(v.normal);
o.posWorld = mul(unity_ObjectToWorld, v.vertex);
float3 lightColor = _LightColor0.rgb;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex );
UNITY_TRANSFER_FOG(o,o.pos);
o.screenPos = o.pos;
return o;
}
float4 frag(VertexOutput i) : COLOR {
#if UNITY_UV_STARTS_AT_TOP
float grabSign = -_ProjectionParams.x;
#else
float grabSign = _ProjectionParams.x;
#endif
i.normalDir = normalize(i.normalDir);
i.screenPos = float4( i.screenPos.xy / i.screenPos.w, 0, 0 );
i.screenPos.y *= _ProjectionParams.x;
float3 normalDirection = i.normalDir;
float2 sceneUVs = float2(1,grabSign)*i.screenPos.xy*0.5+0.5;
float4 sceneColor = tex2D(Refraction, sceneUVs);
float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz);
float3 lightColor = _LightColor0.rgb;
////// Lighting:
float attenuation = 1;
float3 attenColor = attenuation * _LightColor0.xyz;
/////// Diffuse:
float NdotL = max(0.0,dot( normalDirection, lightDirection ));
float3 directDiffuse = max( 0.0, NdotL) * attenColor;
float3 indirectDiffuse = float3(0,0,0);
indirectDiffuse += UNITY_LIGHTMODEL_AMBIENT.rgb; // Ambient Light
float3 diffuseColor = _Color.rgb;
float3 diffuse = (directDiffuse + indirectDiffuse) * diffuseColor;
////// Emissive:
float3 emissive = lerp(sceneColor.rgb,sceneColor.rgb,0.3);
/// Final Color:
float3 finalColor = diffuse + emissive;
fixed4 finalRGBA = fixed4(finalColor,1);
UNITY_APPLY_FOG(i.fogCoord, finalRGBA);
return finalRGBA;
}
ENDCG
}
Pass {
Name "FORWARD_DELTA"
Tags {
"LightMode"="ForwardAdd"
}
Blend One One
ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#define UNITY_PASS_FORWARDADD
#include "UnityCG.cginc"
#include "AutoLight.cginc"
#pragma multi_compile_fwdadd
#pragma multi_compile_fog
#pragma exclude_renderers gles3 metal d3d11_9x xbox360 xboxone ps3 ps4 psp2
#pragma target 3.0
uniform float4 _LightColor0;
uniform sampler2D Refraction;
uniform float4 _Color;
struct VertexInput {
float4 vertex : POSITION;
float3 normal : NORMAL;
};
struct VertexOutput {
float4 pos : SV_POSITION;
float4 posWorld : TEXCOORD0;
float3 normalDir : TEXCOORD1;
float4 screenPos : TEXCOORD2;
LIGHTING_COORDS(3,4)
UNITY_FOG_COORDS(5)
};
VertexOutput vert (VertexInput v) {
VertexOutput o = (VertexOutput)0;
o.normalDir = UnityObjectToWorldNormal(v.normal);
o.posWorld = mul(unity_ObjectToWorld, v.vertex);
float3 lightColor = _LightColor0.rgb;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex );
UNITY_TRANSFER_FOG(o,o.pos);
o.screenPos = o.pos;
TRANSFER_VERTEX_TO_FRAGMENT(o)
return o;
}
float4 frag(VertexOutput i) : COLOR {
#if UNITY_UV_STARTS_AT_TOP
float grabSign = -_ProjectionParams.x;
#else
float grabSign = _ProjectionParams.x;
#endif
i.normalDir = normalize(i.normalDir);
i.screenPos = float4( i.screenPos.xy / i.screenPos.w, 0, 0 );
i.screenPos.y *= _ProjectionParams.x;
float3 normalDirection = i.normalDir;
float2 sceneUVs = float2(1,grabSign)*i.screenPos.xy*0.5+0.5;
float4 sceneColor = tex2D(Refraction, sceneUVs);
float3 lightDirection = normalize(lerp(_WorldSpaceLightPos0.xyz, _WorldSpaceLightPos0.xyz - i.posWorld.xyz,_WorldSpaceLightPos0.w));
float3 lightColor = _LightColor0.rgb;
////// Lighting:
float attenuation = LIGHT_ATTENUATION(i);
float3 attenColor = attenuation * _LightColor0.xyz;
/////// Diffuse:
float NdotL = max(0.0,dot( normalDirection, lightDirection ));
float3 directDiffuse = max( 0.0, NdotL) * attenColor;
float3 diffuseColor = _Color.rgb;
float3 diffuse = directDiffuse * diffuseColor;
/// Final Color:
float3 finalColor = diffuse;
fixed4 finalRGBA = fixed4(finalColor * 1,0);
UNITY_APPLY_FOG(i.fogCoord, finalRGBA);
return finalRGBA;
}
ENDCG
}
}
FallBack "Diffuse"
CustomEditor "ShaderForgeMaterialInspector"
}