Dec
14
2011

Plasma shader testing.. (v2)

Testing some shaders. Trying to convert a plasma GLSL shader to unity.. not working properly yet.
(and still looking for a good shader tutorial for beginner..: / )

The main code should be under fragment shader I guess..(?)
The original GLSL shader doesnt give any error in Unity, but I guess you cannot view those shaders in editor?
(it says: no subshaders can run on this graphics card..)

Shader "mShaders/mplasma2"
{
Properties
{
_Anim("Time", Float) = 0
_ResX("ResX", Float) = 32
_ResY("ResY", Float) = 32
}
SubShader
{
Tags {Queue = Geometry}
//        Cull Off

Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag

#include "UnityCG.cginc"

uniform float _ResX;
uniform float _ResY;
uniform float _Anim;

struct v2f {
float4 pos : POSITION;
float4 color : COLOR0;
float4 fragPos : COLOR1;
};

v2f vert (appdata_base v)
{
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.fragPos = o.pos;

// main code: ***original shader by: 'Plasma' by Viktor Korsun (2011)
float x = o.pos.x;
float y = o.pos.y;
float mov0 = x+y+cos(sin(_Anim)*2.)*100.+sin(x/100.)*1000.;
float mov1 = y / _ResX / 0.2 + _Anim;
float mov2 = x / _ResY / 0.2;
float c1 = abs(sin(mov1+_Anim)/2.+mov2/2.-mov1-mov2+_Anim);
float c2 = abs(sin(c1+sin(mov0/1000.+_Anim)+sin(y/40.+_Anim)+sin((x+y)/100.)*3.));
float c3 = abs(sin(c2+cos(mov1+mov2+c2)+cos(mov2)+sin(x/1000.)));

o.color = float4 (c1, c2, c3, 0.5);
return o;
}

half4 frag (v2f i) : COLOR
{
float4 outColor = i.color;
outColor.a = float4(1,1,1,1);
return outColor;
}
ENDCG

}
}
FallBack "VertexLit"
}

*UPDATE#1
Now I got the main code as pixel shader,
much better, but still not same as original..

Had to add line “#pragma target 3.0”,
without it you get error “Instruction limit .. exceeded; .. instructions needed to compile program”

Shader "mShaders/mplasma3"
{
Properties
{
_Anim("Time", Float) = 0
_ResX("_ResX", Float) = 128
_ResY("_ResY", Float) = 128
}
SubShader
{
Tags {Queue = Geometry}
Pass
{
CGPROGRAM
#pragma target 3.0
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"

uniform float _ResX;
uniform float _ResY;
uniform float _Anim;

struct v2f {
float4 pos : POSITION;
float4 color : COLOR0;
float4 fragPos : COLOR1;
};

v2f vert (appdata_base v)
{
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.fragPos = o.pos;
o.color = float4 (1.0, 1.0, 1.0, 1);
return o;
}

half4 frag (v2f i) : COLOR
{
float4 outColor = i.color;
// main code, *original shader by: 'Plasma' by Viktor Korsun (2011)
float x = i.fragPos.x;
float y = i.fragPos.z;
float mov0 = x+y+cos(sin(_Anim)*2.)*100.+sin(x/100.)*1000.;
float mov1 = y / _ResY / 0.2 + _Anim;
float mov2 = x / _ResX / 0.2;
float c1 = abs(sin(mov1+_Anim)/2.+mov2/2.-mov1-mov2+_Anim);
float c2 = abs(sin(c1+sin(mov0/1000.+_Anim)+sin(y/40.+_Anim)+sin((x+y)/100.)*3.));
float c3 = abs(sin(c2+cos(mov1+mov2+c2)+cos(mov2)+sin(x/1000.)));
outColor.rgba = float4(c1,c2,c3,1);
return outColor;
}
ENDCG
}
}
FallBack "VertexLit"
}

3 Comments + Add Comment

  • Change the variable “_Anim” to “_Time[1]” gave me the perfect plasma effect. Thanks!

    half4 frag (v2f i) : COLOR {
    float4 outColor = i.color;
    // main code, *original shader by: ‘Plasma’ by Viktor Korsun (2011)
    float x = i.fragPos.x;
    float y = i.fragPos.z;
    float mov0 = x+y+cos(sin(_Time[1]/10)*2.)*100.+sin(x/100.)*1000.;
    float mov1 = y / _ResY / 0.2 + _Time[1];
    float mov2 = x / _ResX / 0.2;
    float c1 = abs(sin(mov1+_Time[1])/2.+mov2/2.-mov1-mov2+_Time[1]);
    float c2 = abs(sin(c1+sin(mov0/1000.+_Time[1])+sin(y/40.+_Time[1])+sin((x+y)/100.)*3.));
    float c3 = abs(sin(c2+cos(mov1+mov2+c2)+cos(mov2)+sin(x/1000.)));
    outColor.rgba = float4(c1,c2,c3,0.5);
    return outColor;
    }

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.