0.8.19/20: Fantastic Global Update II

This commit is contained in:
MrZ_26
2020-05-21 01:12:17 +08:00
parent 2768fa748b
commit 28d5136e95
59 changed files with 3092 additions and 2144 deletions

View File

@@ -1,30 +1,29 @@
#define PI 3.14
extern float xresolution;
//从1D距离map采样
//sample from 1D vis-depth map
float samp(vec2 coord,float r,Image u_texture){
return step(r,Texel(u_texture,coord).r);
}
vec4 effect(vec4 color,Image texture,vec2 texture_coords,vec2 screen_coords){
//直角转极坐标用于采样1D材质的y总是0
//cartesian to polar, y of 1D sample is always 0
vec2 norm=texture_coords.st*2.-1.;
float r=length(norm);
vec2 tc=vec2((atan(norm.y,norm.x)+PI)/(2.*PI),0.);
//根据离光源距离放大模糊系数,模拟影子淡出
float blur=(1./xresolution)*smoothstep(0.,1.,r);
//简易高斯模糊
float sum=
samp(vec2(tc.x-4.*blur,tc.y),r,texture)*.5
+samp(vec2(tc.x-3.*blur,tc.y),r,texture)*.9
+samp(vec2(tc.x-2.*blur,tc.y),r,texture)*.12
+samp(vec2(tc.x-1.*blur,tc.y),r,texture)*.15
//enlarge blur parameter by distance, light scattering simulation
float blur=(1./xresolution)*smoothstep(.3,1.,r);
+samp(tc,r,texture)*.16//The center tex coord,which gives us hard shadows.
+samp(vec2(tc.x+1.*blur,tc.y),r,texture)*.15
+samp(vec2(tc.x+2.*blur,tc.y),r,texture)*.12
+samp(vec2(tc.x+3.*blur,tc.y),r,texture)*.9
+samp(vec2(tc.x+4.*blur,tc.y),r,texture)*.5;
//sum值为亮度(0~1)
//乘上距离得到逐渐变淡的光线
return vec4(vec3(1.),sum*smoothstep(1.,.1,r));
//Simple Gaussian blur
float sum=//brightness(0~1)
samp(vec2(tc.x-3.*blur,tc.y),r,texture)*.1
+samp(vec2(tc.x-2.*blur,tc.y),r,texture)*.13
+samp(vec2(tc.x-1.*blur,tc.y),r,texture)*.17
+samp(tc,r,texture)*.2//The center tex coord,which gives us hard shadows.
+samp(vec2(tc.x+1.*blur,tc.y),r,texture)*.17
+samp(vec2(tc.x+2.*blur,tc.y),r,texture)*.13
+samp(vec2(tc.x+3.*blur,tc.y),r,texture)*.1;
//Multiply the distance to get a soft fading
return vec4(vec3(1.),sum*smoothstep(1.,0.,r));
}