Unity表面着色器
表面着色器和之前无光照着色器不同,其中没有顶点着色器和片元着色器,而增加了光照函数;
接下写了一个求两个贴图的光照效果
两个贴图做插值运算:
Shader "Custom/SurfaceShader"
{
Properties
{
_Color ("Color", Color) = (,,,)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_SecondAlbedo("Second Albedo(RGB)",2D) = "white"{}
_AlbedoLerp("Albedo lerp",Range(,))=0.5
_Glossiness ("Smoothness", Range(,)) = 0.5
_Metallic ("Metallic", Range(,)) = 0.0
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows // Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0 sampler2D _MainTex;
sampler2D _SecondAlbedo;
half _AlbedoLerp; struct Input
{
float2 uv_MainTex;
}; half _Glossiness;
half _Metallic;
fixed4 _Color; // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
// See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
// #pragma instancing_options assumeuniformscaling
UNITY_INSTANCING_BUFFER_START(Props)
// put more per-instance properties here
UNITY_INSTANCING_BUFFER_END(Props) void surf (Input IN, inout SurfaceOutputStandard o)
{
// Albedo comes from a texture tinted by color
fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
fixed4 secondAebed = tex2D(_SecondAlbedo, IN.uv_MainTex); o.Albedo = lerp(c,secondAebed, _AlbedoLerp)*_Color;
// Metallic and smoothness come from slider variables
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
添加漫反射贴图
Shader "Custom/SufaceShaderNormalMap"
{
Properties
{
_Color ("Color", Color) = (,,,)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_NormalMap("Normal Map",2D) = "bump"{}
_Glossiness ("Smoothness", Range(,)) = 0.5
_Metallic ("Metallic", Range(,)) = 0.0
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows // Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0 sampler2D _MainTex;
sampler2D _NormalMap; struct Input
{
float2 uv_MainTex;
}; half _Glossiness;
half _Metallic;
fixed4 _Color; // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
// See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
// #pragma instancing_options assumeuniformscaling
UNITY_INSTANCING_BUFFER_START(Props)
// put more per-instance properties here
UNITY_INSTANCING_BUFFER_END(Props) void surf (Input IN, inout SurfaceOutputStandard o)
{
// Albedo comes from a texture tinted by color
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Normal = UnpackNormal(tex2D(_NormalMap, IN.uv_MainTex));
o.Albedo = c.rgb;
// Metallic and smoothness come from slider variables
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
Unity表面着色器的更多相关文章
- UnityShader 表面着色器简单例程集合
		
0.前言 这些简单的shader程序都是写于2015年的暑假.当时实验室空调坏了,30多个人在实验室中挥汗如雨,闷热中学习shader的日子还历历在目.这些文章闲置在我个人博客中,一年将过,师弟也到了 ...
 - 关于Unity中表面着色器的使用
		
写shader其实就是在两个工位顶点shader工位和着色shader工位插入代码,供GPU使用运行 表面着色器四个函数的入口 1:表面着色器包括4个函数: (1): 顶点变换函数; (2): 表面着 ...
 - Unity Shader入门精要学习笔记 - 第17章 Unity的表面着色器探秘
		
转自 冯乐乐的<Unity Shader 入门精要> 2010年的Unity 3 中,Surface Shader 出现了. 表面着色器的一个例子. 我们先做如下准备工作. 1)新建一个场 ...
 - Unity3D Shader官方教程翻译(十九)----Shader语法,编写表面着色器
		
Writing Surface Shaders Writing shaders that interact with lighting is complex. There are different ...
 - unity3d游戏开发学习分享之表面着色器讲解
		
一.三种着色器的书写格式: 1.surface shaders, 指的是表面着色器 2.vertex and fragment shaders and 指的是顶点和片段着色器 3.fixed func ...
 - Surface Shader(表面着色器)
		
Shader "Custom/Surface_Shadeer" { Properties { ...
 - 记录一个Unity播放器插件的开发
		
背景 公司最近在做VR直播平台,VR开发我们用到了Unity,而在Unity中播放视频就需要一款视频插件,我们调研了几个视频插件,记录两个,如下: Unity视频插件调研 网上搜了搜,最流行的有以下两 ...
 - Unity 着色器基础知识
		
一.着色器基础知识 着色器通过代码模拟物体表面发生的事情,其实就是GPU中运行的一段代码. 着色器的类型: 顶点着色器.片元着色器.无光照着色器.表面着色器.图像特效着色器.计算着色器. 坐标空间: ...
 - Unity 着色器训练营(2) - MVP转换和法线贴图
		
https://mp.weixin.qq.com/s/Qf4qT15s9bWjbVGh7H32lw 我们刚刚公布了Unity 2018.1中,Unity将会内置可视化编程工具Shader Graph, ...
 
随机推荐
- 单选按钮 设置required属性无法进行非空验证
			
先看代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...
 - HL7解析器
			
最近做了关于医疗的项目,用了HL7协议,以下是解析的代码: HL7解析器: using System; using System.Text; using System.Xml; using Syste ...
 - Servlet线程安全问题(转载)
			
转载地址:https://www.cnblogs.com/LipeiNet/p/5699944.html 前言:前面说了很多关于Servlet的一些基础知识,这一篇主要说一下关于Servlet的线程安 ...
 - mac机器smb映射
			
1 finder中打开前往 2 输入:smb://10.216.90.* 链接 3 输入 账户和密码(名称和密码是你机器的smb密码:比如123***)
 - 解决STM32工程出现:Undefined symbol TIM_ClearFlag (referred from hcsr04.o).错误。类型问题Undefined symbol TIM_xxx (referred from xxx.o).
			
出错原因: 工程FWLIB目录下没有添加stm32f10x_tim.c文件. 添加即可. 一般利用库开发,将ppp.c(ppp.c又调用了库stm32f10x_xx.h)写好之后的调用步骤: 举例使用 ...
 - 《MFC dialog中加入OpenGL窗体》
			
<MFC dialog中加入OpenGL窗体> 最近学习了如何在MFC对话框程序中加入OpenGL窗体的方法,在这里将自己的实现过程归纳一下. 步骤零: 加入PictureControl控 ...
 - i.MX RT1010之FlexIO模拟I2S外设
			
恩智浦的i.MX RT1010是跨界处理器产品,作为i.MX RT跨界MCU系列的一个新的切入点,i.MX RT1010是成本最低的LQFP封装方式与i.MX RT系列产品一贯的高性能和易用性的结合产 ...
 - 爬虫(十三):PIL模块
			
1. PIL模块 在爬虫(十二):图形验证码的识别.滑动验证码的识别(B站滑动验证码)中我留下了一个悬念,为什么安装的是pillow模块,而不是PIL模块.这是因为PIL是python2的产物,它并没 ...
 - 例题3_2   WERTYU(UVa10082)
			
把手放在键盘上时,稍不注意就会往右错一位.这样,输入Q会变成W,输入J会变成K等.键盘如下图所示: 输入一个错位后敲出的字符串(所有字母均大写),输出打字员本来想打出的句子.输入保证合法,即一定是错位 ...
 - js的JSON新方法和历史记录管理
			
今天看妙味的视频,一下是一些简单的笔记: 1.JSON的一些新方法: JSON.stringify(); JSON.parse(); 第一个是把js脚本转换成JSON的字符串形式. 而第二个则是吧这种 ...