Skip to content

Instantly share code, notes, and snippets.

View stilllisisi's full-sized avatar
🎯
Focusing

stilllisisi

🎯
Focusing
View GitHub Profile
@stilllisisi
stilllisisi / RimLight.shader
Created March 12, 2020 02:20
【游戏-Shader】shader实现边缘自定角度高光、描边、闪烁效果
Shader"QQ/RimLight"{
Properties{
_Color("Color",Color)=(1,1,1,1)
_MainTex("纹理",2D)="white"{}
<spanstyle="white-space:pre"> </span>_LightColor("灯颜色",Color)=(1,1,1,1)
_LightDir("灯方向",Vector)=(0,1,0,1)
_OutLine("描边颜色",Color)=(1,1,1,1)
_EdgeChange("描边大小",Range(0,.1))=.05
_FlickerTime("闪烁时间,0为关闭",Range(0,2))=1
}
@stilllisisi
stilllisisi / AlphaSkinShader.shader
Created March 12, 2020 02:04
【游戏-Unity】Unity使用RenderTexture实现实时阴影绘制。一般实时阴影主要出现在角色、怪物的脚底为了然场景表现的更加逼真,主要用三种方式:脚底放个阴影图片跟着主角动,通过摄像机的RenderRexture绘制显示,直接使用Unity的Projector组件。在3D场景绘制脚底阴影,为了让阴影效果更加逼真,使用RenderTexture的方式实现实时阴影绘制的效果。
//给小骨模型做了一个御剑的动画,剑贴图所在的面片layer调整的也和主角模型一样的时候,发现居然还是看不到剑的阴影。
//这个时候还对专门针对map(显示阴影的面片)材质写一个Shader,就不能用默认的Transparent/Diffuse了,并且最终剑这种透明贴图的还需要使用Unlit/Transparent,新添加的Shader详细代码如下:
///作为带Alpha通道的模型贴图的shader
Shader “MyShader/AlphaSkinShader”
{
Properties
{
_Color(“Main Color”,Color)=(1,1,1,1)
_MainTex (“Base (RGB)”, 2D) = “white” {}
_Cutoff(“Base Alpha cutoff”,Range(0,0.9))=0.2
@stilllisisi
stilllisisi / ComputeShader.cs
Created March 11, 2020 11:03
【游戏-网格】使用ComputeShader实现实例化大网格,主要也是借助了ComputeShader对于运行的图形库的支持,包括DX11、DX12、OpenGL4.3+、OpenGLES3等,在涉及到大量的数学计算时,并且是可以并行的没有很多分支的计算,都可以采用ComputeShader。
//ComputeShader代码:
#pragma kernel Init
#pragma kernel Emit
#pragma kernel Update
#include "./ComputeBuffer.cginc"
RWStructuredBuffer<Particle> _Particles;
int _xMod, _yMod, _zMod;
float4 _Scale;
float4 _Pos;
float _Time;
@stilllisisi
stilllisisi / RegistDB.php
Created March 11, 2020 10:56
【游戏-网络】Unity和PHP的Http数据交互。经常需要做一些简单的数据统计,可以使用Socket写的服务端交互,也可以用http的交互。本篇文章实现Unity与PHP的Http数据交互。
//PHP注册代码,每次访问都需要开关一次数据库,可以借助数据库连接池来解决此问题。
<?php
include 'Common.php';//引用包含Check方法的php文件,这个是自己写的,一种检测非法手段,可以百度下,也可以不写
$name=Check($_POST["name"]);//PHP获取form内容的方法,$name=$_POST["name"];
$pass=Check($_POST["pass"]);
$con=mysql_connect("127.0.0.1","root","");//连接mysql
if(!$con)
die("Could not connect:".mysql_error());//如果连接失败则结束
mysql_select_db("CreateData",$con);//选择数据库
mysql_query("set names utf8");//设置utf8,否则中文会乱码噢
@stilllisisi
stilllisisi / ImageSequenceAnimation.shader
Created March 11, 2020 10:48
【游戏-shader】Shader序列帧动画效果。序列帧动画属于纹理动画的其中之一,主要的实现原理是设置显示UV纹理的大小,并逐帧修改图片的UV坐标
Shader "Image Sequence Animation" {
Properties {
_Color ("Color Tint", Color) = (1, 1, 1, 1)
_MainTex ("Image Sequence", 2D) = "white" {}
_HorizontalAmount ("Horizontal Amount", Float) = 4
_VerticalAmount ("Vertical Amount", Float) = 4
_Speed ("Speed", Range(1, 100)) = 30
}
SubShader {
// 设置成透明是希望画面特效能在其他物体都绘制完之后再显示
@stilllisisi
stilllisisi / LightWave.shader
Created March 11, 2020 09:36
【游戏-Shader】Shader灯光遮罩(水纹,散焦等)效果实现
//原理
//1. 利用灯光投射范围
//2. 利用法线RG偏移贴图
Shader "QQ/LightWave"
{
Properties
{
_Color("Color",Color) = (0,0,0,1)
_MainTex("Texture", 2D) = "white" {}
_WaveTex("Wave",2D) = "white" {}
@stilllisisi
stilllisisi / WaterConfig.cs
Last active March 11, 2020 09:39
【游戏-unity】Unity Shader移动端海面实现
//摄像机脚本
using UnityEngine;
[RequireComponent(typeof(Camera))]
public class WaterConfig : MonoBehaviour
{
private Camera cam;
[ContextMenu("Depth")]
void Start()
{
if (!cam)
@stilllisisi
stilllisisi / LightTrail.shader
Last active March 13, 2020 10:03
【游戏-Shader】Shader实现体积光影。shader实现阴影基础上,实现体积光影的方法
//思路:
//1.为了投影出体积阴影,我们多用一个pass来渲染网格。
//2.网格延伸的方向是灯光的方向。
//3.我们将顶点转换到模型空间,然后计算和灯光的角度进行顶点的偏移。
//4.因为根据顶点偏移,所以不能对断开的顶点进行平滑的过度。
//5.通过点乘插值我们来决定颜色的插值。
//6.该shader不仅可以用来做体积投影,也可以在灯光下做体积光。
//源代码:
Shader"QQ/LightTrail"
@stilllisisi
stilllisisi / InteractiveGridMesh.cs
Last active March 11, 2020 09:17
【游戏-网格】Mesh绘制交互网格
//思路
//1.绘制网格(使用Mesh网格生成圆柱网格https://gist.github.com/stilllisisi/fdd2c9b0035b6180c95573193038806a)
//2.使用B曲线平滑连接和排序网格
//3.销毁网格
//4.彩虹滚动使用shader实现
//实现
//1. 连接的网格
//先生成了一系列小网格搭配BOX碰撞,为了让我们后期能对他进行裁剪和逐步消失功能。
//因为我们知道网格每个顶点的序号,所以只需要根据鼠标方向生成下个网格,旧网格的结束顶点的坐标改成新网格起始顶点的坐标,就可以实现网格连接。
@stilllisisi
stilllisisi / CylinderDemo.cs
Last active March 11, 2020 09:18
【游戏-网格】使用Mesh网格生成圆柱网格。Mesh不止可以用于绘制图形,还可以用来生成圆柱
//一个顶点,可以分配一个UV信息,也就是说如果生成一个6边的圆柱,你需要7个边的顶点,第一边和最后一边重合,来生成0-1之间的UV值,包括法线,切线,颜色等,如果你需要一个顶点有3个法线面向,那就需要在这个位置生成3个顶点。
//源代码:
public Mesh CreateMesh(int edg_x, int edg_y, float rad, float len)
{
edg_x = Mathf.Max(2, edg_x);//保证最低2个边
edg_y = Mathf.Max(2, edg_y);
int _deglen = edg_x * edg_y + edg_y;
normals = new Vector3[_deglen];
verts = new Vector3[_deglen];