2016-11-18 22:53:54 ecidevilin 阅读数 6921

在Unity内建Shader的DefaultResourcesExtra的目录中,有一个很简单却很实用的shader——Decal。这是一个贴花着色器,可以在模型的表面添加一个贴花纹理。

Unity内建Shader下载地址

如图所示:

(程序员的审美也就这样吧……)

我们看看Decal的代码:
Shader "Legacy Shaders/Decal" {
Properties {
	_Color ("Main Color", Color) = (1,1,1,1)
	_MainTex ("Base (RGB)", 2D) = "white" {}
	_DecalTex ("Decal (RGBA)", 2D) = "black" {}
}

SubShader {
	Tags { "RenderType"="Opaque" }
	LOD 250
	
CGPROGRAM
#pragma surface surf Lambert

sampler2D _MainTex;
sampler2D _DecalTex;
fixed4 _Color;

struct Input {
	float2 uv_MainTex;
	float2 uv_DecalTex;
};

void surf (Input IN, inout SurfaceOutput o) {
	fixed4 c = tex2D(_MainTex, IN.uv_MainTex);
	half4 decal = tex2D(_DecalTex, IN.uv_DecalTex);
	c.rgb = lerp (c.rgb, decal.rgb, decal.a);
	c *= _Color;
	o.Albedo = c.rgb;
	o.Alpha = c.a;
}
ENDCG
}

Fallback "Legacy Shaders/Diffuse"
}

这是一个表面着色器,代码非常简单。

唯一要注意的是:
lerp (c.rgb, decal.rgb, decal.a)
实际上就等于:
decal.a*(decal.rgb-c.rgb)+c.rgb
也就等于:
decal.a*decal+(1-decal.a)*c.rgb

也就相当于使用了常规的混合模式(参考Shader山下(十八)混合(Blend)命令
Blend SrcAlpha OneMinusSrcAlpha
(因为是Opaque,所以透明度也就无所谓了)

2016-11-17 22:15:22 ecidevilin 阅读数 2036

在Unity内建Shader的DefaultResourcesExtra的目录中,可以看到AlphaTest-SoftEdgeUnlit.shader这个文件。可以用来渲染草、树和叶子。

当绘制半透明的物体,例如草的时候,因为关闭了ZWrite,所以没有办法保证这些半透明物体正确的绘制顺序,就需要对它们进行深度排序。(参考【Unity Shaders】Alpha Test和Alpha Blending

AlphaTest-SoftEdgeUnlit它将物体渲染分为了两个Pass,第一个Pass用来渲染不透明的部分,第二个pass用来渲染透明部分。

Unity内建Shader下载地址

我们先看看SubShader的指令:

	Tags { "Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout" }
	Lighting off
	
	// Render both front and back facing polygons.
	Cull Off

Tags(参考Shader山下(十九)标记Tag

它的渲染序列是AlphaTest(2450),忽略投影,渲染类型为透明裁切。

Lighing off

不受光照影响

Cull Off

剔除关闭


接着是第一个Pass的frag方法:

			fixed4 frag (v2f i) : SV_Target
			{
				half4 col = _Color * tex2D(_MainTex, i.texcoord);
				clip(col.a - _Cutoff);
				UNITY_APPLY_FOG(i.fogCoord, col);
				return col;
			}
使用clip方法检测Alpha是否小于_Cutoff,如果小于便会舍弃掉该片元。

UNITY_APPLY_FOG将雾效(参考Unity3D开发小贴士(十)雾效)颜色与当前颜色根据雾效参数进行插值。


然后我们看第二个Pass的指令:

		Tags { "RequireOption" = "SoftVegetation" }
		
		// Dont write to the depth buffer
		ZWrite off
		
		// Set up alpha blending
		Blend SrcAlpha OneMinusSrcAlpha

Tags

需要选项SoftVegetation(默认是开启的,但是没有找到在哪里设置,求指教)
ZWrite off

不将深度值写入ZBuffer(深度缓存,用来判断对象前后顺序,以及片元是否会被剔除掉)

Blend SrcAlpha OneMinusSrcAlpha

使用常规混合方式(参考Shader山下(十八)混合(Blend)命令


第二个Pass的frag方法:

			fixed4 frag (v2f i) : SV_Target
			{
				half4 col = _Color * tex2D(_MainTex, i.texcoord);
				clip(-(col.a - _Cutoff));
				UNITY_APPLY_FOG(i.fogCoord, col);
				return col;
			}
舍弃掉Alpha大于_Cutoff的片元。


最后我们看一看效果,使用官方Environment Package里面的Conifer_Needles_Desktop作为贴图:

Base Alpha cutoff = 0.01(接近标准的Alpha Test效果)


Base Alpha cutoff = 0.5


Base Alpha cutoff = 0.9


2016-11-20 22:45:03 ecidevilin 阅读数 4141

我们除了可以使用Unity3D默认的天空盒之外,还可以自定义天空盒。可以使用Skybox/6 Sided这个shader作为天空盒材质的着色器,它在内建Shader的

DefaultResourcesExtra的目录中。

Unity内建Shader下载地址

首先我们创建一个Material,将Skybox/6 Sided设置为着色器,我们看到需要设置6张贴图。


然后我们在菜单栏里找到Window->Lighting,切换到Scene页,就可以看到修改Skybox材质的地方:

修改为我们创建的材质,我们就可以看到:

当我们旋转摄像机角度的时候,可以看到天空盒6个面,但是当我们调整摄像机坐标的时候,天空盒却不会发生变化。





我们来看看这个shader里面都有什么:
Shader "Skybox/6 Sided" {
Properties {
	_Tint ("Tint Color", Color) = (.5, .5, .5, .5)
	[Gamma] _Exposure ("Exposure", Range(0, 8)) = 1.0
	_Rotation ("Rotation", Range(0, 360)) = 0
	[NoScaleOffset] _FrontTex ("Front [+Z]   (HDR)", 2D) = "grey" {}
	[NoScaleOffset] _BackTex ("Back [-Z]   (HDR)", 2D) = "grey" {}
	[NoScaleOffset] _LeftTex ("Left [+X]   (HDR)", 2D) = "grey" {}
	[NoScaleOffset] _RightTex ("Right [-X]   (HDR)", 2D) = "grey" {}
	[NoScaleOffset] _UpTex ("Up [+Y]   (HDR)", 2D) = "grey" {}
	[NoScaleOffset] _DownTex ("Down [-Y]   (HDR)", 2D) = "grey" {}
}

SubShader {
	Tags { "Queue"="Background" "RenderType"="Background" "PreviewType"="Skybox" }
	Cull Off ZWrite Off
	
	CGINCLUDE
	#include "UnityCG.cginc"

	half4 _Tint;
	half _Exposure;
	float _Rotation;

	float4 RotateAroundYInDegrees (float4 vertex, float degrees)
	{
		float alpha = degrees * UNITY_PI / 180.0;
		float sina, cosa;
		sincos(alpha, sina, cosa);
		float2x2 m = float2x2(cosa, -sina, sina, cosa);
		return float4(mul(m, vertex.xz), vertex.yw).xzyw;
	}
	
	struct appdata_t {
		float4 vertex : POSITION;
		float2 texcoord : TEXCOORD0;
	};
	struct v2f {
		float4 vertex : SV_POSITION;
		float2 texcoord : TEXCOORD0;
	};
	v2f vert (appdata_t v)
	{
		v2f o;
		o.vertex = mul(UNITY_MATRIX_MVP, RotateAroundYInDegrees(v.vertex, _Rotation));
		o.texcoord = v.texcoord;
		return o;
	}
	half4 skybox_frag (v2f i, sampler2D smp, half4 smpDecode)
	{
		half4 tex = tex2D (smp, i.texcoord);
		half3 c = DecodeHDR (tex, smpDecode);
		c = c * _Tint.rgb * unity_ColorSpaceDouble.rgb;
		c *= _Exposure;
		return half4(c, 1);
	}
	ENDCG
	
	Pass {
		CGPROGRAM
		#pragma vertex vert
		#pragma fragment frag
		sampler2D _FrontTex;
		half4 _FrontTex_HDR;
		half4 frag (v2f i) : SV_Target { return skybox_frag(i,_FrontTex, _FrontTex_HDR); }
		ENDCG 
	}
	Pass{
		CGPROGRAM
		#pragma vertex vert
		#pragma fragment frag
		sampler2D _BackTex;
		half4 _BackTex_HDR;
		half4 frag (v2f i) : SV_Target { return skybox_frag(i,_BackTex, _BackTex_HDR); }
		ENDCG 
	}
	Pass{
		CGPROGRAM
		#pragma vertex vert
		#pragma fragment frag
		sampler2D _LeftTex;
		half4 _LeftTex_HDR;
		half4 frag (v2f i) : SV_Target { return skybox_frag(i,_LeftTex, _LeftTex_HDR); }
		ENDCG
	}
	Pass{
		CGPROGRAM
		#pragma vertex vert
		#pragma fragment frag
		sampler2D _RightTex;
		half4 _RightTex_HDR;
		half4 frag (v2f i) : SV_Target { return skybox_frag(i,_RightTex, _RightTex_HDR); }
		ENDCG
	}	
	Pass{
		CGPROGRAM
		#pragma vertex vert
		#pragma fragment frag
		sampler2D _UpTex;
		half4 _UpTex_HDR;
		half4 frag (v2f i) : SV_Target { return skybox_frag(i,_UpTex, _UpTex_HDR); }
		ENDCG
	}	
	Pass{
		CGPROGRAM
		#pragma vertex vert
		#pragma fragment frag
		sampler2D _DownTex;
		half4 _DownTex_HDR;
		half4 frag (v2f i) : SV_Target { return skybox_frag(i,_DownTex, _DownTex_HDR); }
		ENDCG
	}
}
}

需要注意的是:
1、在Properties里,为六张贴图添加了特性[NoScaleOffset],这样就隐藏了Tiling和Offset。
2、Queue为Background,也就是最先渲染。
3、Cull Off关闭了(背面)剔除。
4、ZWrite Off关闭了深度写入。
5、总共六个Pass,分别用来渲染六张贴图。
6、六个Pass公用一个vert方法,调用了RotateAroundYInDegrees方法,会根据Rotation旋转天空盒。(sincos求Rotation的sin值和cos值)。
7、六个Pass里的frag方法都调用了skybox_frag方法,分别以贴图和贴图的HDR(参考百度百科高动态光照渲染)向量。
8、unity_ColorSpaceDouble没有相关的文档,但是从Frame Debugger来看,是(2,2,2,2)。
9、DecodeHDR在CGIncludes/UnityCG.cginc里,代码:
// Decodes HDR textures
// handles dLDR, RGBM formats
inline half3 DecodeHDR (half4 data, half4 decodeInstructions)
{
	// If Linear mode is not supported we can skip exponent part
	#if defined(UNITY_NO_LINEAR_COLORSPACE)
		return (decodeInstructions.x * data.a) * data.rgb;
	#else
		return (decodeInstructions.x * pow(data.a, decodeInstructions.y)) * data.rgb;
	#endif
}

另外,Skybox/Cubemap与Skybox/6 Sided基本一致,只是将六张贴图换成了一个Cubemap,创建Cubemap的方法如图:

恩,还是需要六张贴图。

2017-08-13 15:28:17 biezhihua 阅读数 492

这里写图片描述

官方视频:https://unity3d.com/cn/learn/tutorials/topics/graphics/standard-shader

官方Demo:https://github.com/biezhihua/Unity3DTutorials/tree/master/Graphics/StandardShader

视频字幕文件:https://github.com/biezhihua/Unity3DTutorials/blob/master/Graphics/%5BDownSub.com%5D%20Unity%205%20Graphics%20-%20The%20Standard%20Shader%20-%20Unity%20Official%20Tutorials.srt

视频字幕内容:

The Standard Shader is a powerful and versatile shader.

This single physically-based shadercan be used to make such a wide varietyof materials it’s easilypossible that this one shader can makeevery material in a given project.

The standard is used to create Unity’s default material.

So all mesh rendered usingthe default material will be using the standard shader.

All new materials that are createdwill use the standard shader as well.

To change the shader used by a materialselect the Shader menu on the material.

Select Standard to use the standard shader.

It is worth noting the Unityhas shaders available for bothpopular approaches to physically-based rendering.

Metallic, as default,and specular.

To choose the standard shaderusing the specular approachselect Standard (Specular Setup).

Otherwise use Standardfor the metallic approach.

It is important to understand that themetallic approach to physically-based shadingis not only for materials which aresupposed to look metallic.

This mode is known as metallicbecause this approach is based ondefining how metallic or non-metallicthat material’s surface is.

This is opposed to the specular approachwhich defines how specular,or non-specular that surface is.

Both approaches are valid ways todescribe a physically-based material.

This physically-based material isstill a standard Unity materialand this material is associatedwith a renderer in the same way as usual.

There are three sections to the standard shader.

Rendering Mode.

Main Mapsand Secondary Maps.

The standard shader has four rendering modes.

Opaque, Cutout, Fade and Transparent.

Most materials are opaque, or solid materials.

Opaque is the default render mode.

For transparent materials, such as glass,choose Transparent.

In transparent rendering modethe alpha channel on the diffuse colour propertyis used to control the level of transparency.

With rendering mode cutoutthe alpha channel of the diffuse imageis used to mask out parts of the texture.

If the alpha channel has a gradient value to the maskthe alpha cutoff slider can be usedto adjust the shape of the cutout.

based on the strength of the mask in the alpha channel.

Rendering mode fade is similarto rendering mode transparent.

Fade is intended for fading outgame objects on screen.

With rendering mode transparenta transparent material will preserve it’sreflectivity regardless of it’s alpha value.

Fade however will fade allrelevant aspects of the materialso the faded material is completely invisible.

The main map section defines the look of the material.

Before going in to the details of each propertythere are a few subjects that are worth covering first.

Optimisation.

The standard shader is highly optimised.

When the standard shader is builttwo important things happen.

All properties that are not being used are discarded.

The build target is checkedand the shader is optimised for that device.

Because of this there is no need to populate everyproperty with a map or values.

And there is no need to worry about wastedresources due to unused properties.

Physically-based shading.

Physically-based shading tries to definecertain physical aspects of a material’s surface.

Including it’s diffuse colour,specular refection and other propertiesso the material behaves correctlyand believably in all lighting environments.

The response of the scene lighting to the materialcreated with a physically based shadermimics light in the real physical world.

This means that even though there isfull control over the values onall of the properties in the standard shaderthere are certain ranges of values thatwork best for certain types of materials.

This is particularly true of the metallic and specular valuesdepending up which approach is being usedTaking specular colour for example,when analysing real-world materialsmost materials have a specular rangethat is a very dark grey.

Metals created with a specular workflow are one of the few exceptions,they have very bright specular values.

As well, no material, even the most dull,has no specularity at all.

This means to have a physically basedmaterial behave correctlysome attention needs to be paid in usingthe correct physical values for some key properties,especially the specular or metallic propertiesdepending upon the approach being used.

For more information on physical-based shading,material charts and sample materialsplease see the information linked below.

There is no need to panic however.

Items with materials from previous versions of Unitywill work well out of the box.

Upgrading from a legacy diffuse shaderto the standard shader should display little or no difference.

In the main map section each of these propertiescontrol one aspect of the final material.

Each property can be defined by a texture map.

With the metallic approach,for the albido, metallic and emission propertiesthe texture is optional.

The albido and emission propertiescan simply use a colour value instead of a texture.

The colour value is not available onthe emission property until the emissivescale is larger than 0.

The metallic property can use a sliderinstead of a texture.

The albido property uses acombination of an optional texture.

And a colour value to define the base look of the material.

The colour value will tint the texture.

Where pure white leaves the main texture unaffected,if there is no texture being usedthe tint colour will be the base colour for the materialThe metallic property can be definedby either a textureor a value from 0 to 1set by the slider.

This defines the metalness of the material surface.

Metalness works very closely with smoothness.

The smoothness property is used tocontrol the smoothness,or micro-surface detail, of the material.

It is also a value between 0 and 1.

The less smooth the surface is,the more diffuse the reflections will be.

The more smooth, the sharper the reflections.

The metallic property can use a textureto define the material’s metalness.

This texture can be a simple shade of greyused to define the metalness from black,or non-metallic,to white, completely metallic.

However, the advantage of using a textureto define the metalness of a materialis to vary the metalness valueacross the surface of the material.

An additional advantage is this texture’s alpha channel.

This alpha channel can be used to definea smoothness map.

Many materials are far more complexthan a single uniform surface.

Take this leather case for example.

With a single value for metalness and asingle value for smoothnessthe case looks good.

But it could look better.

Use a metalness and smoothness mapto describe the properties.

And it looks much better.

Note how the straps are far more glossythan the main body of the case.

Giving them a feel of polished leather.

It is worth noting that when using a textureto define the metalnessthe smoothness value must also bedefined by that texture’s alpha channel.

It is also worth noting that the metalnessvalue is stored only in the redchannel of the metalness map’s RGB values.

The green and blue channels are ignored.

It is often easier however to visualisethe metalness values of a textureif all three colour channels share the same map,so the texture appears as a greyscale image.

When using the standard shader with the specular setupthe metallic property is replaced withthe specular property.

The specular approach also usesa smoothness property, which behaves essentiallyin the same way as with the metalness approach.

The specualar property can either be a textureor a colour valueand defines the specular reflectivityof the material’s surface.

The specular value can have some colour in itbut looking at real world valueswith the exception of some metalsthis is usually a grey and often very dark.

Specular maps are usually a dark grey as well.

When a specular texture map is not being usedthe overall surface smoothness can beset with the slider.

This is easier to see when the albidotexture is removed.

The ball looks like polished porcelain.

For a more true mirror, the specular from dark grey,which makes the ball look like porcelainin to the range of metals and it will nowreflect the sky and surroundings.

The smoother the surface, the more it is mirror-like.

The rougher the surface the more diffuse,or scattered the reflections are.

The normal map property is an optional propertyused to define the apparent bumpiness of the surface.

When a normal map is appliedthe strength of the normal map can be controlledby adjusting the normal map value.

As well as positive numbers, this valuecan be a negative numberor 0.

The height map property is an optionalproperty used to define the apparentheight of the surface.

When a height map is appliedthe strength of the height map can be controlledby adjusting the height map value.

The occlusion property uses atexture map to define the amount ofambient occlusion that is applied to the material.

This is used to help darkenhidden or recessed areas on the texture.

The ambient occlusion map alsoprevents specular and reflections inthese occluded areas, given the materiala more realistic look.

The emission property controls whether or notthe material’s surface will emit light.

The material’s emission value can contributeto the scene’s global illumination.

The strength of the emission can be controlledby the emission value.

The shape of the emission can be controlled with an emission map.

The map can be a simple black and white map.

bBut this texture can also be a colour map.

When there is a value for emissionthe contribution of the emissive lightcan be assigned to either the baked light mapsor to the real time light maps.

The detail mask property is an optional mask elementto control the secondary maps.

Tiling and offset control the position of the map.

The secondary maps are used to defineadditional surface detail.

This additional detail, sometimes referred to as micro detail,is added on top of the surface definedby the main maps.

This helps to add extra detail andvariation to a material, which is overlaidon top of the main maps defining that material.

Because detail maps can be tiled across meshesthey can add incredibly high levels of surface detail.

2013-06-19 09:24:15 naoomi 阅读数 1061
http://wenku.baidu.com/view/e82c4e196bd97f192279e922.html

Unity3D置了很多Shader,文详细,自己翻一下.便于加深印象. 

      首先先解Unity3D的Shader.Unity里面的Shaders是使用一ShaderLab的编写的,同微.FX文件或者NVIDIA的CgFX有些似。传统上的vertex shader和pixel shader 是使用准的Cg/HLSL 编写的。(因此Unity文里面的Shader,都是指用ShaderLab编写的代

      然后我们来看下Unity3D自60多Shader。 Shader被分Normal,Transparent,Transparent Cutout,Self-llluminated,Reflective。由于量比多,分几篇幅一一介

      (一) Normal Shader Family

      这个家族一共9Shader,都是针对不透明的象的。

      (1) Vertex-Lit:

      最简单的一Shader之一,所有照射在物体上的光在一Pass里面渲染完,光源只在算。所以不有任何基于像素渲染得效果,比如normal mapping,light cookies和shadows.这个shader模型的剖分(物体几何描述变为形表示的程)非常敏感,如果你将点光源放在很靠近一立方体的一个顶点那里,立方体使用这个shader,光源只在角落算。基于像素光照的shader剖分有要求,在表现圆形高光上效果也很好。如果上述情况时你想要的效果,可以考使用一基于像素光照的shader或者增加模型的剖分。(增加

      来说这个shader的渲染代价比小。这个shader包含了2subshader,分别对应成管线和固定管线。是所有硬件都支持的一最基本的shader。如果设备支持可成管线,那使用可成管线subshader,否使用固定管线的。

      (2) Diffuse:

      Diffuse基于一个简单的光照模型-Lambertian,光照强度着物体表面和光入射角角的小而(即光垂直于表面强度最大)。光照的强度只和角度有系,和像机无。由于是一基于像素光照的shader,因此他有这类shader的优势,同他需要设备支持可程管线,如果设备不支持,使用Vertex-Lit这个Shader。

      来说这个shader渲染代价比小。

      (3) Specular

      Specular 使用和Diffuse相同的光照模型,但是添加了一察角度相的反射高光。这个称为Blinn-Phong光照模型。他包含了一反射强光,这个反射高光物体表面角度,光的入射角度以及察者角度都有系。这种高光算方法实际上是对实时光源模糊反射的一具有可行性的模。模糊的等inspector里面Shininess这个变量控制。

      主理的alpha通道被用来当Specular Map使用(有候也gloss map),了物体的反光率。理中alpha里面全黑 的部分完全不反光(即反光率0%)。而全白的的部分反光率100%。这个Map在的物体在不同的部分有不同的反光率的候非常有用。比如迹斑斑的金属会反光率低,而磨光的金反光率比高。口的反光率比皮高,而皮的反光率比棉衣服高。一精心制作的Specular Map将会让玩家身其境。如果目标设备不支持可程管线使用Vertex-Lit这个Shader。

       这个shader的渲染代价

       (4)Bumped Diffuse

       同Diffuse Shader一这个Shader基于Lambertian光照模型,同使用了normal mapping技术来增加物体表面细节。相于通增加剖分物体表面细节的方式,normal mapping不改物体的形,而是使用一张称为Normal Map的特殊来达这种效果。在normal map中,每象素的色代表了像素所在物体表面的法线,然后通过这个线(而不是通物体模型算而的法线来计算光照。可以Normal Map在算光照的程中“高效地修改”了整模型

       如何Normal maps:可以通过导入一普通的灰度(白色表示凸起,黑色表示凹Unity动将它转换为Normal Map。

       技术细节里使用Normal map是一Tangent space Normal Map”,Tangent space(正切空)是一模型物体表面的空。在这个中,z终从表面指向外面。Tangent space Normal Map相于另一称为Object space Normal Map”来说有点复杂,但是他有一些优势1)可以使用在各奇形怪的表面  2)便于在同一物体不同域或者不同物体间复

        具体Tangent Space Normal Map和Object Space Normal Map的区别,下次再

        如果这个shader失则会调Diffuse这个shader,一般而言,shader渲染代价低。

        (5) Bumped Specular

        和Specular一的光照模型,相比Specular而言,使用一Tangent Space Normal Map描述物体表面法向量的化,增加物体细节。(normal map具体Bumpped Diffuse)如果用失使用Specular这个shader,一般而言,这个shader的渲染代价大。

        (6) Parallax Diffuse

        Parallax Normal mapped与传统normal mapped一,但是“深度”的模更佳。外的深度效果是通Height Map(高度来实现的。Height Map在Normal map的alpha通道里面保存。全黑表示有高度,而白色表示有高度。通常或者砖块间的裂

        Parallax mapping的技简单,因此有些人工痕迹或者不太正常的效果出。尤其是,陡峭的高低转换在高度里面应该避免。在inspector里面height数值来调整高度的范,有造成物体不真实,凌的情。因此建使用高度化平的高度或者高度数值设置比低,表面看起

        这个shader的渲染代价相比bumped diffuse而言更大。如果这个Shader失使用Bumped Diffuse。

        (7) Parallax Specular

        Bumped Spcular相比,增加了一Height Map描述深度细节Height Map,parallax Diffuse。如果用失则调Bumped Specular这个Shader。

        (8) Decal

        这个Shader在unity文里面的描述和Unity3.0有明实现区别,文由于比老,07年的,官下的Built-in Shader里面,decal是使用可程管线实现的,就是,如果的机器不支持可程管线使用diffuse,因diffuse也不需要可程管线,所以只能使用vertex-lit。这个Shader除了主理之外,这个Shader是用了第二张纹理用描述细节。第二Decal()的理使用alpha通道确定是否覆盖主理。花用的理只是理的充。比如说你有一个砖砌的壁,可以使用一个砖块理作理,然后使用alpha通道的Decal理在壁的不同地方涂

        (9) Diffuse Detail 

        是一普通的diffuse shader加上一些据的shader。许你第二张纹理,称为Detail Texture。camera靠近的候,Detail Texture逐渐显示出,一般用于地形。比如当你使用一低分辨率的理拉升到整地形上的候。camera逐拉近,低分辨率的始模糊,不是我想要的效果。了避免这个效果,建一Detail 会将地形tile化。在这种模式下,着camera逐拉近,外的细节将会以避免出模糊的效果。

        Detail 理是覆盖在主理上面的。Detail理中深色的部分将会使得主深,而淡色的部分将会使主亮,Detail理通常是灰色。(Decal里面Decal理不同的是,Decal理是RGBA,通alpha控制Decal TextureMain Texture的融合,而Detail的理是RGB,直接是两张纹理的rgb通道分相乘再*2,就是Detail理中数值 = 0.5不,>0.5会变亮,<0.5加深)


UnityCG.cginc中一些常用的函数

博文 来自: biezhihua
没有更多推荐了,返回首页