ghiboz
1
hi all! I set soft particles in the settings:

and in my standard surface shader, just to test, I added this:
void surf (Input IN, inout SurfaceOutputStandardSpecular o)
{
float test = 0.0f;
#ifdef SOFTPARTICLES_ON
test = 1.0f;
#endif
o.Albedo.r = test;
but my shader looks like this:


any suggestions?
thanks!
bgolus
2
You also need the following line to inform the shader compiler to use the soft particles:
#pragma multi_compile_particles
1 Like
ghiboz
3
thanks @bgolus !
my shader uses it…
SubShader {
Tags { "Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="Transparent" }
LOD 200 //Cull Off //Lighting Off //ZWrite On
ZTest LEqual
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM // Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf StandardSpecular vertex:vert alpha:fade //fullforwardshadows addshadow
#pragma multi_compile_particles
#pragma multi_compile_fog
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
#include "UnityCG.cginc"
I noticed a bug when you try to use #pragma multi_compile_particles in a surface shader. the keyword doesn’t get activated.
I used #pragma multi_compile _ SOFTPARTICLES_ON instead and it worked for me.
2 Likes
ghiboz
5
thanks @Phantom_X , seems that detects now, but the result is not as ‘soft’ as I expect…
could you help me? this is my particle shader:
Shader "gRally/Smoke v1"
{
Properties
{
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_InvFade("Soft Particles Factor", Range(0.01,3.0)) = 1.0
_BumpMap ("Bumpmap", 2D) = "bump" {}
_BumpScale ("Bump Scale", Float) = 1
_Smoothness("Smoothness", Range(0,1)) = 0.5
_Specular("Specular", Range(0,1)) = 0.0
_Opacity("Opacity", Range(0,1)) = 1.0
}
SubShader
{
Tags { "Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="Transparent" }
LOD 200
ZTest LEqual
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma surface surf StandardSpecular vertex:vert alpha:fade
#pragma multi_compile _ SOFTPARTICLES_ON
#pragma multi_compile_fog
#pragma target 3.0
#include "UnityCG.cginc"
sampler2D _MainTex;
sampler2D _BumpMap;
float _BumpScale;
float _Opacity;
float _InvFade;
sampler2D_float _CameraDepthTexture;
struct Input
{
float4 color : COLOR;
float2 uv_MainTex;
float2 uv_BumpMap;
UNITY_FOG_COORDS(1)
float2 texcoord : TEXCOORD0;
#ifdef SOFTPARTICLES_ON
float4 projPos : TEXCOORD2;
#endif
};
half _Smoothness;
half _Specular;
fixed4 _Color;
void vert(inout appdata_full v, out Input o)
{
//set custom value
o.uv_MainTex = v.texcoord;
o.color = v.color;
o.uv_BumpMap = v.texcoord;
o.texcoord = v.texcoord;
#ifdef SOFTPARTICLES_ON
float4 hpos = mul(UNITY_MATRIX_MVP, v.vertex);
o.projPos = ComputeGrabScreenPos(hpos);
#endif
}
void surf (Input IN, inout SurfaceOutputStandardSpecular o)
{
#ifdef SOFTPARTICLES_ON
float sceneZ = LinearEyeDepth(SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(IN.projPos)));
float partZ = IN.projPos.z;
float fade = saturate(_InvFade * (sceneZ - partZ));
IN.color.a *= fade;
#endif
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color * IN.color;
o.Albedo = c.rgb * IN.color.rgb;
o.Normal = UnpackScaleNormal (tex2D (_BumpMap, IN.uv_BumpMap),_BumpScale);
o.Specular = _Specular;
o.Smoothness = _Smoothness;
o.Alpha = c.a * IN.color.a * _Opacity;
UNITY_APPLY_FOG(IN.fogCoord, c);
}
ENDCG
}
}