[Elemental Shader Jam] Stormy Planet


Notice: Undefined variable: GuestHourOffset in /home/nitrogen/public_html_mgsatest/forums/themes/mgsa/class.mgsathemehooks.php on line 281

Notice: Undefined variable: GuestHourOffset in /home/nitrogen/public_html_mgsatest/forums/themes/mgsa/class.mgsathemehooks.php on line 281
edited in Online Competitions & Jams
Alrighty, so time to share some stuff, I will be doing quite a few things for this separately mostly as experimentation and learning (and these are things I have wanted to do for a long long time).

TexturedJitter
My goal with this one is to build a sort of "stormy planet" look, the first step works for a kind of Mars-ey/Saturn-ey storm planet look, though the next thing I will be doing is doing this with 2 textures to allow for a planet texture and then a cloud/storm texture. I initially wanted this to look like a flaming sun but I couldn't quite get that right, so on that I will head back to the drawing board.

The gif doesn't do it justice, but:
image

Code:
Shader "Custom/TexturedJitter" 
{
	Properties
	{
		_MainTex ("Main Texture", 2D) = "white" {}
	}
	
	SubShader 
	{		
		Pass
		{		
			CGPROGRAM
			#include "UnityCG.cginc"
			
			sampler2D	_MainTex;
			float4		_MainTex_ST;
			
			struct v2f
			{
				float4 	pos : POSITION;
				half2	uv : TEXCOORD0;
			};
			
			v2f vert (appdata_base v)
			{
				v2f o;
												
				o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
				o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
				
				return o;
			}

			fixed4 frag (v2f i) : COLOR0
			{
				fixed2 pos = tex2D(_MainTex, i.uv).xy;
				float pos_l = sqrt(pos.x * pos.x + pos.y + pos.y);
				pos = pos/pos_l;
				
				pos.x += cos(_Time.x);
				pos.y += sin(_Time.x * 3/2);
				
				fixed2 pos2 = (i.uv + pos)/(2 - sin(_Time.x));
				
				// Look up those UVs in the texture
				fixed4 col = tex2D(_MainTex, pos2);
				return col;
			}
	
			#pragma vertex vert
			#pragma fragment frag
			ENDCG
		}
	}
}


and texture used for people wanting to run it themselves:
image

Comments


  • Notice: Undefined variable: GuestHourOffset in /home/nitrogen/public_html_mgsatest/forums/themes/mgsa/class.mgsathemehooks.php on line 281
    @edg3 Thanks for sharing - I'm definitely planning to dive into shader code at some point. This is an interesting example and the effect looks amazing.

  • Notice: Undefined variable: GuestHourOffset in /home/nitrogen/public_html_mgsatest/forums/themes/mgsa/class.mgsathemehooks.php on line 281
    I will likely put a video on YouTube tomorrow to show a longer clip (not going to try and share a gif of better quality, this was the bare minimum I could do and its 2mb). I still have some things I want to tweak on this, but thanks :)

  • Notice: Undefined variable: GuestHourOffset in /home/nitrogen/public_html_mgsatest/forums/themes/mgsa/class.mgsathemehooks.php on line 281
    Protip:

    float pos_l = sqrt(pos.x * pos.x + pos.y + pos.y);
    				pos = pos/pos_l;

    This code is much better off written like so:
    float rpos_l = rsqrt(pos.x * pos.x + pos.y + pos.y);
    				pos = pos * rpos_l;


    rsqrt is another intrinsic function that calculates recipricol square roots. Square roots are, generally speaking, pretty expensive operations, but there are tricks to calculating the inverse that are quite a bit faster. As a result, it's (usually) safe to assume the GPU instruction for rsqrt is going to be faster than calculating 1/sqrt, and it's good practice to use rsqrt where it makes sense. Alternately, to just never calculate the square root if you don't absolutely need to (like for normalising) :p

  • Notice: Undefined variable: GuestHourOffset in /home/nitrogen/public_html_mgsatest/forums/themes/mgsa/class.mgsathemehooks.php on line 281
    Thanks @chippit - will keep that in mind in future :)

    Also - arbitrary thread name change, Im assuming Im not allowed to post multiple shaders to a single thread?
Sign In or Register to comment.

Debug Trace

Info Need to re-index theme cache
Info Need to re-index plugin cache
Info CommentModel->PageWhere()
Info
Comment.Page.30.2218.1: false
Info CommentModel->CachePageWhere()
Info
Comment.Page.30.2218.1: array (
  0 => '2014-07-08 13:55:20',
)
Notice Undefined variable: GuestHourOffset
/home/nitrogen/public_html_mgsatest/forums/themes/mgsa/class.mgsathemehooks.php line 281.
/home/nitrogen/public_html_mgsatest/forums/library/core/class.format.php line 465.
/home/nitrogen/public_html_mgsatest/forums/themes/mgsa/views/discussion/discussion.php line 62.
/home/nitrogen/public_html_mgsatest/forums/themes/mgsa/views/discussion/index.php line 35.
Notice Undefined variable: GuestHourOffset
/home/nitrogen/public_html_mgsatest/forums/themes/mgsa/class.mgsathemehooks.php line 281.
/home/nitrogen/public_html_mgsatest/forums/library/core/class.format.php line 465.
/home/nitrogen/public_html_mgsatest/forums/library/core/functions.render.php line 338.
/home/nitrogen/public_html_mgsatest/forums/themes/mgsa/views/discussion/discussion.php line 66.
Notice Undefined variable: GuestHourOffset
/home/nitrogen/public_html_mgsatest/forums/themes/mgsa/class.mgsathemehooks.php line 281.
/home/nitrogen/public_html_mgsatest/forums/library/core/class.format.php line 465.
/home/nitrogen/public_html_mgsatest/forums/themes/mgsa/class.mgsathemehooks.php line 712.
/home/nitrogen/public_html_mgsatest/forums/applications/vanilla/views/discussion/comments.php line 19.
Notice Undefined variable: GuestHourOffset
/home/nitrogen/public_html_mgsatest/forums/themes/mgsa/class.mgsathemehooks.php line 281.
/home/nitrogen/public_html_mgsatest/forums/library/core/class.format.php line 465.
/home/nitrogen/public_html_mgsatest/forums/themes/mgsa/class.mgsathemehooks.php line 712.
/home/nitrogen/public_html_mgsatest/forums/applications/vanilla/views/discussion/comments.php line 19.
Notice Undefined variable: GuestHourOffset
/home/nitrogen/public_html_mgsatest/forums/themes/mgsa/class.mgsathemehooks.php line 281.
/home/nitrogen/public_html_mgsatest/forums/library/core/class.format.php line 465.
/home/nitrogen/public_html_mgsatest/forums/themes/mgsa/class.mgsathemehooks.php line 712.
/home/nitrogen/public_html_mgsatest/forums/applications/vanilla/views/discussion/comments.php line 19.
Notice Undefined variable: GuestHourOffset
/home/nitrogen/public_html_mgsatest/forums/themes/mgsa/class.mgsathemehooks.php line 281.
/home/nitrogen/public_html_mgsatest/forums/library/core/class.format.php line 465.
/home/nitrogen/public_html_mgsatest/forums/themes/mgsa/class.mgsathemehooks.php line 712.
/home/nitrogen/public_html_mgsatest/forums/applications/vanilla/views/discussion/comments.php line 19.