diff --git a/Zframework/light/init.lua b/Zframework/light/init.lua index b8aabee3..0e613e91 100644 --- a/Zframework/light/init.lua +++ b/Zframework/light/init.lua @@ -22,7 +22,7 @@ local function destroy(L) end local function draw(L) --Initialization - local r,g,b,a=love.graphics.getColor() + local r,g,b,a=gc.getColor() setCanvas(L.blackCanvas)clear() setCanvas(L.shadowCanvas)clear() setCanvas(L.renderCanvas)clear() @@ -62,7 +62,7 @@ end local LIGHT={} function LIGHT.draw() for i=1,#Lights do - Lights[i]:draw() + draw(Lights[i]) end end function LIGHT.clear() @@ -71,19 +71,18 @@ function LIGHT.clear() Lights[i]=nil end end -function LIGHT.add(x,y,R,F) +function LIGHT.add(x,y,radius,solidFunc) local id=#Lights+1 Lights[id]={ id=id, - x=x,y=y,size=R, - blackCanvas=gc.newCanvas(R,R),--Solid canvas - shadowCanvas=gc.newCanvas(R,1),--1D vis-depth canvas - renderCanvas=gc.newCanvas(R,R),--Light canvas - blackFn=F,--Solid draw funcion + x=x,y=y,size=radius, + blackCanvas=gc.newCanvas(radius,radius),--Solid canvas + shadowCanvas=gc.newCanvas(radius,1),--1D vis-depth canvas + renderCanvas=gc.newCanvas(radius,radius),--Light canvas + blackFn=solidFunc,--Solid draw funcion move=move, setPow=setPow, - draw=draw, destroy=destroy, } end diff --git a/Zframework/light/lightRender.glsl b/Zframework/light/lightRender.glsl index 5eddc563..b63b9a70 100644 --- a/Zframework/light/lightRender.glsl +++ b/Zframework/light/lightRender.glsl @@ -1,29 +1,29 @@ #define PI 3.14159 extern float xresolution; -//sample from 1D vis-depth 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){ - //cartesian to polar, y of 1D sample is always 0 + // Cartesian to polar, y of 1D sample is always 0 vec2 norm=texture_coords.st*2.-1.; vec2 tc=vec2((atan(norm.y,norm.x)+PI)/(2.*PI),0.); float r=length(norm); - //enlarge blur parameter by distance, light scattering simulation + // Enlarge blur parameter by distance, light scattering simulation float blur=(1./xresolution)*smoothstep(0.3,1.,r); - //Simple Gaussian blur - float sum=//brightness(0~1) + // Simple Gaussian blur + float sum=// Brightness(0~1) samp(vec2(tc.x-3.*blur,tc.y),r,texture)*0.1 +samp(vec2(tc.x-2.*blur,tc.y),r,texture)*0.13 +samp(vec2(tc.x-1.*blur,tc.y),r,texture)*0.17 - +samp(tc,r,texture)*0.2//The center tex coord,which gives us hard shadows. + +samp(tc,r,texture)*0.2// The center tex coord, which gives us hard shadows. +samp(vec2(tc.x+1.*blur,tc.y),r,texture)*0.17 +samp(vec2(tc.x+2.*blur,tc.y),r,texture)*0.13 +samp(vec2(tc.x+3.*blur,tc.y),r,texture)*0.1; - //Multiply the distance to get a soft fading + // Multiply the distance to get a soft fading return vec4(vec3(1.),sum*smoothstep(1.,0.,r)); } \ No newline at end of file diff --git a/Zframework/light/shadowMap.glsl b/Zframework/light/shadowMap.glsl index 8150a6d3..527b89ba 100644 --- a/Zframework/light/shadowMap.glsl +++ b/Zframework/light/shadowMap.glsl @@ -1,9 +1,9 @@ #define PI 3.14 extern float yresolution; vec4 effect(vec4 color,Image texture,vec2 texture_coords,vec2 screen_coords){ - //Iterate through the occluder map's y-axis. + // Iterate through the occluder map's y-axis. for(float y=0.;y0.1 - )return vec4(vec3(y/yresolution),1.);//collision check, alpha>0.1 means transparent + vec2(-r*sin(theta),-r*cos(theta))*0.5+0.5// Coord of solid sampling + )).a>0.1 + )return vec4(vec3(y/yresolution),1.);// Collision check, alpha>0.1 means transparent } - return vec4(1.,1.,1.,1.);//return max distance 1 + return vec4(1.);// Return max distance 1 } \ No newline at end of file