Unity3d Reflection Matte for Shaderlab cube graphs
On a simple introduction to the reflection of the cube diagram, can we use a question to specify the mask? This way the artist can better control the effect of the image.
We then use the previous shader Code, create a new material ball, this modification is also a few lines of code, so look directly at the completion of the code.
Code Start--------------------------------------------------------------------
Shader "91ygame/cubemask" {
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
Add masks;
_reflmask ("Reflection Mask", 2D) = "" "{}
}
Subshader {
Tags {"Rendertype" = "Opaque"}
LOD 200
Cgprogram
#pragma surface surf Lambert
Sampler2d _maintex;
Samplercube _cubemap;
FLOAT4 _maintint;
float _reflamount;
Add mask variable;
Sampler2d _reflmask;
struct Input {
FLOAT2 Uv_maintex;
FLOAT3 WORLDREFL;
};
void Surf (Input in, InOut surfaceoutput o) {
Half4 C = tex2d (_maintex, In.uv_maintex);
FLOAT3 reflection = Texcube (_CUBEMAP,IN.WORLDREFL). RGB;
Obtain a mask;
FLOAT4 reflmask = tex2d (_reflmask,in.uv_maintex);
O.albedo = C.rgb*_maintint;
O.emission = (REFLECTION*REFLMASK.R) *_reflamount;
O.alpha = C.A;
}
Endcg
}
FallBack "Diffuse"
}
Code End----------------------------------------------------------------------
The final effect is as follows, with the latest matte effect on the left and the effect without masking on the right:
In summary, it appears that, on the basis of the previous article, it was slightly modified, it first uses the texcube function to sample the cube graph, this function is CGFX built-in function.
He returned for us the color of the cube-chart, in passing Unity built -in WORLDREFL The properties help us pass the reflection vector. We then use the TEX2D function to sample the mask map .
Once you have done this, multiply the color of the cube graph by the reflected texture color value and pass the resulting value to the surface shader Output of the structural body emission property.
Finally, we multiply the value of the reflection mask by our Reflamount parameters. We realized the reflection matte of the cubic diagram.
Unity3d reflection Matte for Shaderlab cube graphs