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
9 changes: 9 additions & 0 deletions SpecularShader/Assets/Materials.meta

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

9 changes: 9 additions & 0 deletions SpecularShader/Assets/Materials/Shaders.meta

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

69 changes: 69 additions & 0 deletions SpecularShader/Assets/Materials/Shaders/SpecularShader.shader
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
Shader "Custom/SpecShader" {
Properties {
_Color ("Color Tint", Color) = (1,1,1,1)
_SpecColour("Specular Color", Color) = (1,1,1,1)
_Shininess("Shininess", float) = 10
}
SubShader {
Pass{
CGPROGRAM
#pragma vertex vertexFunction
#pragma fragment fragmentFunction

//user defined variables
uniform float4 _Color;
uniform float4 _SpecColour;
uniform float _Shininess;
float3 lightDirection;
float attenuation = 1.0;

//Unity Defined Variables
uniform float4 _LightColor0;

//input struct
struct inputStruct{
float4 vertexPos : POSITION;
float3 vertexNormal : NORMAL;
};

//output struct
struct outputStruct{
float4 pixelPos: SV_POSITION;
float4 pixelCol : COLOR;

float3 normalDirection : TEXCOORD0;
float4 pixelWorldPos : TEXCOORD1;
};

//vertex function
outputStruct vertexFunction(inputStruct input){
outputStruct toReturn;

float3 normalDirection = normalize(mul(float4(input.vertexNormal, 0.0), _World2Object).xyz);
toReturn.normalDirection = normalDirection;
toReturn.pixelWorldPos = float4(_WorldSpaceCameraPos.xyz, 1.0);
toReturn.pixelPos = mul(UNITY_MATRIX_MVP, input.vertexPos);

return toReturn;
}

//fragment program
float4 fragmentFunction(outputStruct input) : COLOR {
lightDirection = normalize(_WorldSpaceLightPos0.xyz);
float3 viewDirection = normalize(float3(float4(_WorldSpaceCameraPos.xyz, 1.0) - mul(_Object2World, input.pixelPos).xyz));
float3 diffuseReflection = attenuation * _LightColor0.xyz * max(0.0, dot(input.normalDirection, lightDirection));
float3 specularReflection = reflect(-lightDirection, input.normalDirection);
specularReflection = dot(specularReflection, viewDirection);
specularReflection = pow(max(0.0, specularReflection), _Shininess);
specularReflection = max(0.0, dot(input.normalDirection, lightDirection)) * specularReflection;
float3 finalLight = (specularReflection * _SpecColour) + diffuseReflection + UNITY_LIGHTMODEL_AMBIENT;
input.pixelCol = float4(finalLight * _Color, 1.0);
return input.pixelCol;
}

ENDCG
}
}
//Fallback
//FallBack "Diffuse"
}

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

Binary file not shown.
8 changes: 8 additions & 0 deletions SpecularShader/Assets/Materials/SpecularMaterial.mat.meta

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

Binary file added SpecularShader/Assets/scene.unity
Binary file not shown.
8 changes: 8 additions & 0 deletions SpecularShader/Assets/scene.unity.meta

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

Binary file added SpecularShader/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 SpecularShader/ProjectSettings/InputManager.asset
Binary file not shown.
Binary file added SpecularShader/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 SpecularShader/ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
m_EditorVersion: 5.1.2f1
m_StandardAssetsVersion: 0
Binary file not shown.
Binary file added SpecularShader/ProjectSettings/TagManager.asset
Binary file not shown.
Binary file added SpecularShader/ProjectSettings/TimeManager.asset
Binary file not shown.