Feb
23
2014

Explosion Effect (shader)

explosion_shader_effect_unity

Testing some big explosion effect with shader. Still missing most particle effects..

Info:
– Vertex extrusion using noise texture & timer/distance..
– Explosion cloud + shockwave is from particle system

Webplayer:
http://unitycoder.com/upload/demos/ExplosionEffectShader/

Reference:
Armageddon (explosions) video : http://youtu.be/Tq4o-B5vWYk?t=2m25s

Shader source:


Shader "unitycoder/GroundExplo"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}

_Color ("Color", Color) = (1,1,1,1)

_ExtrudeTex ("Extrusion Texture", 2D) = "white" {}
_Amount ("Extrusion Multiplier", Range(0,5)) = 0
_Pos ("Pos", Vector) = (0,0,0,0)
}

SubShader
{
//    Pass {
//        Cull Off
//        ZWrite On
//        ZTest Always

Tags { "RenderType" = "Opaque" "Queue" = "Geometry" }
CGPROGRAM
#pragma target 3.0
#pragma surface surf Lambert vertex:vert
#include "UnityCG.cginc"


struct Input {
float2 vpos;
float2 uv_MainTex;
};


float4 _Color;
float4 _Pos;
float _Amount;
sampler2D _ExtrudeTex;
float4  _ExtrudeTex_ST;

void vert (inout appdata_full v, out Input o)
{

float t = _Time.y*2;

#if !defined(SHADER_API_OPENGL)
float tex = tex2Dlod(_ExtrudeTex, float4(float2(v.texcoord.x,v.texcoord.y),0.0,0.0)).r;
float3 worldPos = mul (_Object2World, v.vertex).xyz;
float dist = distance(worldPos,_Pos.xyz);
float3 dir = -normalize(_Pos.xyz-worldPos)*0.25f;


if (t>dist)
{
float3 extrude = (v.normal+dir)*tex.r* sqrt(_Amount * (t-dist));
v.vertex.xyz += extrude;
}

o.vpos = v.vertex.xy;

#endif
}

sampler2D _MainTex;


void surf (Input IN, inout SurfaceOutput o)
{
half4 tex1 = tex2D (_MainTex, IN.uv_MainTex);
half4 tex2 = tex2D (_MainTex, IN.uv_MainTex*5-_Time.yy*0.5f)+_Color;
half4 col = lerp(tex1,tex2,IN.vpos.y);
o.Albedo = col;//*(1-_Color*IN.vpos.y);
}

ENDCG
}
Fallback "Diffuse"
}

 


5 Comments + Add Comment

Leave a comment

Connect

Twitter View LinkedIn profile Youtube Github Join Discord Twitch Instagram BlueSky

UnityLauncherPro

Get UnityLauncherPRO and work faster with Unity Projects!
*free unity hub alternative

@unitycoder_com

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.