Advertisemen
Hey guys, In this tutorial, I will show you guys how to script basic shader in unity. This one doesn't include physically base shaders. I will make tutorials on that in my later tutorials.
Here is the script used in this video :
Shader "Tutorial/basicShaderOne" // folder name
{
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
AmColor("Ambient Color", Color) = (1, 1, 1, 1)
Multiplier("Color Multiplier", Range(0, 10)) = 2.5
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert
float4 _Color;
float4 AmColor;
float Multiplier;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o) {
float4 c = pow((_Color + AmColor), Multiplier); // pow(x, y), result is y multiplies x
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
{
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
AmColor("Ambient Color", Color) = (1, 1, 1, 1)
Multiplier("Color Multiplier", Range(0, 10)) = 2.5
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert
float4 _Color;
float4 AmColor;
float Multiplier;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o) {
float4 c = pow((_Color + AmColor), Multiplier); // pow(x, y), result is y multiplies x
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
Basically shader has two divisions "Properties" and "SubShader". Inside the Properties, we give variables a value which we are going to declare inside SubShader. Leave the rest as it is other than the codes I deleted in the video because these are house keeping stuffs.
Advertisemen
Tidak ada komentar:
Posting Komentar