Unity3d reflection Matte for Shaderlab cube graphs

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.