shader学习笔记二
2015-12-30 16:32
225 查看
surface shader中因为使用cg语言,所以不需要pass通道。
Shader "Custom/myshader03" {
Properties
{
_Color ("Color",Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)",2D) = "white"
{}
_Glossiness ("Smoothness",Range(0,1)) = 0.5//浮点值,用来计算高光的光泽度
_Metallic ("Metallic",Range(0,1)) = 0.0//浮点值,用来表现金属的光泽
}
//在SubShader中不需要编写pass
SubShader
{
Tags { "RenderType"="Opaque" "queue"="transparent"}
//渲染类型,是个不透明的物体."queue"="transparent"按透明物体队列渲染
LOD 200
//层级细节
CGPROGRAM //代码块起始,使用了CG语法
//#pragma(编译指令)+surface(用此格式编写)+surf(suifaceFunction(方法名)+Standard(LightonModel光照模型)+其他一些选项
//加alpha给上阿尔法通道实现透明
//删除fullforwardshadows取消阴影的话还要删掉末尾FallBack "Diffuse"
#pragma surface surf Standard fullforwardshadows alpha
// 没有这句默认使用shader model 2.0 target
#pragma target 3.0
sampler2D _MainTex;//属性中类型为2D,这要声明为二维纹理变量
//纹理坐标结构体,必须以uv或uv2开头
struct Input {
float2 uv_MainTex;
};
//属性里都要一一声明
half _Glossiness;
half _Metallic;//范围要声明为一个浮点值
fixed4 _Color;//color类型声明为fixed4的一个四阶向量
//surface函数总是无返回,inout意思是即使输入又是输出。 没有则默认为是int,意思是输入的。out意思是最终为输出。
//SurfaceOutputStandard在官方手册里为:
//4.x版本
//struct SurfaceOutput
//{
//
fixed3 Albedo; // diffuse color
//
fixed3 Normal; // tangent space normal, if written
//
fixed3 Emission;
//
half Specular; // specular power in 0..1 range
//
fixed Gloss; // specular intensity
//fixed Alpha; // alpha for transparencies
// };
//5.x版本
//struct SurfaceOutputStandard
//{
//fixed3 Albedo; // base (diffuse or specular) color 基本的漫反射和高光,结合了旧版本的Specular
//fixed3 Normal; // tangent space normal, if written
//half3 Emission;
//
half Metallic; // 0=non-metal, 1=metal 描述一个物体金属化的程度
//half Smoothness; // 0=rough, 1=smooth 结合了旧版本的Gloss
//half Occlusion; // occlusion (default 1)
//fixed Alpha; // alpha for transparencies
//};
//struct SurfaceOutputStandardSpecular
//{
//fixed3 Albedo; // diffuse color
//
fixed3 Specular; // specular color
//
fixed3 Normal; // tangent space normal, if written
//
half3 Emission;
//half Smoothness; // 0=rough, 1=smooth
//half Occlusion; // occlusion (default 1)
//fixed Alpha; // alpha for transparencies
//};
void surf (Input IN, inout SurfaceOutputStandard o)
{
// Albedo comes from a texture tinted by color
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
// Metallic and smoothness come from slider variables
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = c.a;
}
ENDCG
}
FallBack
"Diffuse" //如果特性不能被使用,使用FallBack定义的默认shader
}
在unity中找到以下文件打开:
下图就是找到了光照函数名称,真正有效的部分是lighting后面的部分,在编写时要加上lighting
shader文件下载地址:http://download.csdn.net/detail/zkq666666/9385413
Shader "Custom/myshader03" {
Properties
{
_Color ("Color",Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)",2D) = "white"
{}
_Glossiness ("Smoothness",Range(0,1)) = 0.5//浮点值,用来计算高光的光泽度
_Metallic ("Metallic",Range(0,1)) = 0.0//浮点值,用来表现金属的光泽
}
//在SubShader中不需要编写pass
SubShader
{
Tags { "RenderType"="Opaque" "queue"="transparent"}
//渲染类型,是个不透明的物体."queue"="transparent"按透明物体队列渲染
LOD 200
//层级细节
CGPROGRAM //代码块起始,使用了CG语法
//#pragma(编译指令)+surface(用此格式编写)+surf(suifaceFunction(方法名)+Standard(LightonModel光照模型)+其他一些选项
//加alpha给上阿尔法通道实现透明
//删除fullforwardshadows取消阴影的话还要删掉末尾FallBack "Diffuse"
#pragma surface surf Standard fullforwardshadows alpha
// 没有这句默认使用shader model 2.0 target
#pragma target 3.0
sampler2D _MainTex;//属性中类型为2D,这要声明为二维纹理变量
//纹理坐标结构体,必须以uv或uv2开头
struct Input {
float2 uv_MainTex;
};
//属性里都要一一声明
half _Glossiness;
half _Metallic;//范围要声明为一个浮点值
fixed4 _Color;//color类型声明为fixed4的一个四阶向量
//surface函数总是无返回,inout意思是即使输入又是输出。 没有则默认为是int,意思是输入的。out意思是最终为输出。
//SurfaceOutputStandard在官方手册里为:
//4.x版本
//struct SurfaceOutput
//{
//
fixed3 Albedo; // diffuse color
//
fixed3 Normal; // tangent space normal, if written
//
fixed3 Emission;
//
half Specular; // specular power in 0..1 range
//
fixed Gloss; // specular intensity
//fixed Alpha; // alpha for transparencies
// };
//5.x版本
//struct SurfaceOutputStandard
//{
//fixed3 Albedo; // base (diffuse or specular) color 基本的漫反射和高光,结合了旧版本的Specular
//fixed3 Normal; // tangent space normal, if written
//half3 Emission;
//
half Metallic; // 0=non-metal, 1=metal 描述一个物体金属化的程度
//half Smoothness; // 0=rough, 1=smooth 结合了旧版本的Gloss
//half Occlusion; // occlusion (default 1)
//fixed Alpha; // alpha for transparencies
//};
//struct SurfaceOutputStandardSpecular
//{
//fixed3 Albedo; // diffuse color
//
fixed3 Specular; // specular color
//
fixed3 Normal; // tangent space normal, if written
//
half3 Emission;
//half Smoothness; // 0=rough, 1=smooth
//half Occlusion; // occlusion (default 1)
//fixed Alpha; // alpha for transparencies
//};
void surf (Input IN, inout SurfaceOutputStandard o)
{
// Albedo comes from a texture tinted by color
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
// Metallic and smoothness come from slider variables
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = c.a;
}
ENDCG
}
FallBack
"Diffuse" //如果特性不能被使用,使用FallBack定义的默认shader
}
在unity中找到以下文件打开:
下图就是找到了光照函数名称,真正有效的部分是lighting后面的部分,在编写时要加上lighting
shader文件下载地址:http://download.csdn.net/detail/zkq666666/9385413
相关文章推荐
- shareSDK
- Start your own JavaScript library using webpack and ES6
- 文法 分析 2
- 11 11 评价
- iOS移除所有的子View
- 关于不再使用的Java对象手工指null是否有意义
- 转载For语句讲解2
- unity xml加密解密源码
- 重庆大学软件学院2013级操作系统实验三:线程同步
- seo
- java设计模式----责任链模式
- 移动端的头部标签和 meta
- hadoopwordcount代码分析
- opencv入门02(visual studio2010)--20151230
- Kong-Mashape 开源 API 网关介绍
- jQuery源码分析17--回调函数
- 15年末留下点东东
- 可能是东半球最全的RxJava使用场景小结
- spring mvc 用ajaxSubmit 在iE8上传文件变下载的问题
- SpringMVC中使用DWR