16
2011
Metablob shader testing
Metablob shader testing.
2D metablobs..hmm..could this be used for (2D) fluids somehow?
Instructions:
– New scene
– Add plane, Location: 0,0,0 Rotation: 0,0,0
– Add camera, Location: 0,10,0 Rotation: 90,0,0 (its looking down the plane)
– Add material using this shader to the plane, you should see some blobs (its using screenposition, so you might not see blobs in editor, depending on your view pos)
Download source:
blobshader.unityPackage
Shader source: (v1.0)
// ORIGINAL GLSL SHADER: 'Metablob' by Adrian Boeing (2011) Shader "mShaders/mblob1" { Properties { } SubShader { Tags {Queue = Geometry} Pass { CGPROGRAM #pragma target 3.0 #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" 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 { float animtime = _Time*10.0; //the centre point for each blob float2 move1; move1.x = cos(animtime)*0.4; move1.y = sin(animtime*1.5)*0.4; float2 move2; move2.x = cos(animtime*2.0)*0.4; move2.y = sin(animtime*3.0)*0.4; //screen coordinates float2 p = -1.0 + 2.0 * i.fragPos.xy / float2 (7,7); //radius for each blob float r1 =(dot(p-move1,p-move1))*8.0; float r2 =(dot(p+move2,p+move2))*16.0; //sum the meatballs // uh..typo maybe Oo? float metaball =(1.0/r1+1.0/r2); //alter the cut-off power float col = pow(metaball,8.0); //set the output color return float4(col,col,col,1.0); } ENDCG } } FallBack "VertexLit" }
Related Posts
10 Comments + Add Comment
Leave a comment
Recent posts
- [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
- webgl+javascript TTS
- Using Moonsharp (LUA) + Unity Webgl
- Using 3D gameobject prefabs with Unity Tilemap + NavMesh Surface
- Custom Unity Hub Project Template Preview Image/Video (using HTML+CSS in package description)
Recent Comments
- Vector3 maths for dummies! on
- UnityHub: Make Hub application background Translucent on
- UnityHub: Make Hub application background Translucent on
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub) on
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub) on
- [Asset Store] Point Cloud Viewer & Tools on
- [Asset Store] Point Cloud Viewer & Tools on
- ffmpeg stream raw video into Unity Texture2D on
How can I make it work?
All I see is a black sphere 🙁
Thanks!!
added some instructions, havent tested it on a sphere..but on a plane it seems to work.
Thanks for the info and for the blog.
I thought it was a material to use in several near spheres in order to achive the 2D metablob effect ^_^U
how i can remove screen position dependency?
replace line:
float4 fragPos : COLOR1;
with:
float4 uv : TEXCOORD0;
replace line:
o.fragPos = o.pos;
with:
o.uv = float4( v.texcoord.xy, 0, 0 );
replace line:
float2 p = -1.0 + 2.0 * i.fragPos.xy / float2 (7,7);
with:
float2 p = i.uv.xy-float2(0.5,0.5);
(you might have to adjust those 0.5 values, but for the same scene, it should display the blobs on middle of the plane then)
Hi, just a quick question – does this shader require Unity Pro? 🙁 Can’t get it to work so i guess it does, but want to be shure. Thanks
Doesn’t need pro, if you set the scene plane & camera to those locations, it should work..
Does it show just black or that pink/magenta color?
Only black plane (everything was done as written above, no idea what could be wrong). Could you maybe upload a project folder where it works for you?
// also tried the modifications written above (screen position dependency), everythings still the same
/* sorry, forgot to click Reply :-X */
^ Added example scene download.