-
-
Save John-O-Really/cbabc21662f86b2888ebe1bd16da470a to your computer and use it in GitHub Desktop.
Space Puck Shader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' | |
Shader "Unlit/Energy" | |
{ | |
Properties //Defines the properties for the shader, shown the GUI and used by the SubShader. Default values are defined here. | |
{ | |
_MainTex ("Texture", 2D) = "white" {} | |
_MainColor ("Color", Color) = (0.5, 0.5, 0.5, 1) | |
_Multiplier ("Multiplier", float) = 1 | |
_WaveStrength ("Wave Strength", float) = 1 | |
_Speed ("Speed", range(0.1,6)) = 1 | |
_Amp ("Amplitude", float) = 1 | |
_Offset ("Offset", float) = 0.2 | |
} | |
SubShader //Where the actual shader starts. References the properties or game values. | |
{ | |
Tags { //How the engine treats the shader, just for wildcards like transparency and stuff. | |
"IgnoreProjector" = "True" | |
"Queue" = "Transparent" | |
"RenderType" = "Transparent" | |
} | |
Pass //The "Shader shader bit" -Dickie 2017 You can have multiple passes which can work with or in place of other passes. The bit that controls the mesh and meterial. Pretty much... | |
{ | |
//Blend One One Addative shading | |
Blend SrcAlpha OneMinusSrcAlpha //Using the Alpha channel in 8 Bit, not 1 Bit. | |
Cull Off //Turn off back face culling, Cull back/front. Front would be used for outlines. | |
ZWrite Off //Writing to the Z-buffer, can be used for masking with lighting with Z-Test. | |
CGPROGRAM //Starting the CG code, talking in hard numbers and moving away from pre-compiled wrappers. | |
#pragma vertex vert //Defining shader as Vertex shader, not surface shader (which is actually just a fancy fragment shader) | |
#pragma fragment frag //So the Vert/Frag bit is what we're calling each thing. Vertex could be called "Steve" or "Vertex the 3rd" | |
#include "UnityCG.cginc" //Refering to an external script that holds functions and such. Such as storing a wind function for grass and trees. | |
struct appdata //Calling model from information from the game. | |
{ | |
float4 vertex : POSITION; | |
float2 uv : TEXCOORD0; //Call UV data | |
float3 normal : NORMAL; | |
}; | |
struct v2f //Storing vertex information so it can be read by the fragment shader | |
{ | |
float2 uv : TEXCOORD0; | |
float4 vertex : SV_POSITION; | |
float sine : TEXCOORD1; | |
float offsetsine : TEXCOORD2; | |
}; | |
sampler2D _MainTex; | |
float4 _MainTex_ST; //Float is defining the type of variable you're using | |
float _Multiplier; //_Thing is calling the properties to used by the Pass | |
float4 _MainColor; //This is hard core CG lingo | |
float _WaveStrength; | |
float _Speed; | |
float _Amp; | |
float _Offset; | |
v2f vert (appdata v)//You're plugging App Data in and calling it V, which is then used as Vertex Data, and then sending that to v2f | |
{ | |
v2f o; //Creating a variable to define V2F, sure. | |
o.sine = sin(_Time.y*_Speed + v.uv.x*_Amp); //_Time is time, _Time.x is half speed, and Time.y is real time. Getting a wave and storing it. | |
o.offsetsine = sin((_Time.y+_Offset)*2*_Speed + v.uv.x*_Amp)*2; | |
v.vertex.xyz += o.sine * (_WaveStrength*v.normal); //How much you effect the Vertex Pos with the Sine wave | |
o.vertex = UnityObjectToClipPos(v.vertex); //Converting the vertices from local space to world space. | |
//float3 normalDir = UnityObjectToWorldNormal(v.normal); | |
o.uv = TRANSFORM_TEX(v.uv, _MainTex); //Defining texture size and offset using the float4 | |
return o; //The end of the function, here is the v2f, goodbye my child :,( | |
} | |
fixed4 frag (v2f i, float facing : VFACE) : COLOR //Affecting the faces that are rendered. | |
{ | |
float isFrontFace = (facing >= 0 ? 1 : 0); //Only I know what this does. It's a secret. | |
float faceSign = (facing >= 0 ? 1 : -1); | |
// sample the texture | |
// return i.sine; | |
fixed4 col = tex2D(_MainTex, i.uv); //Creating the Col variable, Calling texture and UV data | |
col.rgb *= _MainColor; //Takes and defines the RGB data from the texture, affects the alpha by the multiplier, then applies the colour tint. | |
col.a *= saturate(col.a*(_Multiplier*i.offsetsine) + col.a); | |
return col; //Wrap that shit | |
} | |
ENDCG //We done! | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment