- Home /
Particles not showing up using render texture
I have an object with particles shooting out the sides of it. It renders perfectly fine in the camera that it has attached to it. Previously I was doing a camera overlay onto my main camera to get this object to render but I switched it to a render texture. The object itself looks fine but you can't see the particles once they escape the bounds of the object. It's like nothing is being rendered outside of the main object itself. Anybody know why this is happening? I tried changing the clear flags, the clipping planes, the culling mask, etc on the camera but nothing worked. I added textures to the particles and they still aren't being shown.
Thanks!
Answer by nerdjnerdbird · Oct 22, 2013 at 05:25 PM
So, it looks like it comes down to the shader I'm using. Most of the shaders don't show anything because the particles don't have anything behind them. Particles-> Alpha Blending shader shows nothing... BUT Mobile->Particles->Alpha Blending works for some strange reason. You can see the particles with the correct shader!
I found that the normal Particles shader has "Color$$anonymous$$ask RGB", while the mobile one doesn't. Removing that allows you to use it with a RenderTexture. The only side effect I've seen is alpha gets slightly greyer when your RenderTexture includes the skybox, but it's so small it's worth it. Otherwise it works flawlessly.
To save someone the trouble, here's the Particles/Alpha Blended shader with that line removed. You can use it under "Particles/Alpha Blended RenderTexture"
Shader "Particles/Alpha Blended RenderTexture" {
Properties {
_TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5)
_$$anonymous$$ainTex ("Particle Texture", 2D) = "white" {}
_InvFade ("Soft Particles Factor", Range(0.01,3.0)) = 1.0
}
Category {
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" }
Blend SrcAlpha One$$anonymous$$inusSrcAlpha
Cull Off Lighting Off ZWrite Off
SubShader {
Pass {
CGPROGRA$$anonymous$$
#pragma vertex vert
#pragma fragment frag
#pragma target 2.0
#pragma multi_compile_particles
#pragma multi_compile_fog
#include "UnityCG.cginc"
sampler2D _$$anonymous$$ainTex;
fixed4 _TintColor;
struct appdata_t {
float4 vertex : POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
};
struct v2f {
float4 vertex : SV_POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
UNITY_FOG_COORDS(1)
#ifdef SOFTPARTICLES_ON
float4 projPos : TEXCOORD2;
#endif
};
float4 _$$anonymous$$ainTex_ST;
v2f vert (appdata_t v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
#ifdef SOFTPARTICLES_ON
o.projPos = ComputeScreenPos (o.vertex);
CO$$anonymous$$PUTE_EYEDEPTH(o.projPos.z);
#endif
o.color = v.color;
o.texcoord = TRANSFOR$$anonymous$$_TEX(v.texcoord,_$$anonymous$$ainTex);
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
sampler2D_float _CameraDepthTexture;
float _InvFade;
fixed4 frag (v2f i) : SV_Target
{
#ifdef SOFTPARTICLES_ON
float sceneZ = LinearEyeDepth (SA$$anonymous$$PLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos)));
float partZ = i.projPos.z;
float fade = saturate (_InvFade * (sceneZ-partZ));
i.color.a *= fade;
#endif
fixed4 col = 2.0f * i.color * _TintColor * tex2D(_$$anonymous$$ainTex, i.texcoord);
UNITY_APPLY_FOG(i.fogCoord, col);
return col;
}
ENDCG
}
}
}
}
@nerdjnerdbird You are damn genius... The shader u specified "Mobile->Particles->Alpha Blending" works exacyly like Magic wand.It made the Impossible to Possible. Thank you very much for the solution, you rock.
Answer by Rickshao · Jul 13, 2017 at 06:34 AM
Default partilce shaders use ColorMask RGB so alpha value will not be wrote to cache. When renderring to render texture, it gets the color (r, g, b , a) where the value a is 0, as texture uses alpha premultiplied to store color infomation, the color you get become (r*a, g*a, b*a, a) ——(0, 0, 0, 0) then color you eventually get.
Just remove "ColorMask RGB" or replace it with "ColorMask RGBA", you will get the correct picture.
Answer by kwea123 · Nov 07, 2021 at 09:39 PM
for URP, I found it can be solved using URP/Unlit with Render Face: Both ,for URP, I found it can be solved using URP/Unlit with Render Face: Both
Your answer
Follow this Question
Related Questions
Render particle system to texture. 0 Answers
How to remove camera background from render texutre? 0 Answers
Sub emitter lighting problems 1 Answer
Particles effect in a progress bar 1 Answer