Magnifying Shader for Particle System

Hello .I’m a beginner in unity. I’m trying to use a magnifying shader for particle system to make effect similar explosion of homescape.
I found some magnifying shader on youtube but it not run.
Can you guys tell me what i’m doing wrong in my shader? Thanks

Shader “Custom/Magnifier”
{
Properties
{
_Color(“Main Color”, Color) = (1,1,1,1)
_Intensity(“Intensity”, float) = 1
_MainTex(“Alpha (A)”, 2D) = “white” {}
_NoiseTex(“Noise Texture (RG)”, 2D) = “white” {}
_ScaleStrength(“Scale Strength”, Range(-10, 10)) = 0.2
_NosieStrength(“Noise Strength”, Range(-10, 10)) = 0.2
}
SubShader
{
Tags
{
“QUEUE” = “Transparent+1”
“RenderType” = “Transparent”
}
Pass
{
Tags
{
}
ZClip Off
ZWrite Off
Cull Off
Stencil
{
Ref 0
ReadMask 0
WriteMask 0
Pass Keep
Fail Keep
ZFail Keep
PassFront Keep
FailFront Keep
ZFailFront Keep
PassBack Keep
FailBack Keep
ZFailBack Keep
}

	} 
	Pass 
	{
	  Name "BASE"
	  Tags
	  {
		"LIGHTMODE" = "ALWAYS"
		"QUEUE" = "Transparent+1"
		"RenderType" = "Transparent"
	  }
	  ZWrite Off
	  Cull Off
	  Blend SrcAlpha OneMinusSrcAlpha

	  CGPROGRAM

#pragma vertex vert
#pragma fragment frag

#include “UnityCG.cginc”

#define CODE_BLOCK_VERTEX
uniform float4 _MainTex_ST;
uniform float4 _Color;
uniform float _ScaleStrength;
uniform float _NosieStrength;
uniform sampler2D _NoiseTex;
uniform sampler2D _MainTex;
uniform sampler2D _GrabTexture;

		  struct appdata_t {
			  float4 vertex :POSITION0;
			  float4 color :COLOR0;
			  float2 texcoord :TEXCOORD0;
			  float2 texcoord1 :TEXCOORD1;
		  };

		  struct OUT_Data_Vert
		  {
			  float4 color :COLOR0;
			  float4 texcoord :TEXCOORD0;
			  float4 texcoord1 :TEXCOORD1;
			  float4 vertex :SV_POSITION;
		  };

		  struct v2f
		  {
			  float4 color :COLOR0;
			  float4 texcoord :TEXCOORD0;
			  float4 texcoord1 :TEXCOORD1;
		  };

		  struct OUT_Data_Frag
		  {
			  float4 color :SV_Target0;
		  };

		  float4 u_xlat0;
		  float4 u_xlat1;
		  OUT_Data_Vert vert(appdata_t in_v)
		  {
			  OUT_Data_Vert out_v;
			  //UNITY_INITIALIZE_OUTPUT(OUT_Data_Vert, out_v);
			  u_xlat0 = UnityObjectToClipPos(in_v.vertex);
			  out_v.vertex = u_xlat0;
			  u_xlat0.xy = u_xlat0.xy / u_xlat0.ww;
			  out_v.texcoord.xy = (u_xlat0.xy * float2(0.5, 0.5)) + float2(0.5, 0.5);
			  u_xlat0 = in_v.color * _Color;
			  out_v.color = u_xlat0;
			  out_v.texcoord.zw = in_v.texcoord.xy;
			  out_v.texcoord1.xy = TRANSFORM_TEX(in_v.texcoord.xy, _MainTex);
			  out_v.texcoord1.z = in_v.texcoord1.x;
			  return out_v;
		  }

#define CODE_BLOCK_FRAGMENT

		  float2 u_xlat0_d;
		  float3 u_xlat10_0;
		  float u_xlat1_d;
		  float2 u_xlat2;
		  float2 u_xlat3;
		  float u_xlat10_4;
		  float u_xlat6;
		  OUT_Data_Frag frag(v2f in_f)
		  {
			  OUT_Data_Frag out_f;
			  //UNITY_INITIALIZE_OUTPUT(OUT_Data_Frag, out_f);
			  u_xlat10_0.x = tex2D(_NoiseTex, in_f.texcoord1.xy).x;
			  u_xlat0_d.x = u_xlat10_0.x * _NosieStrength;
			  u_xlat2.xy = (-in_f.texcoord.wz) + float2(0.5, 0.5);
			  u_xlat6 = dot(u_xlat2.xy, u_xlat2.xy);
			  u_xlat1_d = rsqrt(u_xlat6);
			  u_xlat6 = sqrt(u_xlat6);
			  u_xlat3.xy = float2(u_xlat6, u_xlat6) * u_xlat2.yx;
			  u_xlat2.xy = u_xlat2.xy * float2(u_xlat1_d, u_xlat1_d);
			  u_xlat0_d.xy = u_xlat0_d.xx * u_xlat2.xy;
			  u_xlat0_d.xy = u_xlat3.xy * float2(float2(_ScaleStrength, _ScaleStrength)) + u_xlat0_d.xy;
			  u_xlat10_4 = tex2D(_MainTex, in_f.texcoord1.xy).w;
			  u_xlat0_d.xy = float2(u_xlat10_4, u_xlat10_4) * u_xlat0_d.xy;
			  u_xlat0_d.xy = u_xlat0_d.xy * in_f.texcoord1.zz + in_f.texcoord.xy;
			  u_xlat10_0.xyz = tex2D(_GrabTexture, u_xlat0_d.xy).xyz;
			  out_f.color.xyz = u_xlat10_0.xyz;
			  out_f.color.w = in_f.color.w;
			  return out_f;
		  }

		  ENDCG
			  }
  }
	  FallBack Off

}

What’s the error message you’re getting?

it has not error message

what does “it not run” mean? Do you see magenta material color or another problem?

1 Like

I don’t know actually how it should work. But I tested it, I had no errors and it works.

Shader “Custom/Magnifier”
{
Properties
{
_Color(“Main Color”, Color) = (1,1,1,1)
//_Intensity(“Intensity”, float) = 1
_MainTex(“Alpha (A)”, 2D) = “white” {}
_NoiseTex(“Noise Texture (RG)”, 2D) = “white” {}
_ScaleStrength(“Scale Strength”, Range(-10, 10)) = 0.2
_NosieStrength(“Noise Strength”, Range(-10, 10)) = 0.2
}
SubShader
{
Tags
{
“QUEUE” = “Transparent+1”
“RenderType” = “Transparent”
}

    GrabPass{ }

  Pass 
  {
        Name "BASE"

        Tags
        {
            "LIGHTMODE" = "ALWAYS"
            "QUEUE" = "Transparent+1"
            "RenderType" = "Transparent"
        }

        ZWrite Off
        Cull Off
        Blend SrcAlpha OneMinusSrcAlpha

        CGPROGRAM

        #pragma vertex vert
        #pragma fragment frag

        #include "UnityCG.cginc"

        #define CODE_BLOCK_VERTEX
        uniform float4 _MainTex_ST;
        uniform float4 _Color;
        uniform float _ScaleStrength;
        uniform float _NosieStrength;
        uniform sampler2D _NoiseTex;
        uniform sampler2D _MainTex;
        uniform sampler2D _GrabTexture;

        struct appdata_t 
            {
                float4 vertex :POSITION;
                float4 color :COLOR;
                float2 texcoord :TEXCOORD0;
                float2 texcoord1 :TEXCOORD1;
            };

        struct OUT_Data_Vert
            {
                float4 color :COLOR;
                float4 texcoord :TEXCOORD0;
                float4 texcoord1 :TEXCOORD1;
                float4 vertex :SV_POSITION;
            };

        struct v2f
            {
                float4 color :COLOR;
                float4 texcoord :TEXCOORD0;
                float4 texcoord1 :TEXCOORD1;
            };

        struct OUT_Data_Frag
            {
                float4 color :SV_Target0;
            };

        float4 u_xlat0;
        float4 u_xlat1;

        OUT_Data_Vert vert(appdata_t in_v)
        {
            OUT_Data_Vert out_v;
            UNITY_INITIALIZE_OUTPUT(OUT_Data_Vert, out_v);
            u_xlat0 = UnityObjectToClipPos(in_v.vertex);
            out_v.vertex = u_xlat0;
            u_xlat0.xy = u_xlat0.xy / u_xlat0.ww;
            out_v.texcoord.xy = (u_xlat0.xy * float2(0.5, 0.5)) + float2(0.5, 0.5);
            u_xlat0 = in_v.color * _Color;
            out_v.color = u_xlat0;
            out_v.texcoord.zw = in_v.texcoord.xy;
            out_v.texcoord1.xy = TRANSFORM_TEX(in_v.texcoord.xy, _MainTex);
            out_v.texcoord1.z = in_v.texcoord1.x;
            return out_v;
        }

        #define CODE_BLOCK_FRAGMENT

        float2 u_xlat0_d;
        float3 u_xlat10_0;
        float u_xlat1_d;
        float2 u_xlat2;
        float2 u_xlat3;
        float u_xlat10_4;
        float u_xlat6;

        OUT_Data_Frag frag(v2f in_f)
        {
            OUT_Data_Frag out_f;
            UNITY_INITIALIZE_OUTPUT(OUT_Data_Frag, out_f);
            u_xlat10_0.x = tex2D(_NoiseTex, in_f.texcoord1.xy).x;
            u_xlat0_d.x = u_xlat10_0.x * _NosieStrength;
            u_xlat2.xy = (-in_f.texcoord.wz) + float2(0.5, 0.5);
            u_xlat6 = dot(u_xlat2.xy, u_xlat2.xy);
            u_xlat1_d = rsqrt(u_xlat6);
            u_xlat6 = sqrt(u_xlat6);
            u_xlat3.xy = float2(u_xlat6, u_xlat6) * u_xlat2.yx;
            u_xlat2.xy = u_xlat2.xy * float2(u_xlat1_d, u_xlat1_d);
            u_xlat0_d.xy = u_xlat0_d.xx * u_xlat2.xy;
            u_xlat0_d.xy = u_xlat3.xy * float2(float2(_ScaleStrength, _ScaleStrength)) + u_xlat0_d.xy;
            u_xlat10_4 = tex2D(_MainTex, in_f.texcoord1.xy).w;
            u_xlat0_d.xy = float2(u_xlat10_4, u_xlat10_4) * u_xlat0_d.xy;
            u_xlat0_d.xy = u_xlat0_d.xy * in_f.texcoord1.zz + in_f.texcoord.xy;
            u_xlat10_0.xyz = tex2D(_GrabTexture, u_xlat0_d.xy).xyz;
            out_f.color.xyz = u_xlat10_0.xyz;
            out_f.color.w = in_f.color.w;
            return out_f;
        }
  ENDCG
  }
}

}

1 Like

I want it to be like homescape’s explosion.


And I found out that creating a magnifier shader will create such an effect. So I found a magnifier shader but don’t know how to see it in action.
here’s my particle with this magnifier shader

use this) and make sure you use texture with alpha channel as alpha (a)

Shader “Custom/Magnifier”
{
Properties
{
_Color(“Main Color”, Color) = (1,1,1,1)
//_Intensity(“Intensity”, float) = 1
_MainTex(“Alpha (A)”, 2D) = “white” {}
_NoiseTex(“Noise Texture (RG)”, 2D) = “white” {}
_ScaleStrength(“Scale Strength”, Range(-10, 10)) = 0.2
_NosieStrength(“Noise Strength”, Range(-10, 10)) = 0.2
}
SubShader
{
Tags
{
“QUEUE” = “Transparent+1”
“RenderType” = “Transparent”
}

    GrabPass{ }

  Pass 
  {
        Name "BASE"

        Tags
        {
            "LIGHTMODE" = "ALWAYS"
            "QUEUE" = "Transparent+1"
            "RenderType" = "Transparent"
        }

        ZWrite Off
        Cull Off
        Blend SrcAlpha OneMinusSrcAlpha

        CGPROGRAM

        #pragma vertex vert
        #pragma fragment frag

        #include "UnityCG.cginc"

        #define CODE_BLOCK_VERTEX
        uniform float4 _MainTex_ST;
        uniform float4 _Color;
        uniform float _ScaleStrength;
        uniform float _NosieStrength;
        uniform sampler2D _NoiseTex;
        uniform sampler2D _MainTex;
        uniform sampler2D _GrabTexture;

        struct appdata_t 
            {
                float4 vertex :POSITION;
                float4 color :COLOR;
                float2 texcoord :TEXCOORD0;
                float2 texcoord1 :TEXCOORD1;
            };

        struct OUT_Data_Vert
            {
                float4 color :COLOR;
                float4 texcoord :TEXCOORD0;
                float4 texcoord1 :TEXCOORD1;
                float4 vertex :SV_POSITION;
            };

        struct v2f
            {
                float4 color :COLOR;
                float4 texcoord :TEXCOORD0;
                float4 texcoord1 :TEXCOORD1;
            };

        struct OUT_Data_Frag
            {
                float4 color :SV_Target0;
            };

        float4 u_xlat0;
        float4 u_xlat1;

        OUT_Data_Vert vert(appdata_t in_v)
        {
            OUT_Data_Vert out_v;
            UNITY_INITIALIZE_OUTPUT(OUT_Data_Vert, out_v);
            u_xlat0 = UnityObjectToClipPos(in_v.vertex);
            out_v.vertex = u_xlat0;
            u_xlat0.xy = u_xlat0.xy / u_xlat0.ww;
            out_v.texcoord.xy = (u_xlat0.xy * float2(0.5, 0.5)) + float2(0.5, 0.5);
            u_xlat0 = in_v.color * _Color;
            out_v.color = u_xlat0;
            out_v.texcoord.zw = in_v.texcoord.xy;
            out_v.texcoord1.xy = TRANSFORM_TEX(in_v.texcoord.xy, _MainTex);
            out_v.texcoord1.z = in_v.texcoord1.x;
            return out_v;
        }

        #define CODE_BLOCK_FRAGMENT

        float2 u_xlat0_d;
        float3 u_xlat10_0;
        float u_xlat1_d;
        float2 u_xlat2;
        float2 u_xlat3;
        float u_xlat10_4;
        float u_xlat6;

        OUT_Data_Frag frag(v2f in_f)
        {
            OUT_Data_Frag out_f;
            UNITY_INITIALIZE_OUTPUT(OUT_Data_Frag, out_f);
            u_xlat10_0.x = tex2D(_NoiseTex, in_f.texcoord1.xy).x;
            u_xlat0_d.x = u_xlat10_0.x * _NosieStrength;
            u_xlat2.xy = (-in_f.texcoord.wz) + float2(0.5, 0.5);
            u_xlat6 = dot(u_xlat2.xy, u_xlat2.xy);
            u_xlat1_d = rsqrt(u_xlat6);
            u_xlat6 = sqrt(u_xlat6);
            u_xlat3.xy = float2(u_xlat6, u_xlat6) * u_xlat2.yx;
            u_xlat2.xy = u_xlat2.xy * float2(u_xlat1_d, u_xlat1_d);
            u_xlat0_d.xy = u_xlat0_d.xx * u_xlat2.xy;
            u_xlat0_d.xy = u_xlat3.xy * float2(float2(_ScaleStrength, _ScaleStrength)) + u_xlat0_d.xy;
            u_xlat10_4 = tex2D(_MainTex, in_f.texcoord1.xy).w;
            u_xlat0_d.xy = float2(u_xlat10_4, u_xlat10_4) * u_xlat0_d.xy;
            u_xlat0_d.xy = u_xlat0_d.xy * in_f.texcoord1.zz + in_f.texcoord.xy;
            u_xlat10_0.xyz = tex2D(_GrabTexture, u_xlat0_d.xy).xyz;
            out_f.color.xyz = u_xlat10_0.xyz;
            out_f.color.w = in_f.color.w * u_xlat10_4;
            return out_f;
        }
  ENDCG
  }
}

}

1 Like

point_1 use this texture

1 Like

Thank you so much. It worked <3

1 Like

Here’s my particle if anyone need
https://drive.google.com/file/d/1aX85B6sPt5ijcz5MinFSvFn3NTo9NWhx/view?usp=sharing

I have a question. Why is the background image inverted when looking through the particle?

While I do not know what is the reason. I need time to figure it out)

1 Like