整理代码
This commit is contained in:
@@ -22,7 +22,7 @@ local function destroy(L)
|
|||||||
end
|
end
|
||||||
local function draw(L)
|
local function draw(L)
|
||||||
--Initialization
|
--Initialization
|
||||||
local r,g,b,a=love.graphics.getColor()
|
local r,g,b,a=gc.getColor()
|
||||||
setCanvas(L.blackCanvas)clear()
|
setCanvas(L.blackCanvas)clear()
|
||||||
setCanvas(L.shadowCanvas)clear()
|
setCanvas(L.shadowCanvas)clear()
|
||||||
setCanvas(L.renderCanvas)clear()
|
setCanvas(L.renderCanvas)clear()
|
||||||
@@ -62,7 +62,7 @@ end
|
|||||||
local LIGHT={}
|
local LIGHT={}
|
||||||
function LIGHT.draw()
|
function LIGHT.draw()
|
||||||
for i=1,#Lights do
|
for i=1,#Lights do
|
||||||
Lights[i]:draw()
|
draw(Lights[i])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function LIGHT.clear()
|
function LIGHT.clear()
|
||||||
@@ -71,19 +71,18 @@ function LIGHT.clear()
|
|||||||
Lights[i]=nil
|
Lights[i]=nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function LIGHT.add(x,y,R,F)
|
function LIGHT.add(x,y,radius,solidFunc)
|
||||||
local id=#Lights+1
|
local id=#Lights+1
|
||||||
Lights[id]={
|
Lights[id]={
|
||||||
id=id,
|
id=id,
|
||||||
x=x,y=y,size=R,
|
x=x,y=y,size=radius,
|
||||||
blackCanvas=gc.newCanvas(R,R),--Solid canvas
|
blackCanvas=gc.newCanvas(radius,radius),--Solid canvas
|
||||||
shadowCanvas=gc.newCanvas(R,1),--1D vis-depth canvas
|
shadowCanvas=gc.newCanvas(radius,1),--1D vis-depth canvas
|
||||||
renderCanvas=gc.newCanvas(R,R),--Light canvas
|
renderCanvas=gc.newCanvas(radius,radius),--Light canvas
|
||||||
blackFn=F,--Solid draw funcion
|
blackFn=solidFunc,--Solid draw funcion
|
||||||
|
|
||||||
move=move,
|
move=move,
|
||||||
setPow=setPow,
|
setPow=setPow,
|
||||||
draw=draw,
|
|
||||||
destroy=destroy,
|
destroy=destroy,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
#define PI 3.14159
|
#define PI 3.14159
|
||||||
extern float xresolution;
|
extern float xresolution;
|
||||||
//sample from 1D vis-depth map
|
// Sample from 1D vis-depth map
|
||||||
float samp(vec2 coord,float r,Image u_texture){
|
float samp(vec2 coord,float r,Image u_texture){
|
||||||
return step(r,Texel(u_texture,coord).r);
|
return step(r,Texel(u_texture,coord).r);
|
||||||
}
|
}
|
||||||
vec4 effect(vec4 color,Image texture,vec2 texture_coords,vec2 screen_coords){
|
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 norm=texture_coords.st*2.-1.;
|
||||||
vec2 tc=vec2((atan(norm.y,norm.x)+PI)/(2.*PI),0.);
|
vec2 tc=vec2((atan(norm.y,norm.x)+PI)/(2.*PI),0.);
|
||||||
float r=length(norm);
|
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);
|
float blur=(1./xresolution)*smoothstep(0.3,1.,r);
|
||||||
|
|
||||||
// Simple Gaussian blur
|
// Simple Gaussian blur
|
||||||
float sum=//brightness(0~1)
|
float sum=// Brightness(0~1)
|
||||||
samp(vec2(tc.x-3.*blur,tc.y),r,texture)*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-2.*blur,tc.y),r,texture)*0.13
|
||||||
+samp(vec2(tc.x-1.*blur,tc.y),r,texture)*0.17
|
+samp(vec2(tc.x-1.*blur,tc.y),r,texture)*0.17
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ extern float yresolution;
|
|||||||
vec4 effect(vec4 color,Image texture,vec2 texture_coords,vec2 screen_coords){
|
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.;y<yresolution;y++){
|
for(float y=0.;y<yresolution;y++){
|
||||||
//cartesian to polar
|
// Cartesian to polar
|
||||||
// y/yresolution=distance to light source(0~1)
|
// y/yresolution=distance to light source(0~1)
|
||||||
vec2 norm=vec2(texture_coords.s,y/yresolution)*2.-1.;
|
vec2 norm=vec2(texture_coords.s,y/yresolution)*2.-1.;
|
||||||
float theta=PI*1.5+norm.x*PI;
|
float theta=PI*1.5+norm.x*PI;
|
||||||
@@ -12,10 +12,9 @@ vec4 effect(vec4 color,Image texture,vec2 texture_coords,vec2 screen_coords){
|
|||||||
//sample from solid
|
//sample from solid
|
||||||
if(
|
if(
|
||||||
Texel(texture,(
|
Texel(texture,(
|
||||||
vec2(-r*sin(theta),-r*cos(theta))*0.5+0.5//coord of solid sampling
|
vec2(-r*sin(theta),-r*cos(theta))*0.5+0.5// Coord of solid sampling
|
||||||
))
|
)).a>0.1
|
||||||
.a>0.1
|
)return vec4(vec3(y/yresolution),1.);// Collision check, alpha>0.1 means transparent
|
||||||
)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
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user