shader-application v&f for transparent materials

Source: Internet
Author: User
Tags mul

See the wind to realize the earth is very handsome. He wrote the program is very subtle, the earth and cloud color to do an interpolation, as the color value of this pixel, very good. Worship the great God first!

Http://blog.sina.com.cn/s/blog_471132920101d6xb.html

However, I write today shader also achieve the same effect, our thinking is very conventional: the Earth as an opaque object, first rendered. Clouds are rendered as transparent body. No more nonsense to start!

Earth.shader

Shader "Custom/earth" {Properties {_maintex ("Texture", 2D) = "White" {}}subshader {tags{"Queue" = "Geometry" "Rendertype "=" Opaque "}pass {cgprogram#pragma vertex vert#pragma fragment Frag#include" Unitycg.cginc "sampler2d _maintex;struct v2f {float4  pos:sv_position;float2  uv:texcoord0;}; Float4 _maintex_st;v2f Vert (Appdata_base v) {v2f o;//the position on the viewport O.pos = Mul (UNITY_MATRIX_MVP, V.vertex);//Map texture coordinates O.UV = TRANS Form_tex (V.texcoord, _maintex); return o;} Half4 Frag (v2f i): color{//obtains a map of the Earth's UV x that is transverse in the move float u = i.uv.x + -0.1*_time;float2 x=float2 (U, i.uv.y); Half4 Texcol = Tex (_maintex, x); return texcol;} ENDCG}}}

Cloud.shader

Shader "Custom/cloud" {Properties {_maintex ("Texture", 2D) = "White" {}}subshader {tags{             "Queue" = "Transparent"              "Rendertype" = "Transparent"} Pass {             Blend srcalpha oneminussrcalpha cgprogram#pragma vertex vert#pragma fragment Frag#include "Unitycg.cginc" Sampler2d _maintex;struct v2f {float4  pos:sv_position;float2  uv:texcoord0;}; Float4 _maintex_st;v2f Vert (Appdata_base v) {v2f o;//the position on the viewport O.pos = Mul (UNITY_MATRIX_MVP, V.vertex);//Map texture coordinates O.UV = TRANS Form_tex (V.texcoord, _maintex); return o;} Half4 Frag (v2f i): color{//obtains the Earth map of the UV x that is, the transverse moving float u = i.uv.x + -0.2*_time;float2 x = float2 (U, i.uv.y); Half4 Texcol = t ex2d (_maintex, x); texcol = FLOAT4 (1, 1, 1, 0) * (texcol.x); if (texcol.x + texcol.y + texcol.z > 0.95) {texcol = Half4 (t EXCOL.XYZ, 0.5);} return texcol;} ENDCG}}}

OK, the reason why, texcol this step, is because the map is colorful, like thermal imaging diagram. After a

Texcol = FLOAT4 (1, 1, 1, 0) * (texcol.x);
Converted to black and white, in which whites are the cloud effect.

And then you can judge it.


The idea is no problem, but when I write most of the code, it is always ineffective.



How to be transparent in 0 places where there is no cloud. And then I joined the blend Srcalpha Oneminussrcalpha, and it worked.


Ok. The rest is Baidu his role, this is not my job. Ha ha

http://download.csdn.net/detail/lihuozhiling/8365965


shader-application v&f for transparent materials

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.