Unity3d Shaderlab Simple Cube-chart reflection
Reflection is a key factor in a shader's simulation of a real-world environment that makes our shader rendering more visually striking because he takes advantage of the environment around us,
Let the shader reflect the outside scene information and reflect them to the material surface to simulate the external environment, so we will use the cubic graph "CubeMap" 6 textures to simulate the color situation of the environment.
First, create a Shader, create a material ball, prepare a cubic diagram, double-click Shader, and go to the Code Editor.
From the Properties to the cgprogram, and then to the surf, this function is relatively simple, first look at the code.
Code Start-----------------------------------------------------------------------
Shader "91ygame/cube1" {
Properties {
_maintint ("Diffuse Tint", Color) = (1,1,1,1)
_maintex ("Base (RGB)", 2D) = "White" {}
_cubemap ("CubeMap", CUBE) = "" "{}
_reflamount ("Reflection Amount", Range (0.1,3)) =0.5
}
Subshader {
Tags {"Rendertype" = "Opaque"}
LOD 200
Cgprogram
#pragma surface surf Lambert
Sampler2d _maintex;
Samplercube _cubemap;
FLOAT4 _maintint;
float _reflamount;
struct Input {
FLOAT2 Uv_maintex;
FLOAT3 WORLDREFL;
};
void Surf (Input in, InOut surfaceoutput o) {
Half4 C = tex2d (_maintex, In.uv_maintex) *_maintint;
O.emission = Texcube (_CUBEMAP,IN.WORLDREFL). Rgb*_reflamount;
O.albedo = C.rgb;
O.alpha = C.A;
}
Endcg
}
FallBack "Diffuse"
}
Code End------------------------------------------------------------------------
With the simple modifications above, we also have a simple in-traditional reflection effect, which can be viewed directly in Unity.
In summary, the shader samples the cubic graph and gets a similar real-world reflection.
This is thanks to Unity 's built -in worldrefl attribute in the surface shader's Input structure , which provides us with the necessary reflection vectors directly.
Help us to sample the cubic chart correctly. We only need to use the WORLDREFL variable in the texcube function to get the correct reflection graph.
Unity3d Shaderlab Simple Cube-chart reflection