unity3d游戏开发之简单的透明shader技能培训
下面我们开始今天的Unity3D游戏开发技能透明shader技能培训。 我们学习Unity3D培训目标:让U3D初学者可以更快速的掌握U3D技术,自行制作修改素材,可以独立完成2D、3D小规模游戏及网页游戏开发。
[plain] view plaincopy
// Shader created with Shader Forge Beta 0.34
// Shader Forge (c) Joachim Holmer - http://www.acegikmo.com/shaderforge/
// Note: Manually altering this data may prevent you from opening it in Shader Forge
/*SF_DATA;ver:0.34;sub:START;pass:START;ps:flbk:,lico:1,lgpr:1,nrmq:1,limd:1,uamb:True,mssp:True,lmpd:False,lprd:False,enco:False,frtr:True,vitr:True,dbil:False,rmgx:True,rpth:0,hqsc:True,hqlp:False,blpr:1,bsrc:3,bdst:7,culm:0,dpts:2,wrdp:False,ufog:True,aust:True,igpj:True,qofs:0,qpre:3,rntp:2,fgom:False,fgoc:False,fgod:False,fgor:False,fgmd:0,fgcr:0.5,fgcg:0.5,fgcb:0.5,fgca:1,fgde:0.01,fgrn:0,fgrf:300,ofsf:0,ofsu:0,f2p0:False;n:type:ShaderForge.SFN_Final,id:3,x:32038,y:32598|diff-227-RGB,alpha-226-OUT;n:type:ShaderForge.SFN_Fresnel,id:226,x:32459,y:32705;n:type:ShaderForge.SFN_Color,id:227,x:32398,y:32551,ptlb:Color,ptin:_Color,glob:False,c1:1,c2:1,c3:1,c4:1;proporder:227;pass:END;sub:END;*/
Shader "Custom/Shader1" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
[HideInInspector]_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
}
SubShader {
Tags {
"IgnoreProjector"="True"
"Queue"="Transparent"
"RenderType"="Transparent"
}
LOD 200
Pass {
Name "ForwardBase"
Tags {
"LightMode"="ForwardBase"
}
Blend SrcAlpha OneMinu***cAlpha
ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#define UNITY_PASS_FORWARDBASE
#include "UnityCG.cginc"
#pragma multi_compile_fwdbase
#pragma exclude_renderers xbox360 ps3 flash d3d11_9x
#pragma target 3.0
uniform float4 _LightColor0;
uniform float4 _Color;
struct VertexInput {
float4 vertex : POSITION;
float3 normal : NORMAL;
};
struct VertexOutput {
float4 pos : SV_POSITION;
float4 posWorld : TEXCOORD0;
float3 normalDir : TEXCOORD1;
};
VertexOutput vert (VertexInput v) {
VertexOutput o;
o.normalDir = mul(float4(v.normal,0), _World2Object).xyz;
o.posWorld = mul(_Object2World, v.vertex);
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
return o;
}
fixed4 frag(VertexOutput i) : COLOR {
i.normalDir = normalize(i.normalDir);
float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
/// Normals:
float3 normalDirection = i.normalDir;
float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz);
// Lighting:
float attenuation = 1;
float3 attenColor = attenuation * _LightColor0.xyz;
/// Diffuse:
float NdotL = dot( normalDirection, lightDirection );
float3 diffuse = max( 0.0, NdotL) * attenColor + UNITY_LIGHTMODEL_AMBIENT.rgb;
float3 finalColor = 0;
float3 diffuseLight = diffuse;
finalColor += diffuseLight * _Color.rgb;
/// Final Color:
return fixed4(finalColor,(1.0-max(0,dot(normalDirection, viewDirection))));
}
ENDCG
}
Pass {
Name "ForwardAdd"
Tags {
"LightMode"="ForwardAdd"
}
Blend One One
ZWrite Off
Fog { Color (0,0,0,0) }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#define UNITY_PASS_FORWARDADD
#include "UnityCG.cginc"
#include "AutoLight.cginc"
#pragma multi_compile_fwdadd
#pragma exclude_renderers xbox360 ps3 flash d3d11_9x
#pragma target 3.0
uniform float4 _LightColor0;
uniform float4 _Color;
struct VertexInput {
float4 vertex : POSITION;
float3 normal : NORMAL;
};
struct VertexOutput {
float4 pos : SV_POSITION;
float4 posWorld : TEXCOORD0;
float3 normalDir : TEXCOORD1;
LIGHTING_COORDS(2,3)
};
VertexOutput vert (VertexInput v) {
VertexOutput o;
o.normalDir = mul(float4(v.normal,0), _World2Object).xyz;
o.posWorld = mul(_Object2World, v.vertex);
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
TRANSFER_VERTEX_TO_FRAGMENT(o)
return o;
}
fixed4 frag(VertexOutput i) : COLOR {
i.normalDir = normalize(i.normalDir);
float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
/// Normals:
float3 normalDirection = i.normalDir;
float3 lightDirection = normalize(lerp(_WorldSpaceLightPos0.xyz, _WorldSpaceLightPos0.xyz - i.posWorld.xyz,_WorldSpaceLightPos0.w));
// Lighting:
float attenuation = LIGHT_ATTENUATION(i);
float3 attenColor = attenuation * _LightColor0.xyz;
/// Diffuse:
float NdotL = dot( normalDirection, lightDirection );
float3 diffuse = max( 0.0, NdotL) * attenColor;
float3 finalColor = 0;
float3 diffuseLight = diffuse;
finalColor += diffuseLight * _Color.rgb;
/// Final Color:
return fixed4(finalColor * (1.0-max(0,dot(normalDirection, viewDirection))),0);
}
ENDCG
}
}
FallBack "Diffuse"
CustomEditor "ShaderForgeMaterialInspector"
}
更多精彩unity3d技术文章请点击 http://www.gopedu.com/article
转载于:https://blog.51cto.com/1248359860/1558051
unity3d游戏开发之简单的透明shader技能培训相关推荐
- android+Unity3D游戏开发之简单的物体运动
android+Unity3D游戏开发之简单的物体运动 其实这篇也是转载的,真的感觉对于我们初学者来说很不错的,不信你看看嘛;原创链接:http://bbs.9ria.com/thread-98192 ...
- Unity3D游戏开发-宣雨松读书摘要(2015-4-17 18:36)
本书基于Unity3.5编写,通过丰富的游戏实例,以JavaScript与C#两种语言介绍Unity开发. Unity3D游戏开发-宣雨松 序 它支持JavaScript.C#.Boo三种脚本语言 ...
- 《学Unity的猫》——第十八集:Unity3D游戏开发工程师笔试刷题,皮皮收到面试邀请
文章目录 18.1 皮皮收到面试邀请 18.2 面试题库相关网站 18.2.1 牛客网 18.2.2 领扣LintCode 18.2.3 力扣LeetCode 18.3 优质学习网站 18.3.1 菜 ...
- 从一点儿不会开始——Unity3D游戏开发学习(一)
一些废话 我是一个windows phone.windows 8的忠实粉丝,也是一个开发者,开发数个windows phone应用和两个windows 8应用.对开发游戏一直抱有强烈兴趣和愿望,但奈何 ...
- Unity3D游戏开发之仿仙剑奇侠传一2D游戏 (一)
今天要和大家分享的是基于Unity3D开发2D游戏,博主一直钟爱于国产武侠RPG,这个我在开始写Unity3D游戏开发系列文章的时候就已经说过了,所以我们今天要做的就是利用Unity3D来实现在2D游 ...
- Unity3D游戏开发之邂逅Unity3D
从今天起,博主决定要在毕业前把大学里想学的东西都学完.所以,从今天起,大家将看到由我为大家带来的Unity3D系列文章,让我们一起来学习Unity3D游戏开发吧! 在正式今天的文章之前,博主想简单介绍 ...
- [Unity3D]Unity3D游戏开发之鼠标旋转、缩放实现3D物品展示
各位朋友,大家好,我是秦元培,欢迎大家关注我的博主,我的博客地址是blog.csdn.net/qinyuanpei.最近博主重点研究了摄像机旋转.缩放等问题,那么今天为大家分享的是一个在3D展示中比较 ...
- 7小时Unity3D游戏开发培训教程
获取地址:7小时Unity3D游戏开发培训教程 中文名: 7小时Unity3D游戏开发培训教程 英文名: Over 7 hours of Unity Training Videos 资源格式: 光盘镜 ...
- Unity3D游戏开发初探—2.初步了解3D模型基础
一.什么是3D模型? 1.1 3D模型概述 简而言之,3D模型就是三维的.立体的模型,D是英文Dimensions的缩写. 3D模型也可以说是用3Ds MAX建造的立体模型,包括各种建筑.人物.植被. ...
- Unity3D游戏开发第三人称角色控制的模式
众所周知,在Unity3D游戏开发中,经常会用到角色控制,一般情况下角色控制有第一人称和第三人称两种,在 RPG 游戏中通常以第三人称的形式出现.而对于第三人称角色控制而言,通常有 2 种模式,我们今 ...
最新文章
- Microsoft SharePoint Server 2016 部署文档(2)
- java进销存培训_Java实例学习——企业进销存管理系统(2)
- Jquery插件(一) webupload上传插件
- javaSE各阶段练习题--面向对象-StringBuilder-继承-包和访问权限
- eslint vscode 自动格式化_使用 VSCode 的必备三大神器,这才是开发 Vue 的真香解决方案...
- nosql简答什么是最终一致性_可靠消息最终一致性方案中预发送作用是什么
- 16 张图解带你掌握一致性哈希算法
- mysql数据库约束详解_基于MySQL数据库的数据约束实例及五种完整性约束介绍
- Microsoft Excel 不能访问文件
- CCF201812-2 小明放学(100分)【序列处理】
- Ilasm And Ildasm Practice
- 吾儿秘史--趣事糗事大杂烩第二季(2014.6.2-)-更新到2014年9月8日
- 解决 Web、软件 视频播放黑屏
- 面试重点:starter原理以及自己动手实现一个starter
- 题目 1567: 超级玛丽
- maven找不到,变小蜘蛛问题
- osgEarth在斜面内绕自身Z轴旋转的锥体
- insmod depmod modprobe的区别及用法
- Keil5最新版本下载(MDK 5.25, C51v959)
- 解决win7系统print spooler打印服务自动关闭、无法添加打印机
热门文章
- ka电器表示什么意思_电气原理中,QS、FU、KM、KA、KI、KT、SB、SQ分别是什么电器元件的文字符号?...
- android 获取默认字体,Android中的默认字体系列是什么?
- php用for循环输出九九乘法表,php循环之打印九九乘法表
- 未来人类笔记本 T5 67SH2 扩展内存条
- silktest 破解 转帖未验证
- 基于PHP的留言板毕业论文,网络留言板
- Qt6 tesseract-ocr 截图识字
- TCP协议下的recv函数
- 如何把空间数据从CGCS2000转换到WGS84和BD09 ——JAVA语言实现
- python插值算法_python插值算法