Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Lab09-Shaders-vhaskin1.odt
Binary file not shown.
Binary file added Lab09-Shaders/Assets/OnYourOwnMat.mat
Binary file not shown.
8 changes: 8 additions & 0 deletions Lab09-Shaders/Assets/OnYourOwnMat.mat.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

79 changes: 79 additions & 0 deletions Lab09-Shaders/Assets/OnYourOwnShader.shader
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
Shader "OnYourOwnShader" {
//Step 1: change the color tint happens on the material
Properties {
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Diffuse Texture", 2D) = "white" {}
}
SubShader {
Pass{
Tags{"LightMode" = "ForwardBase"}
CGPROGRAM
#pragma vertex vertexFunction
#pragma fragment fragmentFunction

//user defined variables
uniform float4 _Color;
uniform sampler2D _MainTex;
uniform float4 _MainTex_ST;
uniform float3 _LightColor0;


//float4 texture = tex2D(_MainTex, _MainTex_ST.xy * input.Texture.xy + _MainTex_ST.zw);

//input struct
struct inputStruct
{
float4 vertexPos : POSITION;
float4 textureCoord : TEXCOORD0;
//ADDING TO STEP 3
float3 vertexNormal : NORMAL;
};

//output struct
struct outputStruct
{
float4 pixelPos : SV_POSITION;
float4 tex : TEXCOORD0;
//ADDING TO STEP 3
float4 colour : Color;
};

//vertex program
outputStruct vertexFunction(inputStruct input)
{
outputStruct toReturn;
float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz);
float attenuation = 1.0;
float3 ambientLight = UNITY_LIGHTMODEL_AMBIENT.rgb;

float3 tempNorm = input.vertexNormal;
float4 objNorm = mul(float4(tempNorm, 1.0), _World2Object);
float3 normalizedNorm = normalize(objNorm).xyz;

float3 normalDirection = normalize(mul(float4(input.vertexNormal, 1.0), _World2Object).xyz);
float3 diffuseReflection = attenuation * _LightColor0.xyz * _Color.rgb * max(0.0, dot(normalizedNorm, lightDirection));

float3 finalLight = diffuseReflection + ambientLight;
toReturn.colour = float4(finalLight, 1.0);

toReturn.pixelPos = mul(UNITY_MATRIX_MVP, input.vertexPos);
toReturn.tex = input.textureCoord;
return toReturn;
}

//fragment program
float4 fragmentFunction(outputStruct input) : COLOR
{
//STEP 2: FLIP TILING AND OFFSET
float4 tex = tex2D(_MainTex, _MainTex_ST.zw * input.tex.xy + _MainTex_ST.xy);
//final bit of Step 3
tex = tex * input.colour;

return tex ;
}

ENDCG
}
}
FallBack "Diffuse"
}
9 changes: 9 additions & 0 deletions Lab09-Shaders/Assets/OnYourOwnShader.shader.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Lab09-Shaders/Assets/TestMat.mat
Binary file not shown.
8 changes: 8 additions & 0 deletions Lab09-Shaders/Assets/TestMat.mat.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 77 additions & 0 deletions Lab09-Shaders/Assets/TestShader.shader
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
Shader "TestShader" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Diffuse Texture", 2D) = "white" {}
}
SubShader {
Pass{
CGPROGRAM
#pragma vertex vertexFunction
#pragma fragment fragmentFunction

//user defined variables
uniform float4 _Color;
uniform sampler2D _MainTex;
uniform float4 _MainTex_ST;


//float4 texture = tex2D(_MainTex, _MainTex_ST.xy * input.Texture.xy + _MainTex_ST.zw);

//input struct
struct inputStruct
{
float4 vertexPos : POSITION;
float4 textureCoord : TEXCOORD0;
};

//output struct
struct outputStruct
{
float4 pixelPos : SV_POSITION;
float4 tex : TEXCOORD0;
};

//vertex program
outputStruct vertexFunction(inputStruct input)
{
outputStruct toReturn;
toReturn.pixelPos = mul(UNITY_MATRIX_MVP, input.vertexPos);

//Assigning the info that the inputStruct gathered
//to the struct that will be passed into the fragment
//program so that the fragment program can use it.
toReturn.tex = input.textureCoord;
return toReturn;
}

//fragment program
float4 fragmentFunction(outputStruct input) : COLOR
{
float4 tex = tex2D(_MainTex, _MainTex_ST.xy * input.tex.xy + _MainTex_ST.zw);

return tex;
}

ENDCG
}
}
FallBack "Diffuse"
}


















10 changes: 10 additions & 0 deletions Lab09-Shaders/Assets/TestShader.shader.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Lab09-Shaders/Assets/UnityVS.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Lab09-Shaders/Assets/UnityVS/Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
guid: 38d405c119fcc7c4e83d4a478a40ff2f
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
guid: 4ad02dc83da735c4e8d945332b9202f6
Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Lab09-Shaders/Assets/testImage.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 55 additions & 0 deletions Lab09-Shaders/Assets/testImage.jpg.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Lab09-Shaders/Assets/testScene.unity
Binary file not shown.
8 changes: 8 additions & 0 deletions Lab09-Shaders/Assets/testScene.unity.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Lab09-Shaders/ProjectSettings/AudioManager.asset
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added Lab09-Shaders/ProjectSettings/InputManager.asset
Binary file not shown.
Binary file added Lab09-Shaders/ProjectSettings/NavMeshAreas.asset
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 2 additions & 0 deletions Lab09-Shaders/ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
m_EditorVersion: 5.1.3f1
m_StandardAssetsVersion: 0
Binary file not shown.
Binary file added Lab09-Shaders/ProjectSettings/TagManager.asset
Binary file not shown.
Binary file added Lab09-Shaders/ProjectSettings/TimeManager.asset
Binary file not shown.
Binary file added Untitled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.