layout: post
title: “中级Shader教程05 2D雪花”
date: 2018-03-27 16:09:03
author: Jiepeng Tan
categories:
- shader tutorial
tags: shader_tutorial snow grid shader
img_path: /assets/img/blog/ShaderTutorial2D/Snow
mathjax: true
Shader 视频教程
本篇主要技术点有:
- grid 空间划分
- 2D模拟3D中"分层"的概念
- 透视模拟
1.原理:
在前面中介绍了2D模拟3D中的一些小技巧,这里用到了透视以及空间划分的概念,这里将不再重复:
2.分析:
ps:后面()中的数字表示前面透视中的特点
根据 中级Shader教程02 基本图形2D中介绍了相应的一些概念
将上述知识具体到观察下雪这各场景中:
- 雪花前面的大点(1)
- 雪花前面的少点(2)
- 雪花前面的亮点(3)
其他的特点有:
- 整体是向下降落,因为透视关系后面的下降速度慢点(2)
- 现实中的雪花的薄厚程度不一
- 雪花的空间分布比较随机
- 雪花的下落过程的可能会左右移动
3.代码实现:
1.空间划分
uv *=10;//将uv放大后frac
uv = frac(uv);
uv-=0.5;
2.添加随机值
fixed2 Rand22(fixed2 co){
fixed x = frac(sin(dot(co.xy ,fixed2(122.9898,783.233))) * 43758.5453)