float rand(float n){return fract(sin(n) * 43758.5453123);}
float noise(float p){
float fl = floor(p);
float fc = fract(p);
return mix(rand(fl), rand(fl + 1.0), fc);
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //我们使用的噪声其实是这个噪声:https://www.shadertoy.com/view/4sfGzS | |
| //这是Iq大神弄的一个噪声,效率和表现都算很好。 | |
| float noise(in float3 x) | |
| { | |
| float3 p = floor(x); | |
| float3 f = frac(x); | |
| f = f * f*(3.0 - 2.0*f); | |
| float2 uv2 = (p.xy + float2(37.0, 17.0)*p.z) + f.xy; | |
| float2 rg = tex2Dlod(_NoiseTex, float4((uv2 + 0.5) / 256.0, 0, 0)).yx; | |
| return lerp(rg.x, rg.y, f.z); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //首先还是从雪粒子开始,雪粒子无法像雨一样根据深度来直接判断阻挡,因为雨是垂直下落的,但雪不是,雪是会有各种方向的,所以这里需要做实实在在的碰撞来处理遮挡。 | |
| private void OnTriggerEnter(Collider other) | |
| { | |
| SnowManager.inst.reclaim(this); | |
| } | |
| //就是用了一个触发器,就可以看到雪被挡住了。因为自带的物理引擎性能也很好,这样做还可以接受。 | |
| //然后要开始处理积雪。第一步还是要实现一个雪的材质,起码要看上去像雪。 | |
| //基本原理就是雪是白色的,然后加上一个法线,模拟雪表面的纹理。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //首先用最简单的方式,用程序生成了一个大网格。 | |
| //考虑到自然风,打算模仿一个dx 草下面的一个算法: | |
| //用位置信息作为随机种子 | |
| #ifdef GRASS_OBJECT_MODE | |
| float3 randCalcPos = p[0].objectSpacePos; | |
| #else | |
| float3 randCalcPos = oPos; | |
| #endif | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //我们需要设计一种tile方式的雨来处理摄像机看到雨的范围。水平方向上可以调整tile个数,垂直方向我可以根据控制雨下落的生命周期来控制。 | |
| //我们要计算出摄像机能看到的AABB盒,从而去做需要雨落下的物体的范围。 | |
| Vector3[] GetCorners(float distance) | |
| { | |
| Vector3[] corners = new Vector3[4]; | |
| float halfFOV = (Camera.main.fieldOfView * 0.5f) * Mathf.Deg2Rad; | |
| float aspect = Camera.main.aspect; | |
| float height = distance * Mathf.Tan(halfFOV); | |
| float width = height * aspect; | |
| Transform tx = Camera.main.transform; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'dart:math' as math; | |
| import 'package:flutter/material.dart'; | |
| import 'package:flutter/rendering.dart'; | |
| import 'package:flutter/scheduler.dart'; | |
| void main() => runApp(ExampleApp()); | |
| class ExampleApp extends StatelessWidget { | |
| @override |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Basic Sprite Shader for aligning pixel art to the same grid, based on the Unity Sprite Shader. | |
| Create one Material where you assign the same Pixels Per Unit value you use on your imported Sprites, | |
| then reuse this Material on all appropriate Sprite Renderers. | |
| (You can use Shader.SetGlobalFloat to set that Pixels Per Unit value for all your shaders: | |
| https://docs.unity3d.com/ScriptReference/Shader.SetGlobalFloat.html) | |
| This is not for scaled or rotated artwork. If you need those features, look at low res render textures. | |
| Use this however you want. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Shader created with Shader Forge v1.38 | |
| // Shader Forge (c) Neat Corporation / Joachim Holmer - http://www.acegikmo.com/shaderforge/ | |
| // Note: Manually altering this data may prevent you from opening it in Shader Forge | |
| /*SF_DATA;ver:1.38;sub:START;pass:START;ps:flbk:,iptp:0,cusa:False,bamd:0,cgin:,lico:1,lgpr:1,limd:1,spmd:1,trmd:0,grmd:0,uamb:True,mssp:True,bkdf:False,hqlp:False,rprd:False,enco:False,rmgx:True,imps:True,rpth:0,vtps:0,hqsc:True,nrmq:1,nrsp:0,vomd:0,spxs:False,tesm:0,olmd:1,culm:0,bsrc:0,bdst:1,dpts:2,wrdp:True,dith:0,atcv:False,rfrpo:True,rfrpn:Refraction,coma:15,ufog:True,aust:True,igpj:False,qofs:0,qpre:2,rntp:3,fgom:False,fgoc:False,fgod:False,fgor:False,fgmd:0,fgcr:1,fgcg:1,fgcb:1,fgca:1,fgde:0.01,fgrn:5,fgrf:15,stcl:False,atwp:False,stva:128,stmr:255,stmw:255,stcp:6,stps:0,stfa:0,stfz:0,ofsf:0,ofsu:0,f2p0:False,fnsp:False,fnfb:False,fsmp:False;n:type:ShaderForge.SFN_Final,id:4904,x:33076,y:32617,varname:node_4904,prsc:2|diff-5996-OUT,clip-8651-A;n:type:ShaderForge.SFN_Color,id:848,x:32 |