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"
}
Related Posts
3 Comments + Add Comment
Leave a comment
Recent posts
- Convert LAS/LAZ/PLY pointclouds to GLTF (GLB) Point Meshes (standalone converter)
- Detect SRP (URP or HDRP) with Assembly Definition Version Defines
- [LudumDare57] Theme: Depths
- MotionVector Effect: Object “disappears” when paused
- [GreaseMonkey] Unity Forum Fixer
- UnityHub: Make Hub application background Translucent
- Customize SpriteShapeRenderer quality (but has issues)
- Editor tool: Copy selected gameobject’s names into clipboard as rows (for Excel)
- Editor tool: Replace string in selected gameobject’s names
- UnityHub: Enable built-in Login Dialog (no more browser login/logout issues!)
- Use TikTok-TTS in Unity (with WebRequest)
- Create Scene Thumbnail Image using OnSceneSaved & OnPreviewGUI
Recent Comments
- on Vector3 maths for dummies!
- on UnityHub 3.6.0: Remove Version Control & Cloud Dashboard columns
- on Using RenderDoc with Unity (graphics debugger)
- on UI Scroll View automatic Content height
- on [Asset Store] Point Cloud Viewer & Tools
- on [Asset Store] Point Cloud Viewer & Tools
- on Vector3 maths for dummies!
- on UnityHub: Make Hub application background Translucent
An article by












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;
}
some gradient color example shaders here:
http://docs.unity3d.com/Documentation/Components/SL-VertexFragmentShaderExamples.html
some interesting shader effects here also (free)
http://forum.unity3d.com/threads/220460-Aubergines-Backgrounds-%28Free-stuff%29