- 博客(152)
- 资源 (1)
- 收藏
- 关注
原创 在Unity3d中创建一个简单的Mesh
假如我们要创建如下一个网格,该怎么做呢?这是个4x4的网格,一共有25个顶点,16x2个三角形。建个坐标系如下图:1.创建顶点:如坐标系所示,我们的25个顶点为:(0,4)(1,4)(2,4)(3,4)(4,4)(0,3)(1,3)(2,3)(3,3)(4,3)(0,2)(1,2)(2,2)(3,2)(4,2)(0,1)(1,1)(2,1)(3,1)(4,1...
2018-07-28 18:08:26 5248
原创 Unity中写GLSL(二十一)—— Cook-Torrance— Fresnel
参考:http://www.codinglabs.net/article_physically_based_rendering_cook_torrance.aspx下面是效果: 其实之前的文章就写过菲涅尔反射了。 下面是代码:Shader "Custom/FresnalShader"{ Properties { _DiffuseColor ("Diffuse C
2018-02-01 20:09:15 421
原创 Unity中写GLSL(二十)—— Cook-Torrance—Geometry
参考:http://www.codinglabs.net/article_physically_based_rendering_cook_torrance.aspx这个函数是关于microfacet方面的。roughness为0时如图: roughness为0.2时如图: roughness为0.5时如图: roughness为0.8时如图: roughness为1时如图: 最后是代码:
2018-02-01 17:05:33 477
原创 Unity中写GLSL(十九)—— Cook-Torrance—Distribution
参考http://www.codinglabs.net/article_physically_based_rendering_cook_torrance.aspx这个分布函数其实就是靠roughness来改变高光分布的意思。roughness为0.01时如图: roughness为0.2时如图: roughness为0.6时如图: roughness为1时如图: 下面是代码: 这代码只是拿
2018-02-01 16:10:44 572
原创 Unity中写GLSL(十八)—— 创建Diffuse环境贴图和Specular环境贴图
参考了WIKI:https://en.wikibooks.org/wiki/GLSL_Programming/Unity/Many_Light_Sources 具体的可以到这个wiki上面去看,我这里只给结果。(写太多东西太麻烦。。。) 这是生成的Diffuse环境贴图: 这是生成的Specular环境贴图: 下面是代码:using System.Collections;using Sys
2018-01-31 17:02:01 2752
原创 Unity中写GLSL(十七)—— 半球光照
参考wiki:https://en.wikibooks.org/wiki/GLSL_Programming/Unity/Diffuse_Reflection_of_Skylight先上图: 然后是代码:Shader "Custom/ShaderExample18"{ Properties { _Color ("Diffuse Material Color", Co
2018-01-29 16:42:07 737 1
原创 Unity中写GLSL(十六)—— 菲涅尔反射
参考了wiki:https://en.wikibooks.org/wiki/GLSL_Programming/Unity/Specular_Highlights_at_Silhouettes先上图:不过看不太出什么区别 然后是代码:Shader "Custom/ShaderExample17"{ Properties { _Color ("Diffuse Mate
2018-01-29 16:38:23 772
原创 Unity中写GLSL(十五)—— 折射
先上图: 因为天空盒的问题,所以黑色那部分看上去不太对,但是大概就是这个样子。 然后是代码:Shader "Custom/ShaderExample14"{ Properties { _Cube ("Environment Map", Cube) = "" {} } SubShader { Pass {
2018-01-25 13:08:59 427
原创 Unity中写GLSL(十四)—— Unity中的Projector
上图: 和之前的cookie差不多,是种投影仪的感觉,阴影也可以靠这个实现。下面是代码:Shader "Custom/ShaderExample13"{ Properties { _ShadowTex ("Projected Image", 2D) = "white" {} } SubShader { Pass
2018-01-24 12:55:09 602
原创 Unity中写GLSL(十三)—— light cookie
参考WIKI:https://en.wikibooks.org/wiki/GLSL_Programming/Unity/Cookies light cookie其实是这么个效果: 首先在PhotoShop里画了一张有透明部分的图,储存成PNG格式: 把cookie.png拖进unity3d,然后需要设置一下光源的cookie和cookie size, 然后效果如图: 最后是代码:Shade
2018-01-22 14:27:25 2816 2
转载 Unity中写GLSL(十二)—— layer texture
参考了WIKI:https://en.wikibooks.org/wiki/GLSL_Programming/Unity/Layers_of_Textures 先上图: 两张图片是根据lightDir与normal的夹角来确定混合权重的,所以放两张图: 下面是代码:Shader "Custom/ShaderExample10"{ Properties { _D
2018-01-21 17:19:48 674
原创 Unity中写GLSL(十一)—— 双面材质
先上图:左边是背面,右边是正面 然后是代码:Shader "Custom/ShaderExample9"{ Properties { _Color ("Front Material Diffuse Color", Color) = (1,1,1,1) _SpecColor ("Front Material Specular Color", Colo
2018-01-21 14:19:42 513
原创 Unity中写GLSL(十)—— Specular + Diffuse
先上图: 这光照是在顶点着色器里计算的,如果在片元着色器中计算效果会好一些。然后是代码:Shader "Custom/ShaderExample8"{ Properties { _Color ("Diffuse Material Color", Color) = (1, 1, 1, 1) _SpecColor ("Specular Material
2018-01-20 20:31:50 512
原创 Unity中写GLSL(九)—— 渲染简单的透明物体
参照了wiki:https://en.wikibooks.org/wiki/GLSL_Programming/Unity/Transparency先上图: 下面是代码:Shader "Custom/ShaderExample6"{ Properties { } SubShader { Tags { "Queue" = "Transparent
2018-01-14 19:30:40 1013
原创 Unity中写GLSL(八)—— 方向光 + Normal Map + Diffuse Map + AO Map
先上图: 下面是代码Shader "Custom/ShaderExample5"{ Properties { _MainTex ("Texture", 2D) = "white" {} //diffuse _BumpMap("Normal Map", 2D) = "bump" {} //normal _OcclusionMap
2018-01-14 18:53:31 1209
原创 Unity中写GLSL(七)—— 程序式纹理:棋盘格
先上图:原理:在顶点着色器中先把uv乘以density,这样uv的range就从0 - 1变成了0 - density。 然后在片元着色器中把uv值取整再除以2,这样uv值就变成了0, 0.5, 1, 1.5, 2, 2.5 。。。 接着把x,y相加,值为0, 0.5, 1, 1.5 。。。 再取小数,值为0或者0.5 再乘以2,值为0或者1 最后取颜色。然后是代码:
2018-01-14 16:32:10 1504
原创 Unity中写GLSL(六)—— 环境skybox反射 + Normal Map + Diffuse Map + AO Map
先上图:再来是代码:Shader "Custom/ShaderExample3"{ Properties { _MainTex ("Texture", 2D) = "white" {} //duffuse _BumpMap("Normal Map", 2D) = "bump" {} //normal _Occl
2018-01-14 15:53:38 363
原创 Unity中写GLSL(五)—— 环境skybox反射 + Normal Map
先上图: 这normal map是从3dsmax里面导出的。注意:normal map在Unity3d中的texture type要保持默认default才行。下面是代码:Shader "Custom/ShaderExample2"{ Properties { _BumpMap("Normal Map", 2D) = "bump" {}
2018-01-13 20:09:16 469
原创 Unity中写GLSL(四)—— 环境skybox反射
先上图: 看着不太对是因为skybox的问题,skybox没底部图片,所以用了top图片。下面是代码:Shader "Custom/ShaderExample2"{ Properties { _Cube("Reflection Map", Cube) = "" {} } SubShader { Pass
2018-01-13 16:31:24 626
原创 Unity中写GLSL —— 常用的一些内置变量
本页的内容参考了Wiki:https://en.wikibooks.org/wiki/GLSL_Programming/Unity/Shading_in_World_Space首先是一些顶点相关的:gl_Vertex //模型坐标gl_Position //projection过后顶点坐标gl_MultiTexCoord0 //uv坐标gl_Normal //法线gl_FragCo
2018-01-13 14:09:59 1018
原创 Unity中写GLSL(三)—— 试试法线Normal
这里只是把法线当做color来用。法线的range是-1 - 1所以要转换range到0 - 1。下面上图:下面是代码:Shader "Custom/ShaderExample1"{ Properties { _MainTex ("Texture", 2D) = "white" {} } SubShader { Pass
2018-01-13 13:50:48 713
原创 Unity中写GLSL(二)—— Unlit着色器,无光照,只从纹理采样
GLSL语法用的330之后的语法。先上图: 棋盘格纹理是我百度随便找的。 下面是代码:Shader "Unlit/UnlitShader_GL"{ Properties { _MainTex ("Texture", 2D) = "white" {} //纹理 } SubShader { Pass {
2018-01-12 21:34:50 823
原创 GameEntity(十一)—— Iplayer
目录为:Assets/Scripts/GameEntity/目录下 Iplayer.csplayer接口using UnityEngine;using System.Collections;using System.Collections.Generic;using System;//继承Ientitypublic class Iplayer: Ientity{ //吸附特效
2017-11-06 20:17:13 381
原创 GameEntity(十)—— Mail
目录为:Assets/Scripts/GameEntity/目录下 Mail.csusing System;using System.Collections.Generic;//邮件状态public enum EMailCurtState{ eMailState_None = 0, eMailState_New = 1, eMailState_LookedButNot
2017-11-02 16:11:49 317
原创 GameEntity(九)—— InviteOtherPlayer
目录为:Assets/Scripts/GameEntity/目录下 InviteOtherPlayer.cs邀请好友类using UnityEngine;using System.Collections;using System;using System.Collections.Generic;//邀请好友public class InviteOtherPlayer{ //sta
2017-11-02 15:56:41 176
原创 GameEntity(八)—— FriendManager
目录为:Assets/Scripts/GameEntity/目录下 FriendManager.cs好友管理类using UnityEngine;using System.Collections;using System.Collections.Generic;using System;//好友管理类public class FriendManager{ //static
2017-11-01 16:57:57 197
原创 GameEntity(七)—— Friend
目录为:Assets/Scripts/GameEntity/目录下 Friend.cs看来是好友类using System;using System.Collections.Generic;//好友public class Friend{ public UInt64 SGUID { private set; get; } //是否
2017-11-01 15:55:45 169
原创 GameEntity(六)—— IChat
目录为:Assets/Scripts/GameEntity/目录下 IChat.cs聊天的接口类using UnityEngine;using System.Collections;using System.Collections.Generic;using System;//看来是聊天相关的接口public class IChat{ public UInt64 SGUID
2017-11-01 15:25:08 314
原创 GameEntity(五)—— INpc
目录为:Assets/Scripts/GameEntity/目录下 INpc.cs这是Npc的接口类using UnityEngine;using System.Collections;using System;//Npc的接口public class INpc: Ientity{ //调用Ientity的构造函数 public INpc(UInt64 sGUID, Ent
2017-11-01 15:13:20 227
原创 Unity中写GLSL(一)—— 简单的diffuse color
写这篇文章主要是为了记录一下需要用到的Unity提供的变量等等。 参考了WiKi:GLSL Programming/Unity/Diffuse Reflection注意要给Unity添加启动项才行,像这样 强制使用opengl,这样才能测试shader下面是shader代码,Wiki上的不好用了,改了一下的Shader "GLSL per-vertex diffuse lighting" {
2017-11-01 13:50:11 2257
原创 GameEntity(四)—— Ientity
目录为:Assets/Scripts/GameEntity/目录下 Ientity.cs这是Entity的接口using System;using System.Collections;using System.Collections.Generic;using UnityEngine;//最主要的游戏实体//整个Entity的接口public class Ientity{ /
2017-10-31 21:44:55 906
原创 GameEntity(三)—— EntityStrategyHelper
目录为:Assets/Scripts/GameEntity/目录下 EntityStrategyHelper.csusing UnityEngine;using System.Collections;public static class EntityStrategyHelper{ public const float MoveCheckBlockTick = 1.0f; pu
2017-10-30 14:03:58 235
原创 GameEntity(二)—— EntityType
目录为:Assets/Scripts/GameEntity/目录下 EntityType.csusing UnityEngine;using System.Collections;public enum EntityType{ Monster = 1, Soldier, Buiding, Player, AltarSoldier}public enum
2017-10-29 17:13:59 366
原创 GameEntity(一) —— CampType
目录为:Assets/Scripts/GameEntity/目录下 CampType.cs这次先从Entity入手,好多地方都涉及到这一部分。using UnityEngine;using System.Collections;public enum EntityCampType{ CampTypeNull = -2, CampTypeBad, //全敌对 Cam
2017-10-29 16:56:59 320
原创 Effect(二十二)—— SM_UVScroller
目录为:Assets/Media/Effect/Scripts/目录下 SM_UVScroller.csusing UnityEngine;using System.Collections;//UV滚动public class SM_UVScroller: MonoBehaviour{ public int targetMaterialSlot = 0; public Mat
2017-10-28 16:11:42 227
原创 Effect(二十一)—— SM_TransRimShaderIrisator
目录为:Assets/Media/Effect/Script/目录下 SM_TransRimShaderIrisator.csusing UnityEngine;using System.Collections;public class SM_TransRimShaderIrisator: MonoBehaviour{ public float topStr = 2.0f; p
2017-10-28 16:00:16 259
原创 Effect(二十)—— SM_TransRimShaderFader
目录为:Assets/Media/Effect/Script/目录下 SM_TransRimShaderFader.cs没找到在哪用。using UnityEngine;using System.Collections;public class SM_TransRimShaderFader: MonoBehaviour{ public float startStr = 2.0f;
2017-10-28 15:49:15 186
原创 Effect(十九)—— SM_TrailFade
目录为:Assets/Media/Effect/Script/目录下 SM_TrailFade.csusing UnityEngine;using System.Collections;public class SM_TrailFade: MonoBehaviour{ public float fadeInTime = 0.1f; public float stayTime =
2017-10-27 16:47:30 170
原创 Effect(十八)—— SM_RotateThis
目录为:Assets/Media/Effect/Script/目录下 SM_RotateThis.csusing UnityEngine;using System.Collections;//rotatepublic class SM_rotateThis: MonoBehaviour{ public float rotationSpeedX = 90; public flo
2017-10-27 16:32:27 219
原创 Effect(十七)—— SM_MoveThis
目录为:Assets/Media/Effect/Script/目录下 SM_MoveThis.csusing UnityEngine;using System.Collections;//就只是不停移动而已public class SM_MoveThis: MonoBehaviour{ public float translationSpeedX = 0; public fl
2017-10-27 16:15:49 221
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人