#ifndef RAYMARCHING_INCLUDED
#define RAYMARCHING_INCLUDED
#define MIXSTEP 2
#define ONESTEPDISTANCE 4
#include"CalCulateNoise.cginc"
sampler2D _noiseTex;
float _rainSpeed;
float _chaosRate;
int _rainNumber;
float _density;
//founction
float2 Unity_Rotate_Radians_float(float2 UV, float2 Center, float Rotation)
{
UV -= Center;
float s = sin(Rotation);
float c = cos(Rotation);
float2x2 rMatrix = float2x2(c, -s, s, c);
rMatrix *= 0.5;
rMatrix += 0.5;
rMatrix = rMatrix * 2 - 1;
UV.xy = mul(UV.xy, rMatrix);
UV += Center;
float2 Out=float2(0,0);
return Out;
}
float angleBetween(float3 vector1, float3 vector2) {
return acos(dot(vector1, vector2)/(length(vector1)*length(vector2)));
}
float GetNoiseTexValue(float2 uv,float rainSpeed,float chaosRate ,int rainNumber ){
uv*=pow(1.5,rainNumber);
uv.y*=rainSpeed;
uv.y+=_Time.y*40;
//float2 uv_R=Unity_Rotate_Radians_float(uv,float2(0.5,0.5),chaosRate*15*sin(_Time.y/15 + rainNumber*2));
return smoothstep(0.65,0.85,FBMR(uv,3));
}
fixed4 rayMarching(float3 ro ,float3 rd,fixed3 sceneCol,float rz ,float2 uv){
float3 rayPos=ro+rd*MIXSTEP;
float rainAlpha=0;
for(int ix=0;ix<_rainNumber;ix++){
if(length(rayPos-ro)>=rz){
break;
}
float alpha=1.0;
if(2>=rz-length(rayPos-ro)){
alpha = smoothstep(0,2,rz-length(rayPos-ro));
}
float2 UV=float2(angleBetween(float3(0,0,1),float3(rd.x,0,rd.z))*_density, rayPos.y/300);
rainAlpha+=GetNoiseTexValue(UV,_rainSpeed,_chaosRate,ix+1)*alpha;
rayPos+=rd*ONESTEPDISTANCE;
}
float3 lightCol=float3(0.2,0.2,0.2);
fixed3 finalCol=sceneCol+rainAlpha*lightCol;
return fixed4(finalCol,1.0);
//return fixed4(rainAlpha,rainAlpha,rainAlpha,1.0);
}
#endif
2019-06-09
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- chinadaily.com.cn 2019-06-04 16:16 8:45 – 9: 43, 58 min L...