Created
October 4, 2016 10:38
-
-
Save oneandonlyoddo/ca8c3986f0a776c9e0b63fc7b4ba9942 to your computer and use it in GitHub Desktop.
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
// Unity Shader Doc https://docs.unity3d.com/Manual/SL-ShaderPrograms.html | |
// Unity Shader Doc https://docs.unity3d.com/Manual/SL-Reference.html | |
Shader "Custom/Test/foo shader" { | |
//Variables | |
Properties{ | |
// float, 2D (Texture), color etc. | |
_MainTexture("Main Color (RGB)", 2D) = "white" {} | |
_Color("Color", Color) = (1,1,1,1) | |
} | |
// Subshaders for example for diffferent Plattforms or Detail level | |
SubShader{ | |
// Renderpasses - use as few as possible | |
Pass{ | |
CGPROGRAM // the actual Shadercode beginning | |
// Define what my vert and frag functions are going to be | |
#pragma vertex vertexFunction | |
#pragma fragment fragmentfunction | |
#include "UnityCG.cginc" // include "Shader libraries" - Helpers for different use cases | |
// Define the information from the Object I want to use | |
// This can be for example | |
// Vertices | |
// Normals | |
// Color | |
// uvs etc. | |
struct appdata{ | |
float4 vertex : POSITION; // type variable name : DATA <- The Keywords for the Data is Predefined I guess? | |
float2 uv : TEXCOORD0; | |
}; | |
// Creating the outputtype of our vertexFunction I guess? | |
struct v2f{ | |
float4 position : SV_POSITION; | |
float2 uv: TEXCOORD0; | |
}; | |
float4 _Color; // This will automatically get the _Color Reference from the Properties further up which can be set in the Unity Editor or by Script | |
sampler2D _MainTexture; | |
// Vertex Part - Build the Object | |
v2f vertexFunction(appdata IN){ | |
v2f OUT; | |
// Setting the Vars from my v2f Type / Object | |
OUT.position = mul(UNITY_MATRIX_MVP, IN.vertex); // MVP = Model View Projection / mul() from cg standard library http://http.developer.nvidia.com/Cg/index_stdlib.html | |
OUT.uv = IN.uv; | |
return OUT; | |
} | |
// Fragment Part - Color the Object | |
fixed4 fragmentfunction(v2f IN) : SV_Target{ // Target -> Endresult | |
float4 textureColor = tex2D(_MainTexture, IN.uv); // get the color from the sampler at the uv position | |
float4 endColor = textureColor * _Color; | |
return endColor; // final outcome is a color for this pixel | |
} | |
ENDCG // the actual Shadercode end | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment