0.8.19/20: Fantastic Global Update II
This commit is contained in:
@@ -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));
|
||||
}
|
||||
@@ -3,14 +3,19 @@ extern float yresolution;
|
||||
vec4 effect(vec4 color,Image texture,vec2 texture_coords,vec2 screen_coords){
|
||||
//Iterate through the occluder map's y-axis.
|
||||
for(float y=0.;y<yresolution;y++){
|
||||
//直角转极坐标
|
||||
//cartesian to polar
|
||||
// y/yresolution=distance to light source(0~1)
|
||||
vec2 norm=vec2(texture_coords.s,y/yresolution)*2.-1.;
|
||||
float theta=PI*1.5+norm.x*PI;
|
||||
float r=(1.+norm.y)*.5;
|
||||
//y/yresolution为到光源的距离(0~1)
|
||||
//遮光物采样
|
||||
vec4 data=Texel(texture,(vec2(-r*sin(theta),-r*cos(theta))*.5+.5));//vec2()..是遮光物采样的coord
|
||||
if(data.a>.1)return vec4(vec3(y/yresolution),1.);//碰撞检测,像素透明度>.1即透光
|
||||
|
||||
//sample from solid
|
||||
if(
|
||||
Texel(texture,(
|
||||
vec2(-r*sin(theta),-r*cos(theta))*.5+.5//coord of solid sampling
|
||||
))
|
||||
.a>.1
|
||||
)return vec4(vec3(y/yresolution),1.);//collision check, alpha>0.1 means transparent
|
||||
}
|
||||
return vec4(1,1,1,1);//返回最远距离1
|
||||
return vec4(1.,1.,1.,1.);//return max distance 1
|
||||
}
|
||||
Reference in New Issue
Block a user