Scripting basic shader in Unity 3D

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) = (1111)
        Multiplier("Color Multiplier"Range(010)) = 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 INinout SurfaceOutput o) {
            float4 c = pow((_Color + AmColor), Multiplier); // pow(xy), 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

Disclaimer: Gambar, artikel ataupun video yang ada di web ini terkadang berasal dari berbagai sumber media lain. Hak Cipta sepenuhnya dipegang oleh sumber tersebut. Jika ada masalah terkait hal ini, Anda dapat menghubungi kami disini.

Tidak ada komentar:

Posting Komentar

© Copyright 2017 Tutorial Unity 3D