Unity3D Shader官方教程翻译(三)----Shader语法:属性

Unity3D shader脚本 本文只是文档的简单翻译,主要是学习的过程中做些记录,方便以后回顾 Unity中的shader脚本,是用叫做shaderlab的脚本语言来写。这个unity中的shader不只是DX中HLSL写的顶点和像素shader,而应该说是对应着 DX中的Effect脚本,定义了一个完整渲染的状态。 一个文件,只能包含一个unity的shader shader文件的内容: 阅读详情

ShaderLab syntax: Properties

ShaderLab语法:属性


 

Shaders can define a list of parameters to be set by artists in Unity's material inspector. The Properties block in the shader file defines them.

着色器可以由艺术家定义一个参数列表,这个参数值可以在Unity3D的材质检索器中查看。着色器中属性块定义了这些参数。

Syntax

Properties { Property [Property ...] }

 

Defines the property block. Inside braces multiple properties are defined as follows.

定义了1个属性块。括号内的属性定义如下:
name ("display name", Range (min, max)) = number
Defines a float property, represented as a slider from  min to  max in the inspector.
定义了1个float属性,范围是在min到max之间的值,可以利用检索器中对应的滑块调节他们。
name ("display name", Color) = (number,number,number,number)
Defines a color property.
定义了一个颜色
name ("display name", 2D) = "name" { options }
Defines a 2D texture property.
定义了1个2D纹理
name ("display name", Rect) = "name" { options }
Defines a rectangle (non power of 2) texture property.
定义了1个矩形纹理属性
name ("display name", Cube) = "name" { options }
Defines a cubemap texture property.
定义了1个cubemap纹理属性
name ("display name", Float) = number
Defines a float property.
定义了1个float
name ("display name", Vector) = (number,number,number,number)
Defines a four component vector property.
定义了1个向量,该向量由4个分量组成。

 

Details

细节

Each property inside the shader is referenced by name (in Unity, it's common to start shader property names with underscore). The property will show up in material inspector as display name. For each property a default value is given after equals sign:

每个在Shader中的属性是依据属性的名字来引用的(在Unity3d中,通常属性名是以下划线开头)。属性的名字将在材质检索器中显示。每一个属性的默认值为等号后的值。

  • For Range and Float properties it's just a single number.
    Range和Float属性仅仅是1个数字
     
  • For Color and Vector properties it's four numbers in parentheses.
    Color和Vector属性由4个数字组成
  • For texture (2D, Rect, Cube) the default value is either an empty string, or one of builtin default textures: "white", "black", "gray" or "bump".
  • 纹理属性(2D,Rect,Cube)的默认值是1个字符串,或者是默认的内置纹理:"白色","黑色","灰色","凸点"

Later on in the shader, property values are accessed using property name in square brackets: [name].

要在Shader编程中访问属性可以用属性名加方括号来访问如:[name];

Example

例子

Properties {
    // properties for water shader
    _WaveScale ("Wave scale", Range (0.02,0.15)) = 0.07 // sliders滑块
    _ReflDistort ("Reflection distort", Range (0,1.5)) = 0.5
    _RefrDistort ("Refraction distort", Range (0,1.5)) = 0.4
    _RefrColor ("Refraction color", Color)  = (.34, .85, .92, 1) // color颜色
    _ReflectionTex ("Environment Reflection", 2D) = "" {} // textures纹理
    _RefractionTex ("Environment Refraction", 2D) = "" {}
    _Fresnel ("Fresnel (A) ", 2D) = "" {}
    _BumpMap ("Bumpmap (RGB) ", 2D) = "" {}
} 

Texture property options

纹理属性选项

 

The options inside curly braces of the texture property are optional. The available options are:
纹理属性的花括号内的选项是可选的。可用的选项是:


TexGen texgenmode 纹理坐标自动生成模式

Automatic texture coordinate generation mode for this texture. Can be one of  ObjectLinear,  EyeLinear,  SphereMap,  CubeReflect,  CubeNormal; these correspond directly to OpenGL texgen modes. Note that TexGen is ignored if custom vertex programs are used.

纹理坐标自动生成模式。可以是ObjectLinear,EyeLinear , SphereMap, CubeReflect,CubeNormal之一,这些直接对应到OpenGL texgen模式的。注意:如果使用自定义的顶点程序,TexGen被忽略。
。

LightmapMode 光照模式

If given, this texture will be affected by per-renderer lightmap parameters. That is, the texture to use can be not in the material, but taken from the settings of the Renderer instead, see  Renderer scripting documentation.
如果给定的,这种纹理将受到预渲染的光照参数影响。也就是说,这种纹理的使用效果不是取决于材质,而是取决于渲染设置。详情请参考渲染脚本文件。

Example

// EyeLinear texgen mode example
Shader "Texgen/Eye Linear" {
    Properties {
        _MainTex ("Base", 2D) = "white" { TexGen EyeLinear }
    }
    SubShader {
        Pass {
            SetTexture [_MainTex] { combine texture }
        }
    }
} 
 
由 www.J2meGame.com原创,转载请说明。
告别游戏卡关!用Cheat Engine 7.5修改单机游戏数据的保姆级教程(附Tutorial靶场练习) 本文提供了一份详细的Cheat Engine 7.5使用教程,帮助玩家轻松修改单机游戏数据。从基础操作到高级技巧,包括精确值扫描、模糊扫描、指针扫描和代码注入,教程还涵盖了《植物大战僵尸》和《星露谷物语》的实战案例,确保玩家能够安全、高效地优化游戏体验。 阅读详情

相关推荐

昆仑通态,自由串口通讯

软件默认无该功能,需要问客服索要扩展包。

cfqq1989的博客 1544

Unity 固定渲染管线 SetTexture combine实例

Unity 固定渲染管线 SetTexture实例 说明 SetTexture提供一种使用纹理并且进行混合的方式 后面的Block中可以定义颜色和进行数学运算 重点 混合计算方法 *,+,one-,lerp alpha混合 加入颜色constantColor 效果图 代码 Shader "Practice/FixedFunctionShader" { Properties ...

TDC的专栏 2655

电涡流位移测量技术深度解密

电涡流位移传感器凭借非接触测量、高精度(可达纳米级)、强环境适应性(耐高温高压油污)等优势,成为工业精密位移检测的核心技术。其工作原理基于电磁感应:高频磁场在金属靶面感应涡流,通过检测线圈阻抗变化转化为位移信号。应用需注意靶材依赖性(需按实际材料标定)、安装精度及抗干扰措施。广泛应用于磁悬浮轴承、航空发动机、精密制造等领域,实现对微米级位移的可靠监测。

技术工作者 1756

Unity3d C# 代码动态设置(SetTexture)材质球(Material)贴图纹理(Texture)

实现方式 主要的实现方式就是如下两种方式,更建议使用方式二: //Tex就是用于赋值的贴图 int TexID = Shader.PropertyToID("_MainTex");//获取属性名称ID Mat.SetTexture(TexID, Tex); //方式一设置贴图 Mat.SetTexture("_MainTex", Tex); //方式二设置贴图 注意!! 这里的属性的名称,而不是显示的

qq_33789001的博客 1万+

LSTM模型 轨迹经纬度预测

原始时间序列数据如下所示,我们只取前两列纬度和经度作为输入数据 我们设定用前六个位置信息预测下一个位置,则两个样本的输入输出数据如下所示: 创建LSTM网络训练模型: import numpy as np from keras.layers.core import Dense, Activation, Dropout from keras.layers import LS...

Muzi_Water的博客 2万+

避坑指南:STM32H7不同DMA控制器(MDMA/DMA2D/BDMA)到底该用哪个?

本文深入解析STM32H7系列芯片的DMA控制器选型策略,涵盖MDMA、DMA2D、BDMA等不同控制器的架构原理与性能对比。通过实际项目案例,提供高速TCM数据搬运、GUI加速、低功耗传输等场景的选型决策树,并分享性能优化与调试技巧,帮助工程师避开常见陷阱,提升系统效率。

weixin_26876073的博客 448

Unity图形学之三种自定义Shader(八)

Unity中的Shader都是要通过ShaderLab的基本语法进行编写,unity就是想通过Shaderlab的方案进行Shader的编写。将三种定义的Shader通过同一种格式进行编写,避免不同Shader使用不同的语法。 一、 下面我们先从Shaderlab基本语法开始入手 ShaderLab基本结构大致3个代码块儿(一、二、三) (一) 属性 【Pr...

奋斗的菇凉的博客 6054

初探802.11协议(0)——PCF/DCF与CSMA/CA机制

IEEE802.11 CSMA/CA机制与DCF机制

FanFF的博客 4507

Unity Shader之混合纹理基础示例

对于游戏,始于好玩,陷于好玩,忠于好玩。 今个学习了浅墨大神的一篇关于混合纹理的文章,比较基础,整理如下: 一.双纹理混合 Shader "WC/双纹理混合" { Properties { _MainTex ("主纹理 (RGB)", 2D) = "white" {} _BlendTex ("混合纹理 (RGB)", 2D) = "white"{} } SubSha

double kill = 2.0; 2983

Linux kernel crypto的介绍和代码导读

在Linux kernel的module_init阶段会将algif_type_skcipher、algif_type_aead、algif_type_hash、algif_type_rng 四种算法注册.在userspace通过netlink调用了,kernel种的af_alg模块收到消息后, 根据上层传来的算法种类名字来选择走哪一个结构体(alg_type_xxx)的ops函数。也就是添加到af_alg维护的alg_types链表种. alg_types链表种仅有这四个数据.

baron-周贺贺-代码改变世界ctw 323

基于STM32L4XX、HAL库的ESP32-S3-WROOM-1-N4 WIFI模块驱动程序设计

/ 检查是否收到完整的一行(以\r\n结尾)// 例如: 解析AT命令响应或MQTT消息等。// UART2初始化已在CubeMX中配置。// USART2初始化函数(由CubeMX生成)// 缓冲区溢出,重置。// 如果需要等待响应。// 处理接收到的数据。// 处理接收到的数据。// 等待ESP32模块启动。// 主循环其他任务。// 启用UART全局中断。// 发送HTTP GET请求。// 发送AT测试命令。// 连接Wi-Fi。// UART中断回调函数。

zhusl6688的博客 288

Unity3D Shader官方教程翻译(二)

ShaderLab语法:Shader Shader is the root command of a shader file. Each file must define one (and only one) Shader. It specifies how any objects whose material uses this shader are rendered.

u010216987的专栏 562

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

Unity3D Shader官方教程翻译(三)

Unity3D Shader官方教程翻译(三) 1、Shader语法:Pass 1个Pass块可以使一个几何物体被一次渲染。 Pass { [Name and Tags] [RenderSetup] [TextureSetup] } 最基础的pass命令包含有1个可选的渲染设置命令列表,及1个可选的可用纹理列表。 Name and tags 一个Pass 可以

胡胜同学 2162

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

Unity3D Shader官方教程翻译(一)

Unity3D Shader官方教程翻译 Shader Reference 着色参考 Shaders in Unity can be written in one of three different ways: Unity3D着色器,可以写在三种不同的方式之一: assurface shaders, asvertex and fragm

roadProgram的专栏 918

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

Unity3D Shader官方教程翻译(十五)----Shader语法 UsePass

ShaderLab syntax: UsePass The UsePass command uses named passes from another shader. UsePass命令可以调用在另外1个Shader中已经被命名的passes 。 Syntax 语法 UsePass "Shader/Name" Inserts all passes

苗伟业的专栏 526

【Unity】Shader官方教程翻译

·原创:Unity3DShader官方教程翻译(二十八)---Unity3D 10/27·原创:Unity3d中C#使用指针(Unsafe)的办法 10/23·原创:Unity3DShader官方教程翻译(二十七)---GLSL着色 10/23·原创:Unity3DShader官方教程翻译(二十六)---Shader编 10/22·原创:Unity3DShader...

weixin_34029680的博客 179
上一篇: Unity3D Shader官方教程翻译(二)
下一篇: Unity3D Shader官方教程翻译(四)----Shader语法:SubShader
coding_most
博客等级 码龄15年 13粉丝 38原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值