Last active
October 20, 2021 06:05
-
-
Save danamuise/8e8b01a3ebeac11db5f1e4c749191e7d to your computer and use it in GitHub Desktop.
My basic HLSL Shaders written from scratch
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
Shader "custom/StandardSpecularPBR" | |
{ | |
Properties | |
{ | |
_Color ("Color", Color) = (1,1,1,1) | |
_MetallicTex ("Metallic (R)", 2D) = "white" {} | |
_SpecColor ("Specular Color", Color) = (1, 1, 1, 1) | |
} | |
SubShader | |
{ | |
Tags { "RenderType"="Opaque" } | |
CGPROGRAM | |
// Physically based Standard lighting model, and enable shadows on all light types | |
#pragma surface surf StandardSpecular fullforwardshadows | |
// Use shader model 3.0 target, to get nicer looking lighting | |
#pragma target 3.0 | |
fixed4 _Color; | |
sampler2D _MetallicTex; | |
struct Input | |
{ | |
float2 uv_MetallicTex; | |
}; | |
// Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader. | |
// See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing. | |
// #pragma instancing_options assumeuniformscaling | |
UNITY_INSTANCING_BUFFER_START(Props) | |
// put more per-instance properties here | |
UNITY_INSTANCING_BUFFER_END(Props) | |
void surf (Input IN, inout SurfaceOutputStandardSpecular o) | |
{ | |
o.Albedo = _Color.rgb; | |
// Metallic and smoothness come from slider variables | |
o.Specular = _SpecColor; | |
o.Smoothness = tex2D (_MetallicTex, IN.uv_MetallicTex); | |
} | |
ENDCG | |
} | |
FallBack "Diffuse" | |
} |
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
Shader "Custom/Leaves" { | |
Properties{ | |
_MainTex ("MainTex", 2D) = "white" {} | |
} | |
SubShader{ | |
Tags{ | |
"Queue" = "Transparent" | |
} | |
CGPROGRAM | |
#pragma surface surf Lambert alpha:fade | |
sampler2D _MainTex; | |
struct Input { | |
float2 uv_MainTex; | |
}; | |
void surf(Input IN, inout SurfaceOutput o) { | |
fixed4 c = tex2D(_MainTex, IN.uv_MainTex); | |
o.Albedo = c.rgb; | |
o.Alpha = c.a; | |
} | |
ENDCG | |
} | |
FallBack "Diffuse" | |
} |
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
Shader "Custom/bumpDiffuse" | |
{ | |
Properties | |
{ | |
_MyDiffuse ("Diffuse Texture", 2D) = "white" {} | |
_MyNormal ("Normal Texture", 2D) = "bump" {} | |
_MySlider ("Normal height", Range(0, 10)) = 1 | |
_MyBrightness("Brightness", Range(0, 10)) = 1 | |
_MyCubeMap("Cube map", CUBE) = "white" {} | |
} | |
SubShader | |
{ | |
CGPROGRAM | |
#pragma surface surf Lambert | |
sampler2D _MyDiffuse; | |
sampler2D _MyNormal; | |
samplerCUBE _MyCubeMap; | |
half _MySlider; | |
half _MyBrightness; | |
struct Input | |
{ | |
float2 uv_MyDiffuse; | |
float2 uv_MyNormal; | |
float3 worldRefl; INTERNAL_DATA | |
}; | |
void surf (Input IN, inout SurfaceOutput o) | |
{ | |
o.Albedo = tex2D(_MyDiffuse, IN.uv_MyDiffuse).rgb; | |
//o.Albedo = texCUBE(_MyCubeMap, IN.worldRefl).rgb; | |
o.Normal = UnpackNormal(tex2D(_MyNormal, IN.uv_MyNormal)) * _MyBrightness; | |
o.Normal *= float3(_MySlider, _MySlider, 1); | |
o.Emission = texCUBE (_MyCubeMap, WorldReflectionVector(IN, o.Normal)).rgb; | |
} | |
ENDCG | |
} | |
FallBack "Diffuse" | |
} |
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
Shader "Custom/RimShader" | |
{ | |
Properties | |
{ | |
_RimColor ("Rim Color", Color) = (0.0, 0.5, 0.5, 0.0) | |
_RimPower("Rim power", Range(0.5, 8.0)) = 3.0 | |
} | |
SubShader | |
{ | |
CGPROGRAM | |
#pragma surface surf Lambert | |
struct Input | |
{ | |
float3 viewDir; | |
float3 worldPos; | |
}; | |
float4 _RimColor; | |
float _RimPower; | |
void surf (Input IN, inout SurfaceOutput o) | |
{ | |
//we don't care about dot products < 0 | |
// SATURATE: clamp a value between 0 & 1 | |
half rim = 1- saturate(dot(normalize(IN.viewDir), o.Normal)); | |
//control gradient drop-off uses power function | |
//o.Emission = _RimColor.rgb * pow(rim, _RimPower); | |
//create conditional statement | |
// o.Emission = rim > 0.5 ? float3(1, 0, 0) : rim > 0.3 ? float3(0,1,0): 0; | |
//if pixel y position > 5 paint green, otherwise red | |
// o.Emission = IN.worldPos.y > 5 ? float3(0, 1, 0) : float3(1, 0, 0); | |
//frac= mod: frac(2, 3) = 0.66 | |
//mult Y by 10 to scale up, divide by 2 (mult by 0.5) | |
o.Emission = frac(IN.worldPos.y *10 / 10) > 0.4 ? float3(0, 1, 0) * rim : float3(1, 0, 0) * rim; | |
} | |
ENDCG | |
} | |
FallBack "Diffuse" | |
} |
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
Shader "Custom/HologramShader" | |
{ | |
Properties | |
{ | |
_RimColor ("Rim Color", Color) = (0.0, 0.5, 0.5, 0.0) | |
_RimPower("Rim power", Range(0.5, 8.0)) = 3.0 | |
} | |
SubShader | |
{ | |
Tags{ "Queue" = "Transparent"} | |
//RENDER PASS prevents internal geometry from showing up | |
Pass{ | |
ZWrite On | |
ColorMask 0 | |
} | |
CGPROGRAM | |
#pragma surface surf Lambert alpha:fade | |
struct Input | |
{ | |
float3 viewDir; | |
}; | |
float4 _RimColor; | |
float _RimPower; | |
void surf (Input IN, inout SurfaceOutput o) | |
{ | |
//we don't care about dot products < 0 | |
// SATURATE: clamp a value between 0 & 1 | |
half rim = 1.0 - saturate(dot(normalize(IN.viewDir), o.Normal)); | |
o.Emission = _RimColor.rgb * pow(rim, _RimPower) * 10; | |
o.Alpha = pow (rim, _RimPower); | |
} | |
ENDCG | |
} | |
FallBack "Diffuse" | |
} |
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
Shader "Custom/StandardPBR" | |
{ | |
Properties | |
{ | |
_Color ("Color", Color) = (1,1,1,1) | |
_MetallicTex ("Metallic (R)", 2D) = "white" {} | |
_Metallic ("Metallic", Range(0,1)) = 0.0 | |
} | |
SubShader | |
{ | |
Tags { "RenderType"="Opaque" } | |
CGPROGRAM | |
// Physically based Standard lighting model, and enable shadows on all light types | |
#pragma surface surf Standard fullforwardshadows | |
// Use shader model 3.0 target, to get nicer looking lighting | |
#pragma target 3.0 | |
fixed4 _Color; | |
sampler2D _MetallicTex; | |
half _Metallic; | |
struct Input | |
{ | |
float2 uv_MetallicTex; | |
}; | |
// Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader. | |
// See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing. | |
// #pragma instancing_options assumeuniformscaling | |
UNITY_INSTANCING_BUFFER_START(Props) | |
// put more per-instance properties here | |
UNITY_INSTANCING_BUFFER_END(Props) | |
void surf (Input IN, inout SurfaceOutputStandard o) | |
{ | |
o.Albedo = _Color.rgb; | |
// Metallic and smoothness come from slider variables | |
o.Metallic = _Metallic; | |
o.Smoothness = tex2D (_MetallicTex, IN.uv_MetallicTex); | |
} | |
ENDCG | |
} | |
FallBack "Diffuse" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment