├── .gitignore ├── Assets ├── Lesson1.meta ├── Lesson1 │ ├── Colorizer.cs │ ├── Colorizer.cs.meta │ ├── JustColor.shader │ ├── JustColor.shader.meta │ ├── Lesson1.unity │ └── Lesson1.unity.meta ├── Lesson2.meta ├── Lesson2 │ ├── BGPlaneMaterial.mat │ ├── BGPlaneMaterial.mat.meta │ ├── BlueColor.shader │ ├── BlueColor.shader.meta │ ├── BluePlaneMaterial.mat │ ├── BluePlaneMaterial.mat.meta │ ├── ColorDebug.shader │ ├── ColorDebug.shader.meta │ ├── FGPlaneMaterial.mat │ ├── FGPlaneMaterial.mat.meta │ ├── Lesson2.unity │ └── Lesson2.unity.meta ├── Lesson3.meta ├── Lesson3 │ ├── ColoredBGPlaneMaterial.mat │ ├── ColoredBGPlaneMaterial.mat.meta │ ├── Lesson3.unity │ ├── Lesson3.unity.meta │ ├── SimpleTexture.shader │ ├── SimpleTexture.shader.meta │ ├── SimpleTextureTwoSided.shader │ └── SimpleTextureTwoSided.shader.meta ├── Lesson4.meta ├── Lesson4 │ ├── DualTextureMix.shader │ ├── DualTextureMix.shader.meta │ ├── DualTextureWipe.shader │ ├── DualTextureWipe.shader.meta │ ├── Lesson4.unity │ ├── Lesson4.unity.meta │ ├── SimpleTextureVertFun.shader │ └── SimpleTextureVertFun.shader.meta ├── Lesson5.meta ├── Lesson5 │ ├── Lesson5.unity │ ├── Lesson5.unity.meta │ ├── VertexLit.shader │ └── VertexLit.shader.meta ├── Lesson6.meta ├── Lesson6 │ ├── Lesson6.unity │ ├── Lesson6.unity.meta │ ├── VetexLitSpecular.shader │ └── VetexLitSpecular.shader.meta ├── Shared.meta ├── Shared │ ├── Prime31.cginc │ ├── Prime31.cginc.meta │ ├── Templates.meta │ ├── Templates │ │ ├── BasicTemplate.shader │ │ ├── BasicTemplate.shader.meta │ │ ├── SceneTemplate.unity │ │ ├── SceneTemplate.unity.meta │ │ ├── Template.shader │ │ └── Template.shader.meta │ ├── Textures.meta │ └── Textures │ │ ├── Brick.jpg │ │ ├── Brick.jpg.meta │ │ ├── Brick_NORM.tga │ │ ├── Brick_NORM.tga.meta │ │ ├── Fern.psd │ │ ├── Fern.psd.meta │ │ ├── GlassBreak.jpg │ │ ├── GlassBreak.jpg.meta │ │ ├── earth.png │ │ └── earth.png.meta ├── TesterMaterial.mat └── TesterMaterial.mat.meta ├── ProjectSettings ├── AudioManager.asset ├── DynamicsManager.asset ├── EditorBuildSettings.asset ├── EditorSettings.asset ├── GraphicsSettings.asset ├── InputManager.asset ├── NavMeshLayers.asset ├── NetworkManager.asset ├── ProjectSettings.asset ├── QualitySettings.asset ├── TagManager.asset └── TimeManager.asset ├── README.md └── Shaders.userprefs /.gitignore: -------------------------------------------------------------------------------- 1 | [Ll]ibrary/ 2 | [Tt]emp/ 3 | [Oo]bj/ 4 | 5 | # Autogenerated VS/MD solution and project files 6 | *.csproj 7 | *.unityproj 8 | *.sln 9 | *.userprefs 10 | -------------------------------------------------------------------------------- /Assets/Lesson1.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 39caf8636ac6e4024a9b5ca67e76a3bd 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Lesson1/Colorizer.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | 5 | [ExecuteInEditMode] 6 | public class Colorizer : MonoBehaviour 7 | { 8 | public Color diffuseColor; 9 | 10 | 11 | void Update() 12 | { 13 | renderer.sharedMaterial.SetColor( "_Color", diffuseColor ); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Assets/Lesson1/Colorizer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: df7e73a711b6c421486bbf869f7336f6 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Assets/Lesson1/JustColor.shader: -------------------------------------------------------------------------------- 1 | Shader "_Shaders/JustColor" 2 | { 3 | Properties 4 | { 5 | _Color ( "Tint Color", Color ) = ( 1.0, 1.0, 1.0, 1.0 ) 6 | } 7 | 8 | SubShader 9 | { 10 | Tags { "Queue" = "Transparent" } 11 | Blend SrcAlpha OneMinusSrcAlpha 12 | 13 | Pass 14 | { 15 | CGPROGRAM 16 | #pragma exclude_renderers ps3 xbox360 flash 17 | #pragma fragmentoption ARB_precision_hint_fastest 18 | #pragma vertex vert 19 | #pragma fragment frag 20 | 21 | #include "UnityCG.cginc" 22 | 23 | 24 | // uniforms 25 | uniform fixed4 _Color; 26 | 27 | 28 | struct vertexInput 29 | { 30 | float4 vertex : POSITION; // position (in object coordinates) 31 | }; 32 | 33 | 34 | struct fragmentInput 35 | { 36 | float4 pos : SV_POSITION; 37 | float4 color : COLOR0; 38 | }; 39 | 40 | 41 | fragmentInput vert( vertexInput i ) 42 | { 43 | fragmentInput o; 44 | o.pos = mul( UNITY_MATRIX_MVP, i.vertex ); 45 | o.color = _Color; 46 | 47 | return o; 48 | } 49 | 50 | 51 | half4 frag( fragmentInput i ) : COLOR 52 | { 53 | return i.color; 54 | } 55 | 56 | ENDCG 57 | } // end Pass 58 | } // end SubShader 59 | 60 | FallBack "Diffuse" 61 | } 62 | -------------------------------------------------------------------------------- /Assets/Lesson1/JustColor.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d03be11169b69493d955ceb3493e742a 3 | ShaderImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Lesson1/Lesson1.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/UnityCgShaderTutorials/b99050c9da04829ec665e54d4c4b8c5fd26e5c88/Assets/Lesson1/Lesson1.unity -------------------------------------------------------------------------------- /Assets/Lesson1/Lesson1.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e85c9b31455554276b95a3c667e71f26 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Lesson2.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ccac48d6d0746432db5e78c3985356b9 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Lesson2/BGPlaneMaterial.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/UnityCgShaderTutorials/b99050c9da04829ec665e54d4c4b8c5fd26e5c88/Assets/Lesson2/BGPlaneMaterial.mat -------------------------------------------------------------------------------- /Assets/Lesson2/BGPlaneMaterial.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 64c060c2981764e47889eec33cee3afd 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Lesson2/BlueColor.shader: -------------------------------------------------------------------------------- 1 | Shader "_Shaders/Blue Color" 2 | { 3 | SubShader 4 | { 5 | Tags { "Queue" = "Transparent" } 6 | Blend SrcAlpha OneMinusSrcAlpha 7 | ZWrite Off 8 | 9 | Pass 10 | { 11 | CGPROGRAM 12 | #pragma exclude_renderers ps3 xbox360 flash 13 | #pragma fragmentoption ARB_precision_hint_fastest 14 | #pragma vertex vert 15 | #pragma fragment frag 16 | 17 | #include "UnityCG.cginc" 18 | 19 | 20 | struct vertexInput 21 | { 22 | float4 vertex : POSITION; // position (in object coordinates) 23 | }; 24 | 25 | 26 | struct fragmentInput 27 | { 28 | float4 pos : SV_POSITION; 29 | }; 30 | 31 | 32 | fragmentInput vert( vertexInput i ) 33 | { 34 | fragmentInput o; 35 | o.pos = mul( UNITY_MATRIX_MVP, i.vertex ); 36 | 37 | return o; 38 | } 39 | 40 | 41 | half4 frag( fragmentInput i ) : COLOR 42 | { 43 | return half4( 0.0, 0.0, 1.0, 0.3 ); 44 | } 45 | 46 | ENDCG 47 | } // end Pass 48 | } // end SubShader 49 | 50 | FallBack "Diffuse" 51 | } 52 | -------------------------------------------------------------------------------- /Assets/Lesson2/BlueColor.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b7b94a2dcc50f4f29a469f9eb1036185 3 | ShaderImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Lesson2/BluePlaneMaterial.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/UnityCgShaderTutorials/b99050c9da04829ec665e54d4c4b8c5fd26e5c88/Assets/Lesson2/BluePlaneMaterial.mat -------------------------------------------------------------------------------- /Assets/Lesson2/BluePlaneMaterial.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9cd1864c6df7b459e8ed35c95b40a7b6 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Lesson2/ColorDebug.shader: -------------------------------------------------------------------------------- 1 | Shader "_Shaders/ColorDebug" 2 | { 3 | Properties 4 | { 5 | _Color ( "Tint Color", Color ) = ( 1.0, 1.0, 1.0, 1.0 ) 6 | } 7 | 8 | SubShader 9 | { 10 | Tags { "Queue" = "Transparent" } 11 | ZWrite Off // should we write to the depth buffer? 12 | 13 | // Blend modes equation: 14 | // SrcFactor * fragment_output + DstFactor * pixel_color_in_framebuffer; 15 | // Blend {code for SrcFactor} {code for DstFactor} 16 | 17 | Blend SrcAlpha OneMinusSrcAlpha // alpha blending 18 | //Blend One OneMinusSrcAlpha // premultiplied alpha blending 19 | //Blend One One // additive 20 | //Blend SrcAlpha One // additive blending 21 | //Blend OneMinusDstColor One // soft additive 22 | //Blend DstColor Zero // multiplicative 23 | //Blend DstColor SrcColor // 2x multiplicative 24 | //Blend Zero SrcAlpha // multiplicative blending for attenuation by the fragment's alpha 25 | 26 | Pass 27 | { 28 | CGPROGRAM 29 | #pragma exclude_renderers ps3 xbox360 flash 30 | #pragma fragmentoption ARB_precision_hint_fastest 31 | #pragma vertex vert 32 | #pragma fragment frag 33 | 34 | #include "UnityCG.cginc" 35 | 36 | 37 | // uniforms 38 | uniform fixed4 _Color; 39 | 40 | 41 | struct vertexInput 42 | { 43 | float4 vertex : POSITION; // position (in object coordinates, i.e. local or model coordinates) 44 | float4 tangent : TANGENT; // vector orthogonal to the surface normal 45 | float3 normal : NORMAL; // surface normal vector (in object coordinates; usually normalized to unit length) 46 | float4 texcoord : TEXCOORD0; // 0th set of texture coordinates (a.k.a. “UV”; between 0 and 1) 47 | float4 texcoord1 : TEXCOORD1; // 1st set of texture coordinates (a.k.a. “UV”; between 0 and 1) 48 | fixed4 color : COLOR; // vertex color 49 | }; 50 | 51 | 52 | struct fragmentInput 53 | { 54 | float4 pos : SV_POSITION; 55 | float4 color : COLOR0; 56 | }; 57 | 58 | 59 | fragmentInput vert( vertexInput i ) 60 | { 61 | fragmentInput o; 62 | o.pos = mul( UNITY_MATRIX_MVP, i.vertex ); 63 | o.color = _Color; 64 | 65 | 66 | 67 | // debug: uncomment the desired item to debug then return i.color directly in the fragment shader 68 | //o.color = i.texcoord; 69 | //o.color = i.texcoord1; 70 | //o.color = i.vertex; 71 | //o.color = i.vertex + float4( 0.5, 0.5, 0.5, 0.0 ); // we add 0.5's to offset if the model verts go from -0.5 - 0.5 72 | //o.color = i.tangent; 73 | //o.color = float4( i.normal * 0.5 + 0.5, 1.0 ); // scale and bias the normal to get it in the range of 0 - 1 74 | //o.color = i.color; // vertex colors 75 | 76 | 77 | return o; 78 | } 79 | 80 | 81 | half4 frag( fragmentInput i ) : COLOR 82 | { 83 | return i.color; 84 | } 85 | 86 | ENDCG 87 | } // end Pass 88 | } // end SubShader 89 | 90 | FallBack "Diffuse" 91 | } 92 | -------------------------------------------------------------------------------- /Assets/Lesson2/ColorDebug.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 16f48fe4607604808804f8e5eede5080 3 | ShaderImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Lesson2/FGPlaneMaterial.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/UnityCgShaderTutorials/b99050c9da04829ec665e54d4c4b8c5fd26e5c88/Assets/Lesson2/FGPlaneMaterial.mat -------------------------------------------------------------------------------- /Assets/Lesson2/FGPlaneMaterial.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3069bc14cc7c947219f6dcf038484c27 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Lesson2/Lesson2.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/UnityCgShaderTutorials/b99050c9da04829ec665e54d4c4b8c5fd26e5c88/Assets/Lesson2/Lesson2.unity -------------------------------------------------------------------------------- /Assets/Lesson2/Lesson2.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a4ed95dc956b042b1ba95ec2aec3504f 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Lesson3.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f9bf99eb546dd419083a04aff680bf56 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Lesson3/ColoredBGPlaneMaterial.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/UnityCgShaderTutorials/b99050c9da04829ec665e54d4c4b8c5fd26e5c88/Assets/Lesson3/ColoredBGPlaneMaterial.mat -------------------------------------------------------------------------------- /Assets/Lesson3/ColoredBGPlaneMaterial.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7a53361cd4e9d4bb39e0e11d03139db2 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Lesson3/Lesson3.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/UnityCgShaderTutorials/b99050c9da04829ec665e54d4c4b8c5fd26e5c88/Assets/Lesson3/Lesson3.unity -------------------------------------------------------------------------------- /Assets/Lesson3/Lesson3.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e9ccd00e101544ce18ae52cf8e84568f 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Lesson3/SimpleTexture.shader: -------------------------------------------------------------------------------- 1 | Shader "_Shaders/Simple Texture" 2 | { 3 | Properties 4 | { 5 | _MainTex ( "Main Texture", 2D ) = "white" {} 6 | } 7 | 8 | SubShader 9 | { 10 | Tags { "Queue" = "Transparent" } 11 | ZWrite Off 12 | Blend SrcAlpha OneMinusSrcAlpha 13 | 14 | Pass 15 | { 16 | CGPROGRAM 17 | #pragma exclude_renderers ps3 xbox360 flash 18 | #pragma fragmentoption ARB_precision_hint_fastest 19 | #pragma vertex vert 20 | #pragma fragment frag 21 | 22 | #include "UnityCG.cginc" 23 | 24 | 25 | // uniforms 26 | uniform sampler2D _MainTex; 27 | uniform float4 _MainTex_ST; 28 | 29 | 30 | struct vertexInput 31 | { 32 | float4 vertex : POSITION; // position (in object coordinates, i.e. local or model coordinates) 33 | float4 texcoord : TEXCOORD0; // 0th set of texture coordinates (a.k.a. “UV”; between 0 and 1) 34 | }; 35 | 36 | 37 | struct fragmentInput 38 | { 39 | float4 pos : SV_POSITION; 40 | half2 uv : TEXCOORD0; 41 | }; 42 | 43 | 44 | fragmentInput vert( vertexInput i ) 45 | { 46 | fragmentInput o; 47 | o.pos = mul( UNITY_MATRIX_MVP, i.vertex ); 48 | o.uv = TRANSFORM_TEX( i.texcoord, _MainTex ); 49 | 50 | return o; 51 | } 52 | 53 | 54 | half4 frag( fragmentInput i ) : COLOR 55 | { 56 | return tex2D( _MainTex, i.uv ); 57 | } 58 | 59 | ENDCG 60 | } // end Pass 61 | } // end SubShader 62 | 63 | FallBack "Diffuse" 64 | } 65 | -------------------------------------------------------------------------------- /Assets/Lesson3/SimpleTexture.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 292f484704c0145c3a9c27f2e36ba9b9 3 | ShaderImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Lesson3/SimpleTextureTwoSided.shader: -------------------------------------------------------------------------------- 1 | Shader "_Shaders/Simple Texture Two Sided" 2 | { 3 | Properties 4 | { 5 | _MainTex ( "Main Texture", 2D ) = "white" {} 6 | } 7 | 8 | SubShader 9 | { 10 | Tags { "Queue" = "Transparent" } 11 | ZWrite Off 12 | Blend SrcAlpha OneMinusSrcAlpha 13 | 14 | 15 | Pass 16 | { 17 | Cull Front 18 | CGPROGRAM 19 | #pragma exclude_renderers ps3 xbox360 flash 20 | #pragma fragmentoption ARB_precision_hint_fastest 21 | #pragma vertex vert 22 | #pragma fragment frag 23 | 24 | #include "UnityCG.cginc" 25 | 26 | 27 | // uniforms 28 | uniform sampler2D _MainTex; 29 | uniform float4 _MainTex_ST; 30 | 31 | 32 | struct vertexInput 33 | { 34 | float4 vertex : POSITION; // position (in object coordinates, i.e. local or model coordinates) 35 | float4 texcoord : TEXCOORD0; // 0th set of texture coordinates (a.k.a. “UV”; between 0 and 1) 36 | }; 37 | 38 | 39 | struct fragmentInput 40 | { 41 | float4 pos : SV_POSITION; 42 | half2 uv : TEXCOORD0; 43 | }; 44 | 45 | 46 | fragmentInput vert( vertexInput i ) 47 | { 48 | fragmentInput o; 49 | o.pos = mul( UNITY_MATRIX_MVP, i.vertex ); 50 | o.uv = TRANSFORM_TEX( i.texcoord, _MainTex ); 51 | 52 | return o; 53 | } 54 | 55 | 56 | half4 frag( fragmentInput i ) : COLOR 57 | { 58 | return tex2D( _MainTex, i.uv ); 59 | } 60 | 61 | ENDCG 62 | } // end Pass 63 | 64 | Pass 65 | { 66 | Cull Back 67 | CGPROGRAM 68 | #pragma exclude_renderers ps3 xbox360 flash 69 | #pragma fragmentoption ARB_precision_hint_fastest 70 | #pragma vertex vert 71 | #pragma fragment frag 72 | 73 | #include "UnityCG.cginc" 74 | 75 | 76 | // uniforms 77 | uniform sampler2D _MainTex; 78 | uniform float4 _MainTex_ST; 79 | 80 | 81 | struct vertexInput 82 | { 83 | float4 vertex : POSITION; // position (in object coordinates, i.e. local or model coordinates) 84 | float4 texcoord : TEXCOORD0; // 0th set of texture coordinates (a.k.a. “UV”; between 0 and 1) 85 | }; 86 | 87 | 88 | struct fragmentInput 89 | { 90 | float4 pos : SV_POSITION; 91 | half2 uv : TEXCOORD0; 92 | }; 93 | 94 | 95 | fragmentInput vert( vertexInput i ) 96 | { 97 | fragmentInput o; 98 | o.pos = mul( UNITY_MATRIX_MVP, i.vertex ); 99 | o.uv = TRANSFORM_TEX( i.texcoord, _MainTex ); 100 | 101 | return o; 102 | } 103 | 104 | 105 | half4 frag( fragmentInput i ) : COLOR 106 | { 107 | return tex2D( _MainTex, i.uv ); 108 | } 109 | 110 | ENDCG 111 | } // end Pass 112 | } // end SubShader 113 | 114 | FallBack "Diffuse" 115 | } 116 | -------------------------------------------------------------------------------- /Assets/Lesson3/SimpleTextureTwoSided.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 21d563b8e4b4a4e19a1cdeeaad8561de 3 | ShaderImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Lesson4.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 19d28cb61b61048e88663661a9179ce6 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Lesson4/DualTextureMix.shader: -------------------------------------------------------------------------------- 1 | Shader "_Shaders/Dual Texture Mix" 2 | { 3 | Properties 4 | { 5 | _MainTex ( "Main Texture", 2D ) = "white" {} 6 | _SecondTex ( "Second Texture", 2D ) = "white" {} 7 | _TextureMix ( "Texture mix", Range( 0.0, 1.0 ) ) = 0.5 8 | } 9 | 10 | SubShader 11 | { 12 | Tags { "Queue" = "Transparent" } 13 | ZWrite Off 14 | Blend SrcAlpha OneMinusSrcAlpha 15 | 16 | Pass 17 | { 18 | CGPROGRAM 19 | #pragma exclude_renderers ps3 xbox360 flash 20 | #pragma fragmentoption ARB_precision_hint_fastest 21 | #pragma vertex vert 22 | #pragma fragment frag 23 | 24 | #include "UnityCG.cginc" 25 | 26 | 27 | // uniforms 28 | uniform sampler2D _MainTex; 29 | uniform float4 _MainTex_ST; 30 | uniform sampler2D _SecondTex; 31 | uniform float4 _SecondTex_ST; 32 | uniform fixed _TextureMix; 33 | 34 | 35 | struct vertexInput 36 | { 37 | float4 vertex : POSITION; // position (in object coordinates, i.e. local or model coordinates) 38 | float4 texcoord : TEXCOORD0; // 0th set of texture coordinates (a.k.a. “UV”; between 0 and 1) 39 | }; 40 | 41 | 42 | struct fragmentInput 43 | { 44 | float4 pos : SV_POSITION; 45 | half2 uv : TEXCOORD0; 46 | half2 uv2 : TEXCOORD1; 47 | }; 48 | 49 | 50 | fragmentInput vert( vertexInput i ) 51 | { 52 | fragmentInput o; 53 | o.pos = mul( UNITY_MATRIX_MVP, i.vertex ); 54 | o.uv = TRANSFORM_TEX( i.texcoord, _MainTex ); 55 | o.uv2 = TRANSFORM_TEX( i.texcoord, _SecondTex ); 56 | 57 | return o; 58 | } 59 | 60 | 61 | half4 frag( fragmentInput i ) : COLOR 62 | { 63 | fixed4 mainTexColor = tex2D( _MainTex, i.uv ); 64 | fixed4 secondTexColor = tex2D( _SecondTex, i.uv2 ); 65 | 66 | return lerp( mainTexColor, secondTexColor, _TextureMix ); 67 | } 68 | 69 | ENDCG 70 | } // end Pass 71 | } // end SubShader 72 | 73 | FallBack "Diffuse" 74 | } 75 | -------------------------------------------------------------------------------- /Assets/Lesson4/DualTextureMix.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4dbc6836f96c44e3e98061e34eb91bb2 3 | ShaderImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Lesson4/DualTextureWipe.shader: -------------------------------------------------------------------------------- 1 | Shader "_Shaders/Dual Texture Wipe" 2 | { 3 | Properties 4 | { 5 | _MainTex ( "Main Texture", 2D ) = "white" {} 6 | _SecondTex ( "Second Texture", 2D ) = "white" {} 7 | _TextureMix ( "Texture Mix", Range( 0.0, 1.0 ) ) = 0.5 8 | } 9 | 10 | SubShader 11 | { 12 | Tags { "Queue" = "Geometry" } 13 | 14 | Pass 15 | { 16 | CGPROGRAM 17 | #pragma exclude_renderers ps3 xbox360 flash 18 | #pragma fragmentoption ARB_precision_hint_fastest 19 | #pragma vertex vert 20 | #pragma fragment frag 21 | 22 | #include "UnityCG.cginc" 23 | 24 | 25 | // uniforms 26 | uniform sampler2D _MainTex; 27 | uniform float4 _MainTex_ST; 28 | uniform sampler2D _SecondTex; 29 | uniform float4 _SecondTex_ST; 30 | uniform fixed _TextureMix; 31 | 32 | 33 | struct vertexInput 34 | { 35 | float4 vertex : POSITION; // position (in object coordinates, i.e. local or model coordinates) 36 | float4 texcoord : TEXCOORD0; // 0th set of texture coordinates (a.k.a. “UV”; between 0 and 1) 37 | }; 38 | 39 | 40 | struct fragmentInput 41 | { 42 | float4 pos : SV_POSITION; 43 | half2 uv : TEXCOORD0; 44 | half2 uv2 : TEXCOORD1; 45 | fixed2 localPos : TEXCOORD2; 46 | }; 47 | 48 | 49 | fragmentInput vert( vertexInput i ) 50 | { 51 | fragmentInput o; 52 | o.localPos = i.vertex.xy + fixed2( 0.5, 0.5 ); 53 | o.pos = mul( UNITY_MATRIX_MVP, i.vertex ); 54 | o.uv = TRANSFORM_TEX( i.texcoord, _MainTex ); 55 | o.uv2 = TRANSFORM_TEX( i.texcoord, _SecondTex ); 56 | 57 | return o; 58 | } 59 | 60 | 61 | half4 frag( fragmentInput i ) : COLOR 62 | { 63 | fixed distanceFromMixPoint = _TextureMix - i.localPos.x; 64 | 65 | if( abs( distanceFromMixPoint ) < 0.2 ) 66 | { 67 | fixed mixFactor = 1 - ( distanceFromMixPoint + 0.2 ) / 0.4; 68 | return lerp( tex2D( _MainTex, i.uv ), tex2D( _SecondTex, i.uv2 ), mixFactor ); 69 | } 70 | 71 | 72 | if( i.localPos.x < _TextureMix ) 73 | { 74 | return tex2D( _MainTex, i.uv ); 75 | } 76 | else 77 | { 78 | return tex2D( _SecondTex, i.uv2 ); 79 | } 80 | } 81 | 82 | ENDCG 83 | } // end Pass 84 | } // end SubShader 85 | 86 | FallBack "Diffuse" 87 | } 88 | -------------------------------------------------------------------------------- /Assets/Lesson4/DualTextureWipe.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a04c809b076774869997d4c976445464 3 | ShaderImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Lesson4/Lesson4.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/UnityCgShaderTutorials/b99050c9da04829ec665e54d4c4b8c5fd26e5c88/Assets/Lesson4/Lesson4.unity -------------------------------------------------------------------------------- /Assets/Lesson4/Lesson4.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0ee12328eb3c1420aaf4ed04b186b418 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Lesson4/SimpleTextureVertFun.shader: -------------------------------------------------------------------------------- 1 | Shader "_Shaders/Simple Texture Vert Fun" 2 | { 3 | Properties 4 | { 5 | _MainTex ( "Main Texture", 2D ) = "white" {} 6 | } 7 | 8 | SubShader 9 | { 10 | Tags { "Queue" = "Transparent" } 11 | ZWrite Off 12 | Blend SrcAlpha OneMinusSrcAlpha 13 | 14 | Pass 15 | { 16 | CGPROGRAM 17 | #pragma exclude_renderers ps3 xbox360 flash 18 | #pragma fragmentoption ARB_precision_hint_fastest 19 | #pragma vertex vert 20 | #pragma fragment frag 21 | 22 | #include "UnityCG.cginc" 23 | 24 | 25 | // uniforms 26 | uniform sampler2D _MainTex; 27 | uniform float4 _MainTex_ST; 28 | 29 | 30 | struct vertexInput 31 | { 32 | float4 vertex : POSITION; // position (in object coordinates, i.e. local or model coordinates) 33 | float4 texcoord : TEXCOORD0; // 0th set of texture coordinates (a.k.a. “UV”; between 0 and 1) 34 | }; 35 | 36 | 37 | struct fragmentInput 38 | { 39 | float4 pos : SV_POSITION; 40 | half2 uv : TEXCOORD0; 41 | }; 42 | 43 | 44 | fragmentInput vert( vertexInput i ) 45 | { 46 | fragmentInput o; 47 | 48 | // vert distortion 49 | i.vertex.x += _SinTime.w * i.vertex.y; 50 | 51 | o.pos = mul( UNITY_MATRIX_MVP, i.vertex ); 52 | o.uv = TRANSFORM_TEX( i.texcoord, _MainTex ); 53 | 54 | return o; 55 | } 56 | 57 | 58 | half4 frag( fragmentInput i ) : COLOR 59 | { 60 | return tex2D( _MainTex, i.uv ); 61 | } 62 | 63 | ENDCG 64 | } // end Pass 65 | } // end SubShader 66 | 67 | FallBack "Diffuse" 68 | } 69 | -------------------------------------------------------------------------------- /Assets/Lesson4/SimpleTextureVertFun.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 55e774950bc3142a0ab9ae4fcc1cea06 3 | ShaderImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Lesson5.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fc1790e348a0a489f855bb2e35d28764 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Lesson5/Lesson5.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/UnityCgShaderTutorials/b99050c9da04829ec665e54d4c4b8c5fd26e5c88/Assets/Lesson5/Lesson5.unity -------------------------------------------------------------------------------- /Assets/Lesson5/Lesson5.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 00238fe29c82047048482b1c1948f76c 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Lesson5/VertexLit.shader: -------------------------------------------------------------------------------- 1 | Shader "_Shaders/Vertex Lit" 2 | { 3 | Properties 4 | { 5 | _MainTex ( "Base (RGB)", 2D ) = "white" {} 6 | _Color( "Diffuse Material Color", Color ) = ( 1.0, 1.0, 1.0, 1.0 ) 7 | } 8 | 9 | SubShader 10 | { 11 | Tags { "LightMode" = "ForwardBase" } 12 | 13 | Pass 14 | { 15 | CGPROGRAM 16 | #pragma exclude_renderers ps3 xbox360 17 | #pragma fragmentoption ARB_precision_hint_fastest 18 | #pragma vertex vert 19 | #pragma fragment frag 20 | 21 | #include "UnityCG.cginc" 22 | #include "../Shared/Prime31.cginc" 23 | 24 | 25 | // uniforms 26 | uniform sampler2D _MainTex; 27 | uniform float4 _MainTex_ST; 28 | uniform fixed4 _Color; 29 | uniform fixed4 _LightColor0; 30 | 31 | 32 | struct vertexInput 33 | { 34 | float4 vertex : POSITION; // position (in object coordinates, i.e. local or model coordinates) 35 | float3 normal : NORMAL; // surface normal vector (in object coordinates; usually normalized to unit length) 36 | float4 texcoord : TEXCOORD0; // 0th set of texture coordinates (a.k.a. “UV”; between 0 and 1) 37 | }; 38 | 39 | 40 | struct fragmentInput 41 | { 42 | float4 pos : SV_POSITION; 43 | float4 color : COLOR0; 44 | half2 uv : TEXCOORD0; 45 | }; 46 | 47 | 48 | fragmentInput vert( vertexInput i ) 49 | { 50 | fragmentInput o; 51 | o.pos = mul( UNITY_MATRIX_MVP, i.vertex ); 52 | o.uv = TRANSFORM_TEX( i.texcoord, _MainTex ); 53 | 54 | // first off, we need the normal to be in world space 55 | float3 normalDirection = NORMAL_TO_WORLD( i.normal ); 56 | 57 | // we will only be dealing with a single directional light 58 | float3 lightDirection = normalize( _WorldSpaceLightPos0.xyz ); 59 | 60 | 61 | // calculate diffuse lighting = IncomingLight * DiffuseColor * ( N dot L ) 62 | // we use max in case the dot is negative which would indicate the light is on the wrong side 63 | float ndotl = dot( normalDirection, lightDirection ); 64 | float3 diffuse = _LightColor0.xyz * _Color.rgb * max( 0.0, ndotl ); 65 | 66 | o.color = half4( diffuse, 1.0 ); 67 | 68 | return o; 69 | } 70 | 71 | 72 | half4 frag( fragmentInput i ) : COLOR 73 | { 74 | return tex2D( _MainTex, i.uv ) * i.color; 75 | } 76 | 77 | ENDCG 78 | } // end Pass 79 | } // end SubShader 80 | 81 | FallBack "Diffuse" 82 | } 83 | -------------------------------------------------------------------------------- /Assets/Lesson5/VertexLit.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 439b8fafe9a7445d7b9f6551a5b36c96 3 | ShaderImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Lesson6.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b4718e4a2dc574b23a2bbeffa6a03bdb 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/Lesson6/Lesson6.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/UnityCgShaderTutorials/b99050c9da04829ec665e54d4c4b8c5fd26e5c88/Assets/Lesson6/Lesson6.unity -------------------------------------------------------------------------------- /Assets/Lesson6/Lesson6.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 84e5ac04f6eb946f8a84d899d6da9d84 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Lesson6/VetexLitSpecular.shader: -------------------------------------------------------------------------------- 1 | Shader "_Shaders/Vertex Lit Specular" 2 | { 3 | Properties 4 | { 5 | _MainTex ( "Base (RGB)", 2D ) = "white" {} 6 | _Color( "Diffuse Material Color", Color ) = ( 1.0, 1.0, 1.0, 1.0 ) 7 | _SpecColor( "Specular Material Color", Color ) = ( 1, 1, 1, 1 ) 8 | _Shininess( "Shininess", Float ) = 10 9 | } 10 | 11 | SubShader 12 | { 13 | Tags { "LightMode" = "ForwardBase" } 14 | 15 | Pass 16 | { 17 | CGPROGRAM 18 | #pragma exclude_renderers ps3 xbox360 19 | #pragma fragmentoption ARB_precision_hint_fastest 20 | #pragma vertex vert 21 | #pragma fragment frag 22 | 23 | #include "UnityCG.cginc" 24 | #include "../Shared/Prime31.cginc" 25 | 26 | 27 | 28 | 29 | // uniforms 30 | uniform sampler2D _MainTex; 31 | uniform float4 _MainTex_ST; 32 | uniform fixed4 _Color; 33 | uniform fixed4 _LightColor0; 34 | uniform fixed4 _SpecColor; 35 | uniform float _Shininess; 36 | 37 | 38 | struct vertexInput 39 | { 40 | float4 vertex : POSITION; 41 | float3 normal : NORMAL; 42 | float4 texcoord : TEXCOORD0; 43 | }; 44 | 45 | 46 | struct fragmentInput 47 | { 48 | float4 pos : SV_POSITION; 49 | float4 color : COLOR0; 50 | half2 uv : TEXCOORD0; 51 | }; 52 | 53 | 54 | fragmentInput vert( vertexInput i ) 55 | { 56 | fragmentInput o; 57 | o.pos = mul( UNITY_MATRIX_MVP, i.vertex ); 58 | o.uv = TRANSFORM_TEX( i.texcoord, _MainTex ); 59 | 60 | // first off, we need the normal to be in world space 61 | float3 normalDirection = NORMAL_TO_WORLD( i.normal ); 62 | 63 | // we will only be dealing with a single directional light 64 | float3 lightDirection = WorldSpaceLightDir( i.vertex ); 65 | 66 | // dir lights will have a length of 1 due to them being already normalized 67 | // point lights attenuation will fall off as their distance grows 68 | float attenuation = 1.0 / length( lightDirection ); 69 | lightDirection = normalize( lightDirection ); 70 | 71 | // calculate diffuse lighting = IncomingLight * DiffuseColor * ( N dot L ) 72 | // we use max in case the dot is negative which would indicate the light is on the wrong side 73 | float ndotl = dot( normalDirection, lightDirection ); 74 | float3 diffuse = attenuation * _LightColor0.rgb * _Color.rgb * max( 0.0, ndotl ); 75 | 76 | 77 | float3 viewDirection = WorldSpaceViewDir( i.vertex ); 78 | float3 specularReflection; 79 | 80 | // check to make sure the light source is on the correct side 81 | if( ndotl > 0 ) 82 | { 83 | float3 reflection = reflect( -lightDirection, normalDirection ); 84 | float4 rdotv = pow( max( 0.0, dot( reflection, viewDirection ) ), _Shininess ); 85 | specularReflection = attenuation * _LightColor0.rgb * _SpecColor.rgb * rdotv; 86 | } 87 | else 88 | { 89 | specularReflection = float3( 0.0, 0.0, 0.0 ); 90 | } 91 | 92 | float3 ambientLighting = UNITY_LIGHTMODEL_AMBIENT.rgb * _Color.rgb; 93 | o.color = float4( ambientLighting + diffuse + specularReflection, 1.0 ); 94 | 95 | return o; 96 | } 97 | 98 | 99 | half4 frag( fragmentInput i ) : COLOR 100 | { 101 | return tex2D( _MainTex, i.uv ) * i.color; 102 | } 103 | 104 | ENDCG 105 | } // end Pass 106 | } // end SubShader 107 | 108 | FallBack "Diffuse" 109 | } 110 | -------------------------------------------------------------------------------- /Assets/Lesson6/VetexLitSpecular.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bb2f458d3d6584a80b36a0b751c426a8 3 | ShaderImporter: 4 | defaultTextures: [] 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/Shared.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3c40044b1dbff4134bd0a6a412377eb8 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Shared/Prime31.cginc: -------------------------------------------------------------------------------- 1 | 2 | #define NORMAL_TO_WORLD( normal ) normalize( mul( float4( normal, 1.0 ), _World2Object ).xyz ) -------------------------------------------------------------------------------- /Assets/Shared/Prime31.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 58db48142b3944ac9836604f0b2f29b3 3 | ShaderImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Shared/Templates.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7ef76ace3892140b9bf55db384d1d3b8 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Shared/Templates/BasicTemplate.shader: -------------------------------------------------------------------------------- 1 | Shader "_Shaders/BasicTemplate" 2 | { 3 | Properties 4 | { 5 | //_Color ( "Tint Color", Color ) = ( 1.0, 1.0, 1.0, 1.0 ) 6 | } 7 | 8 | SubShader 9 | { 10 | //Tags { "RenderType" = "Transparent" } 11 | Tags { "RenderType" = "Opaque" } 12 | 13 | //Blend SrcAlpha OneMinusSrcAlpha 14 | 15 | Pass 16 | { 17 | CGPROGRAM 18 | #pragma exclude_renderers ps3 xbox360 19 | #pragma fragmentoption ARB_precision_hint_fastest 20 | #pragma vertex vert 21 | #pragma fragment frag 22 | 23 | #include "UnityCG.cginc" 24 | 25 | 26 | // uniforms 27 | uniform fixed4 _Color; 28 | 29 | 30 | struct vertexInput 31 | { 32 | float4 vertex : POSITION; // position (in object coordinates, i.e. local or model coordinates) 33 | float4 tangent : TANGENT; // vector orthogonal to the surface normal 34 | float3 normal : NORMAL; // surface normal vector (in object coordinates; usually normalized to unit length) 35 | float4 texcoord : TEXCOORD0; // 0th set of texture coordinates (a.k.a. “UV”; between 0 and 1) 36 | float4 texcoord1 : TEXCOORD1; // 1st set of texture coordinates (a.k.a. “UV”; between 0 and 1) 37 | fixed4 color : COLOR; // vertex color 38 | }; 39 | 40 | 41 | struct fragmentInput 42 | { 43 | float4 pos : SV_POSITION; 44 | float4 color : COLOR0; 45 | half2 uv : TEXCOORD0; 46 | }; 47 | 48 | 49 | fragmentInput vert( vertexInput i ) 50 | { 51 | fragmentInput o; 52 | o.pos = mul( UNITY_MATRIX_MVP, i.vertex ); 53 | o.color = _Color; 54 | 55 | return o; 56 | } 57 | 58 | 59 | half4 frag( fragmentInput i ) : COLOR 60 | { 61 | return i.color; 62 | } 63 | 64 | ENDCG 65 | } // end Pass 66 | } // end SubShader 67 | 68 | FallBack "Diffuse" 69 | } 70 | -------------------------------------------------------------------------------- /Assets/Shared/Templates/BasicTemplate.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 302e22a3e04214b219a2abdd8157d28c 3 | ShaderImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Shared/Templates/SceneTemplate.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/UnityCgShaderTutorials/b99050c9da04829ec665e54d4c4b8c5fd26e5c88/Assets/Shared/Templates/SceneTemplate.unity -------------------------------------------------------------------------------- /Assets/Shared/Templates/SceneTemplate.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 44f176be85a864d19adc025c5e9c0d6b 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Shared/Templates/Template.shader: -------------------------------------------------------------------------------- 1 | Shader "_Shaders/Template" 2 | { 3 | Properties 4 | { 5 | _MainTex ( "Base (RGB)", 2D ) = "white" {} 6 | _Color ( "Tint Color", Color ) = ( 1.0, 1.0, 1.0, 1.0 ) 7 | } 8 | 9 | SubShader 10 | { 11 | Tags { "Queue" = "Geometry" } 12 | //Tags { "Queue" = "Transparent" } 13 | //ZWrite Off 14 | 15 | // Blend modes equation: SrcFactor * fragment_output + DstFactor * pixel_color; 16 | // Blend {code for SrcFactor} {code for DstFactor} 17 | 18 | //Blend SrcAlpha OneMinusSrcAlpha // alpha blending 19 | //Blend One OneMinusSrcAlpha // premultiplied alpha blending 20 | //Blend One One // additive 21 | //Blend SrcAlpha One // additive blending 22 | //Blend OneMinusDstColor One // soft additive 23 | //Blend DstColor Zero // multiplicative 24 | //Blend DstColor SrcColor // 2x multiplicative 25 | //Blend Zero SrcAlpha // multiplicative blending for attenuation by the fragment's alpha 26 | 27 | //ZWrite Off // don't write to depth buffer in order not to occlude other objects 28 | 29 | Pass 30 | { 31 | CGPROGRAM 32 | #pragma exclude_renderers ps3 xbox360 33 | #pragma fragmentoption ARB_precision_hint_fastest 34 | #pragma vertex vert 35 | #pragma fragment frag 36 | 37 | #include "UnityCG.cginc" 38 | 39 | 40 | // uniforms 41 | sampler2D _MainTex; 42 | uniform float4 _MainTex_ST; 43 | uniform fixed4 _Color; 44 | 45 | 46 | struct vertexInput 47 | { 48 | float4 vertex : POSITION; // position (in object coordinates, i.e. local or model coordinates) 49 | float4 tangent : TANGENT; // vector orthogonal to the surface normal 50 | float3 normal : NORMAL; // surface normal vector (in object coordinates; usually normalized to unit length) 51 | float4 texcoord : TEXCOORD0; // 0th set of texture coordinates (a.k.a. “UV”; between 0 and 1) 52 | float4 texcoord1 : TEXCOORD1; // 1st set of texture coordinates (a.k.a. “UV”; between 0 and 1) 53 | fixed4 color : COLOR; // vertex color 54 | }; 55 | 56 | 57 | struct fragmentInput 58 | { 59 | float4 pos : SV_POSITION; 60 | float4 color : COLOR0; 61 | half2 uv : TEXCOORD0; 62 | }; 63 | 64 | 65 | fragmentInput vert( vertexInput i ) 66 | { 67 | fragmentInput o; 68 | o.pos = mul( UNITY_MATRIX_MVP, i.vertex ); 69 | o.uv = TRANSFORM_TEX( i.texcoord, _MainTex ); 70 | o.color = _Color; 71 | 72 | // debug: uncomment the desired item to debug then return i.color directly in the fragment shader 73 | //o.color = i.texcoord; 74 | //o.color = i.vertex; 75 | //o.color = i.vertex + float4( 0.5, 0.5, 0.5, 0.0 ); // we add 0.5's to offset if the model verts go from -0.5 - 0.5 76 | //o.color = i.tangent; 77 | //o.color = float4( i.normal, 1.0 ); 78 | //o.color = i.texcoord; 79 | //o.color = i.texcoord1; 80 | //o.color = i.color; // vertex colors 81 | 82 | return o; 83 | } 84 | 85 | 86 | half4 frag( fragmentInput i ) : COLOR 87 | { 88 | i.color = tex2D( _MainTex, i.uv ) * i.color; 89 | return i.color; 90 | } 91 | 92 | ENDCG 93 | } // end Pass 94 | } // end SubShader 95 | 96 | FallBack "Diffuse" 97 | } 98 | -------------------------------------------------------------------------------- /Assets/Shared/Templates/Template.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 01a280c2df1a640fabbd03b6b8767b02 3 | ShaderImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Shared/Textures.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 83fc6bc94382f46a984f45a73266f5ea 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Shared/Textures/Brick.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/UnityCgShaderTutorials/b99050c9da04829ec665e54d4c4b8c5fd26e5c88/Assets/Shared/Textures/Brick.jpg -------------------------------------------------------------------------------- /Assets/Shared/Textures/Brick.jpg.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b4f922b1a54504d4299ca0d9ef37dc36 3 | TextureImporter: 4 | serializedVersion: 2 5 | mipmaps: 6 | mipMapMode: 0 7 | enableMipMap: 1 8 | linearTexture: 0 9 | correctGamma: 0 10 | fadeOut: 0 11 | borderMipMap: 0 12 | mipMapFadeDistanceStart: 1 13 | mipMapFadeDistanceEnd: 3 14 | bumpmap: 15 | convertToNormalMap: 0 16 | externalNormalMap: 0 17 | heightScale: .25 18 | normalMapFilter: 0 19 | isReadable: 0 20 | grayScaleToAlpha: 0 21 | generateCubemap: 0 22 | seamlessCubemap: 0 23 | textureFormat: -1 24 | maxTextureSize: 1024 25 | textureSettings: 26 | filterMode: -1 27 | aniso: -1 28 | mipBias: -1 29 | wrapMode: -1 30 | nPOTScale: 1 31 | lightmap: 0 32 | compressionQuality: 50 33 | textureType: -1 34 | buildTargetSettings: [] 35 | userData: 36 | -------------------------------------------------------------------------------- /Assets/Shared/Textures/Brick_NORM.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/UnityCgShaderTutorials/b99050c9da04829ec665e54d4c4b8c5fd26e5c88/Assets/Shared/Textures/Brick_NORM.tga -------------------------------------------------------------------------------- /Assets/Shared/Textures/Brick_NORM.tga.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cb0bde51b1ab445bfb4f5bc0b82ec901 3 | TextureImporter: 4 | serializedVersion: 2 5 | mipmaps: 6 | mipMapMode: 0 7 | enableMipMap: 1 8 | linearTexture: 0 9 | correctGamma: 0 10 | fadeOut: 0 11 | borderMipMap: 0 12 | mipMapFadeDistanceStart: 1 13 | mipMapFadeDistanceEnd: 3 14 | bumpmap: 15 | convertToNormalMap: 0 16 | externalNormalMap: 0 17 | heightScale: .25 18 | normalMapFilter: 0 19 | isReadable: 0 20 | grayScaleToAlpha: 0 21 | generateCubemap: 0 22 | seamlessCubemap: 0 23 | textureFormat: -1 24 | maxTextureSize: 1024 25 | textureSettings: 26 | filterMode: -1 27 | aniso: -1 28 | mipBias: -1 29 | wrapMode: -1 30 | nPOTScale: 1 31 | lightmap: 0 32 | compressionQuality: 50 33 | textureType: -1 34 | buildTargetSettings: [] 35 | userData: 36 | -------------------------------------------------------------------------------- /Assets/Shared/Textures/Fern.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/UnityCgShaderTutorials/b99050c9da04829ec665e54d4c4b8c5fd26e5c88/Assets/Shared/Textures/Fern.psd -------------------------------------------------------------------------------- /Assets/Shared/Textures/Fern.psd.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ecf31044075334ccb9af1e3f7676df3a 3 | TextureImporter: 4 | serializedVersion: 2 5 | mipmaps: 6 | mipMapMode: 0 7 | enableMipMap: 1 8 | linearTexture: 0 9 | correctGamma: 0 10 | fadeOut: 0 11 | borderMipMap: 0 12 | mipMapFadeDistanceStart: 1 13 | mipMapFadeDistanceEnd: 3 14 | bumpmap: 15 | convertToNormalMap: 0 16 | externalNormalMap: 0 17 | heightScale: .25 18 | normalMapFilter: 0 19 | isReadable: 0 20 | grayScaleToAlpha: 0 21 | generateCubemap: 0 22 | seamlessCubemap: 0 23 | textureFormat: -1 24 | maxTextureSize: 1024 25 | textureSettings: 26 | filterMode: -1 27 | aniso: -1 28 | mipBias: -1 29 | wrapMode: -1 30 | nPOTScale: 1 31 | lightmap: 0 32 | compressionQuality: 50 33 | textureType: -1 34 | buildTargetSettings: [] 35 | userData: 36 | -------------------------------------------------------------------------------- /Assets/Shared/Textures/GlassBreak.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/UnityCgShaderTutorials/b99050c9da04829ec665e54d4c4b8c5fd26e5c88/Assets/Shared/Textures/GlassBreak.jpg -------------------------------------------------------------------------------- /Assets/Shared/Textures/GlassBreak.jpg.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3cf63764f75dc4420b207c5b493dced9 3 | TextureImporter: 4 | serializedVersion: 2 5 | mipmaps: 6 | mipMapMode: 0 7 | enableMipMap: 1 8 | linearTexture: 0 9 | correctGamma: 0 10 | fadeOut: 0 11 | borderMipMap: 0 12 | mipMapFadeDistanceStart: 1 13 | mipMapFadeDistanceEnd: 3 14 | bumpmap: 15 | convertToNormalMap: 0 16 | externalNormalMap: 0 17 | heightScale: .25 18 | normalMapFilter: 0 19 | isReadable: 0 20 | grayScaleToAlpha: 0 21 | generateCubemap: 0 22 | seamlessCubemap: 0 23 | textureFormat: -1 24 | maxTextureSize: 1024 25 | textureSettings: 26 | filterMode: -1 27 | aniso: -1 28 | mipBias: -1 29 | wrapMode: -1 30 | nPOTScale: 1 31 | lightmap: 0 32 | compressionQuality: 50 33 | textureType: -1 34 | buildTargetSettings: [] 35 | userData: 36 | -------------------------------------------------------------------------------- /Assets/Shared/Textures/earth.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/UnityCgShaderTutorials/b99050c9da04829ec665e54d4c4b8c5fd26e5c88/Assets/Shared/Textures/earth.png -------------------------------------------------------------------------------- /Assets/Shared/Textures/earth.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5950b3d83f73d48f39c1c2f12b165710 3 | TextureImporter: 4 | serializedVersion: 2 5 | mipmaps: 6 | mipMapMode: 0 7 | enableMipMap: 1 8 | linearTexture: 0 9 | correctGamma: 0 10 | fadeOut: 0 11 | borderMipMap: 0 12 | mipMapFadeDistanceStart: 1 13 | mipMapFadeDistanceEnd: 3 14 | bumpmap: 15 | convertToNormalMap: 0 16 | externalNormalMap: 0 17 | heightScale: .25 18 | normalMapFilter: 0 19 | isReadable: 0 20 | grayScaleToAlpha: 0 21 | generateCubemap: 0 22 | seamlessCubemap: 0 23 | textureFormat: -1 24 | maxTextureSize: 1024 25 | textureSettings: 26 | filterMode: -1 27 | aniso: -1 28 | mipBias: -1 29 | wrapMode: -1 30 | nPOTScale: 1 31 | lightmap: 0 32 | compressionQuality: 50 33 | textureType: -1 34 | buildTargetSettings: [] 35 | userData: 36 | -------------------------------------------------------------------------------- /Assets/TesterMaterial.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/UnityCgShaderTutorials/b99050c9da04829ec665e54d4c4b8c5fd26e5c88/Assets/TesterMaterial.mat -------------------------------------------------------------------------------- /Assets/TesterMaterial.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 733a5a43661464b4180441ded51ac837 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/UnityCgShaderTutorials/b99050c9da04829ec665e54d4c4b8c5fd26e5c88/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/UnityCgShaderTutorials/b99050c9da04829ec665e54d4c4b8c5fd26e5c88/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/UnityCgShaderTutorials/b99050c9da04829ec665e54d4c4b8c5fd26e5c88/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/UnityCgShaderTutorials/b99050c9da04829ec665e54d4c4b8c5fd26e5c88/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/UnityCgShaderTutorials/b99050c9da04829ec665e54d4c4b8c5fd26e5c88/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/UnityCgShaderTutorials/b99050c9da04829ec665e54d4c4b8c5fd26e5c88/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/NavMeshLayers.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/UnityCgShaderTutorials/b99050c9da04829ec665e54d4c4b8c5fd26e5c88/ProjectSettings/NavMeshLayers.asset -------------------------------------------------------------------------------- /ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/UnityCgShaderTutorials/b99050c9da04829ec665e54d4c4b8c5fd26e5c88/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/UnityCgShaderTutorials/b99050c9da04829ec665e54d4c4b8c5fd26e5c88/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/UnityCgShaderTutorials/b99050c9da04829ec665e54d4c4b8c5fd26e5c88/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/UnityCgShaderTutorials/b99050c9da04829ec665e54d4c4b8c5fd26e5c88/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prime31/UnityCgShaderTutorials/b99050c9da04829ec665e54d4c4b8c5fd26e5c88/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | UnityCgShaderTutorials 2 | ====================== 3 | 4 | Source code for the Unity Cg Shaders tutorial series on YouTube: http://www.youtube.com/playlist?list=PLb8LPjN5zpx1tauZfNE1cMIIPy15UlJNZ -------------------------------------------------------------------------------- /Shaders.userprefs: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | --------------------------------------------------------------------------------