Unity3D Shader官方教程翻译(一)

Unity3D Shader官方教程翻译

Shader Reference
着色参考

Shaders in Unity can be written in one of three different ways:

Unity3D着色器,可以写在三种不同的方式之一:

  • assurface shaders,
  • asvertex and fragment shaders and
  • asfixed function shaders.
  • 表面着色,
  • 顶点和片段着色器和
  • 作为固定功能着色

Theshader tutorial can guide you on choosing the right type for your needs.
着色教程可以指导您对您的需求选择正确的类型

Regardless of which type you choose, the actual meat of the shader code will always be wrapped in a language called ShaderLab, which is used to organize the shader structure. It looks like this:

无论您选择哪种类型,实际的shader代码肉总是会被裹在被称为ShaderLab一种语言,这是用来组织结构着色。它看起来像这样:

Shader "MyShader" { 
Properties { _MyTexture ("My Texture", 2D) = "white" { }
 // other properties like colors or vectors go here as well //其他属性如颜色或向量 }
 SubShader {
 // here goes the 'meat' of your
 // - surface shader or 
// - vertex and program shader or
 // - fixed function shader
 / /这里写内容
 / / - 表面着色 或
 / / - 顶点和程序着色 或
 / / - 固定功能着色
 }
 SubShader {
 // here goes a simpler version of the SubShader above than can run on older graphics cards 
/ /可以运行在旧的显卡的着色器
 } 
}

We recommend that you start by reading about some basic concepts of the ShaderLab syntax in the sections listed below and then to move on to read about surface shaders or vertex and fragment shaders in other sections. Since fixed function shaders are written using ShaderLab only, you will find more information about them in the ShaderLab reference itself.

我们建议您阅读ShaderLab在下面列出,然后转移到其他章节中有关表面着色或顶点和片段着色器读取的部分语法的一些基本概念开始。由于固定功能着色器编写只能使用ShaderLab,你会发现更多的关于他们的信息在ShaderLab引用本身。

The reference below includes plenty of examples for the different types of shaders. For even more examples of surface shaders in particular, you can get the source of Unity's built-in shaders from theResources section. Unity'sImage Effects package contains a lot of interesting vertex and fragment shaders.


下面的参考,包括大量的着色不同类型的例子。更多的在粒子系统中使用的表面着色的例子,你可以查阅Unity3D内置的Shader获得更多信息。Unity3D的图像效果包中包含了很多有趣的顶点和片段着色器

Read on for shader reference, and check out theshader tutorial as well!

  
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的Unity3D着色器,可以制作冰冻效果。它使用了一个简单的反射纹理和一个噪声纹理来创建冰的外观。 ``` Shader "Custom/IceShader" { Properties { _MainTex ("Texture", 2D) = "white" {} _ReflectTex ("Reflect Texture", 2D) = "white" {} _NoiseTex ("Noise Texture", 2D) = "white" {} _BumpScale ("Bump Scale", Range(0.01, 0.1)) = 0.05 _Reflectivity ("Reflectivity", Range(0.0, 1.0)) = 0.5 _NoiseScale ("Noise Scale", Range(0.1, 10.0)) = 1.0 _IceColor ("Ice Color", Color) = (1,1,1,1) } SubShader { Tags { "Queue"="Transparent" "RenderType"="Opaque" } LOD 100 CGPROGRAM #pragma surface surf Standard sampler2D _MainTex; sampler2D _ReflectTex; sampler2D _NoiseTex; float _BumpScale; float _Reflectivity; float _NoiseScale; fixed4 _IceColor; struct Input { float2 uv_MainTex; float2 uv_ReflectTex; float2 uv_NoiseTex; float3 worldPos; float3 worldNormal; }; void surf (Input IN, inout SurfaceOutputStandard o) { // Get the base color from the main texture fixed4 baseColor = tex2D(_MainTex, IN.uv_MainTex); // Get the reflection from the reflect texture fixed4 reflectColor = tex2D(_ReflectTex, IN.uv_ReflectTex); // Combine the base color and reflection fixed4 finalColor = lerp(baseColor, reflectColor, _Reflectivity); // Apply the ice color finalColor *= _IceColor; // Get the bump from the noise texture float4 noise = tex2D(_NoiseTex, IN.uv_NoiseTex); // Convert the noise to a normal vector float3 normal = UnpackNormal(noise.rgb); // Apply the bump to the surface normal IN.worldNormal += normal * _BumpScale; // Set output parameters o.Albedo = finalColor.rgb; o.Metallic = 0.0; o.Smoothness = 1.0; o.Normal = normalize(IN.worldNormal); o.Emission = finalColor.rgb; o.Occlusion = 1.0; o.Alpha = finalColor.a; } ENDCG } FallBack "Diffuse" } ``` 要使用这个着色器,您需要将三个纹理分别指定给_MainTex,_ReflectTex和_NoiseTex属性。您还可以调整_BumpScale,_Reflectivity和_NoiseScale参数来改变效果。最后,您可以使用_IceColor来指定冰的颜色。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值