下面我们开始今天的Unity3D游戏开发技能透明shader技能培训。 我们学习Unity3D培训目标:让U3D初学者可以更快速的掌握U3D技术,自行制作修改素材,可以独立完成2D、3D小规模游戏及网页游戏开发。


[plain] view plaincopy

  1. // Shader created with Shader Forge Beta 0.34

  2. // Shader Forge (c) Joachim Holmer - http://www.acegikmo.com/shaderforge/

  3. // Note: Manually altering this data may prevent you from opening it in Shader Forge

  4. /*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;*/

  5. Shader "Custom/Shader1" {

  6. Properties {

  7. _Color ("Color", Color) = (1,1,1,1)

  8. [HideInInspector]_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5

  9. }

  10. SubShader {

  11. Tags {

  12. "IgnoreProjector"="True"

  13. "Queue"="Transparent"

  14. "RenderType"="Transparent"

  15. }

  16. LOD 200

  17. Pass {

  18. Name "ForwardBase"

  19. Tags {

  20. "LightMode"="ForwardBase"

  21. }

  22. Blend SrcAlpha OneMinu***cAlpha

  23. ZWrite Off

  24. CGPROGRAM

  25. #pragma vertex vert

  26. #pragma fragment frag

  27. #define UNITY_PASS_FORWARDBASE

  28. #include "UnityCG.cginc"

  29. #pragma multi_compile_fwdbase

  30. #pragma exclude_renderers xbox360 ps3 flash d3d11_9x

  31. #pragma target 3.0

  32. uniform float4 _LightColor0;

  33. uniform float4 _Color;

  34. struct VertexInput {

  35. float4 vertex : POSITION;

  36. float3 normal : NORMAL;

  37. };

  38. struct VertexOutput {

  39. float4 pos : SV_POSITION;

  40. float4 posWorld : TEXCOORD0;

  41. float3 normalDir : TEXCOORD1;

  42. };

  43. VertexOutput vert (VertexInput v) {

  44. VertexOutput o;

  45. o.normalDir = mul(float4(v.normal,0), _World2Object).xyz;

  46. o.posWorld = mul(_Object2World, v.vertex);

  47. o.pos = mul(UNITY_MATRIX_MVP, v.vertex);

  48. return o;

  49. }

  50. fixed4 frag(VertexOutput i) : COLOR {

  51. i.normalDir = normalize(i.normalDir);

  52. float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);

  53. /// Normals:

  54. float3 normalDirection =  i.normalDir;

  55. float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz);

  56. // Lighting:

  57. float attenuation = 1;

  58. float3 attenColor = attenuation * _LightColor0.xyz;

  59. /// Diffuse:

  60. float NdotL = dot( normalDirection, lightDirection );

  61. float3 diffuse = max( 0.0, NdotL) * attenColor + UNITY_LIGHTMODEL_AMBIENT.rgb;

  62. float3 finalColor = 0;

  63. float3 diffuseLight = diffuse;

  64. finalColor += diffuseLight * _Color.rgb;

  65. /// Final Color:

  66. return fixed4(finalColor,(1.0-max(0,dot(normalDirection, viewDirection))));

  67. }

  68. ENDCG

  69. }

  70. Pass {

  71. Name "ForwardAdd"

  72. Tags {

  73. "LightMode"="ForwardAdd"

  74. }

  75. Blend One One

  76. ZWrite Off

  77. Fog { Color (0,0,0,0) }

  78. CGPROGRAM

  79. #pragma vertex vert

  80. #pragma fragment frag

  81. #define UNITY_PASS_FORWARDADD

  82. #include "UnityCG.cginc"

  83. #include "AutoLight.cginc"

  84. #pragma multi_compile_fwdadd

  85. #pragma exclude_renderers xbox360 ps3 flash d3d11_9x

  86. #pragma target 3.0

  87. uniform float4 _LightColor0;

  88. uniform float4 _Color;

  89. struct VertexInput {

  90. float4 vertex : POSITION;

  91. float3 normal : NORMAL;

  92. };

  93. struct VertexOutput {

  94. float4 pos : SV_POSITION;

  95. float4 posWorld : TEXCOORD0;

  96. float3 normalDir : TEXCOORD1;

  97. LIGHTING_COORDS(2,3)

  98. };

  99. VertexOutput vert (VertexInput v) {

  100. VertexOutput o;

  101. o.normalDir = mul(float4(v.normal,0), _World2Object).xyz;

  102. o.posWorld = mul(_Object2World, v.vertex);

  103. o.pos = mul(UNITY_MATRIX_MVP, v.vertex);

  104. TRANSFER_VERTEX_TO_FRAGMENT(o)

  105. return o;

  106. }

  107. fixed4 frag(VertexOutput i) : COLOR {

  108. i.normalDir = normalize(i.normalDir);

  109. float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);

  110. /// Normals:

  111. float3 normalDirection =  i.normalDir;

  112. float3 lightDirection = normalize(lerp(_WorldSpaceLightPos0.xyz, _WorldSpaceLightPos0.xyz - i.posWorld.xyz,_WorldSpaceLightPos0.w));

  113. // Lighting:

  114. float attenuation = LIGHT_ATTENUATION(i);

  115. float3 attenColor = attenuation * _LightColor0.xyz;

  116. /// Diffuse:

  117. float NdotL = dot( normalDirection, lightDirection );

  118. float3 diffuse = max( 0.0, NdotL) * attenColor;

  119. float3 finalColor = 0;

  120. float3 diffuseLight = diffuse;

  121. finalColor += diffuseLight * _Color.rgb;

  122. /// Final Color:

  123. return fixed4(finalColor * (1.0-max(0,dot(normalDirection, viewDirection))),0);

  124. }

  125. ENDCG

  126. }

  127. }

  128. FallBack "Diffuse"

  129. CustomEditor "ShaderForgeMaterialInspector"

  130. }

    更多精彩unity3d技术文章请点击 http://www.gopedu.com/article

转载于:https://blog.51cto.com/1248359860/1558051

unity3d游戏开发之简单的透明shader技能培训相关推荐

  1. android+Unity3D游戏开发之简单的物体运动

    android+Unity3D游戏开发之简单的物体运动 其实这篇也是转载的,真的感觉对于我们初学者来说很不错的,不信你看看嘛;原创链接:http://bbs.9ria.com/thread-98192 ...

  2. Unity3D游戏开发-宣雨松读书摘要(2015-4-17 18:36)

    本书基于Unity3.5编写,通过丰富的游戏实例,以JavaScript与C#两种语言介绍Unity开发. Unity3D游戏开发-宣雨松 序 它支持JavaScript.C#.Boo三种脚本语言 ...

  3. 《学Unity的猫》——第十八集:Unity3D游戏开发工程师笔试刷题,皮皮收到面试邀请

    文章目录 18.1 皮皮收到面试邀请 18.2 面试题库相关网站 18.2.1 牛客网 18.2.2 领扣LintCode 18.2.3 力扣LeetCode 18.3 优质学习网站 18.3.1 菜 ...

  4. 从一点儿不会开始——Unity3D游戏开发学习(一)

    一些废话 我是一个windows phone.windows 8的忠实粉丝,也是一个开发者,开发数个windows phone应用和两个windows 8应用.对开发游戏一直抱有强烈兴趣和愿望,但奈何 ...

  5. Unity3D游戏开发之仿仙剑奇侠传一2D游戏 (一)

    今天要和大家分享的是基于Unity3D开发2D游戏,博主一直钟爱于国产武侠RPG,这个我在开始写Unity3D游戏开发系列文章的时候就已经说过了,所以我们今天要做的就是利用Unity3D来实现在2D游 ...

  6. Unity3D游戏开发之邂逅Unity3D

    从今天起,博主决定要在毕业前把大学里想学的东西都学完.所以,从今天起,大家将看到由我为大家带来的Unity3D系列文章,让我们一起来学习Unity3D游戏开发吧! 在正式今天的文章之前,博主想简单介绍 ...

  7. [Unity3D]Unity3D游戏开发之鼠标旋转、缩放实现3D物品展示

    各位朋友,大家好,我是秦元培,欢迎大家关注我的博主,我的博客地址是blog.csdn.net/qinyuanpei.最近博主重点研究了摄像机旋转.缩放等问题,那么今天为大家分享的是一个在3D展示中比较 ...

  8. 7小时Unity3D游戏开发培训教程

    获取地址:7小时Unity3D游戏开发培训教程 中文名: 7小时Unity3D游戏开发培训教程 英文名: Over 7 hours of Unity Training Videos 资源格式: 光盘镜 ...

  9. Unity3D游戏开发初探—2.初步了解3D模型基础

    一.什么是3D模型? 1.1 3D模型概述 简而言之,3D模型就是三维的.立体的模型,D是英文Dimensions的缩写. 3D模型也可以说是用3Ds MAX建造的立体模型,包括各种建筑.人物.植被. ...

  10. Unity3D游戏开发第三人称角色控制的模式

    众所周知,在Unity3D游戏开发中,经常会用到角色控制,一般情况下角色控制有第一人称和第三人称两种,在 RPG 游戏中通常以第三人称的形式出现.而对于第三人称角色控制而言,通常有 2 种模式,我们今 ...

最新文章

  1. Microsoft SharePoint Server 2016 部署文档(2)
  2. java进销存培训_Java实例学习——企业进销存管理系统(2)
  3. Jquery插件(一) webupload上传插件
  4. javaSE各阶段练习题--面向对象-StringBuilder-继承-包和访问权限
  5. eslint vscode 自动格式化_使用 VSCode 的必备三大神器,这才是开发 Vue 的真香解决方案...
  6. nosql简答什么是最终一致性_可靠消息最终一致性方案中预发送作用是什么
  7. 16 张图解带你掌握一致性哈希算法
  8. mysql数据库约束详解_基于MySQL数据库的数据约束实例及五种完整性约束介绍
  9. Microsoft Excel 不能访问文件
  10. CCF201812-2 小明放学(100分)【序列处理】
  11. Ilasm And Ildasm Practice
  12. 吾儿秘史--趣事糗事大杂烩第二季(2014.6.2-)-更新到2014年9月8日
  13. 解决 Web、软件 视频播放黑屏
  14. 面试重点:starter原理以及自己动手实现一个starter
  15. 题目 1567: 超级玛丽
  16. maven找不到,变小蜘蛛问题
  17. osgEarth在斜面内绕自身Z轴旋转的锥体
  18. insmod depmod modprobe的区别及用法
  19. Keil5最新版本下载(MDK 5.25, C51v959)
  20. 解决win7系统print spooler打印服务自动关闭、无法添加打印机

热门文章

  1. ka电器表示什么意思_电气原理中,QS、FU、KM、KA、KI、KT、SB、SQ分别是什么电器元件的文字符号?...
  2. android 获取默认字体,Android中的默认字体系列是什么?
  3. php用for循环输出九九乘法表,php循环之打印九九乘法表
  4. 未来人类笔记本 T5 67SH2 扩展内存条
  5. silktest 破解 转帖未验证
  6. 基于PHP的留言板毕业论文,网络留言板
  7. Qt6 tesseract-ocr 截图识字
  8. TCP协议下的recv函数
  9. 如何把空间数据从CGCS2000转换到WGS84和BD09 ——JAVA语言实现
  10. python插值算法_python插值算法