更真实的3D方块
This commit is contained in:
@@ -4,9 +4,9 @@ extern float xresolution;
|
|||||||
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 tex,vec2 tex_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=tex_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);
|
||||||
|
|
||||||
@@ -15,14 +15,14 @@ vec4 effect(vec4 color,Image texture,vec2 texture_coords,vec2 screen_coords){
|
|||||||
|
|
||||||
// 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,tex)*0.1
|
||||||
+samp(vec2(tc.x-2.*blur,tc.y),r,texture)*0.13
|
+samp(vec2(tc.x-2.*blur,tc.y),r,tex)*0.13
|
||||||
+samp(vec2(tc.x-1.*blur,tc.y),r,texture)*0.17
|
+samp(vec2(tc.x-1.*blur,tc.y),r,tex)*0.17
|
||||||
|
|
||||||
+samp(tc,r,texture)*0.2// The center tex coord, which gives us hard shadows.
|
+samp(tc,r,tex)*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+1.*blur,tc.y),r,tex)*0.17
|
||||||
+samp(vec2(tc.x+2.*blur,tc.y),r,texture)*0.13
|
+samp(vec2(tc.x+2.*blur,tc.y),r,tex)*0.13
|
||||||
+samp(vec2(tc.x+3.*blur,tc.y),r,texture)*0.1;
|
+samp(vec2(tc.x+3.*blur,tc.y),r,tex)*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));
|
return vec4(vec3(1.),sum*smoothstep(1.,0.,r));
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
#define PI 3.14
|
#define PI 3.14
|
||||||
extern float yresolution;
|
extern float yresolution;
|
||||||
vec4 effect(vec4 color,Image texture,vec2 texture_coords,vec2 screen_coords){
|
vec4 effect(vec4 color,Image tex,vec2 tex_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(tex_coords.s,y/yresolution)*2.-1.;
|
||||||
float theta=PI*1.5+norm.x*PI;
|
float theta=PI*1.5+norm.x*PI;
|
||||||
float r=(1.+norm.y)*0.5;
|
float r=(1.+norm.y)*0.5;
|
||||||
|
|
||||||
//sample from solid
|
//sample from solid
|
||||||
if(
|
if(
|
||||||
Texel(texture,(
|
Texel(tex,(
|
||||||
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
|
||||||
|
|||||||
@@ -44,62 +44,93 @@ local function boardTransform(mode)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local function drawField(P)
|
local function drawRow(h,V,L)
|
||||||
local V,F=P.visTime,P.field
|
|
||||||
local start=int((P.fieldBeneath+P.fieldUp)/30+1)
|
|
||||||
local edge=P.gameEnv.upEdge
|
|
||||||
local rep=GAME.replaying
|
|
||||||
local texture=SKIN.curText
|
local texture=SKIN.curText
|
||||||
if P.falling==-1 then--Blocks only
|
local t=TIME()*4
|
||||||
local t=TIME()*4
|
for i=1,10 do
|
||||||
for j=start,min(start+21,#F)do
|
if L[i]>0 then
|
||||||
for i=1,10 do
|
if V[i]>0 then
|
||||||
if F[j][i]>0 then
|
local a=V[i]*.05
|
||||||
if V[j][i]>0 then
|
gc_setColor(1,1,1,a)
|
||||||
gc_setColor(1,1,1,V[j][i]*.05)
|
gc_draw(texture[L[i]],30*i-30,-30*h)-- drawCell(j,i,L[i])
|
||||||
gc_draw(texture[F[j][i]],30*i-30,-30*j)-- drawCell(j,i,F[j][i])
|
elseif GAME.replaying then
|
||||||
if edge and(not F[j+1]or F[j+1][i]<=0)then
|
gc_setColor(1,1,1,.3+.08*sin(.5*(h-i)+t))
|
||||||
local r,g,b=unpack(SKIN.libColor[F[j][i]])
|
gc_rectangle("fill",30*i-30,-30*h,30,30)
|
||||||
gc_setColor((r+2)/3,(g+2)/3,(b+2)/3,V[j][i]*.05)
|
|
||||||
gc_rectangle("fill",30*i-30,-30*j,30,-4)
|
|
||||||
end
|
|
||||||
elseif rep then
|
|
||||||
gc_setColor(1,1,1,.3+.08*sin(.5*(j-i)+t))
|
|
||||||
gc_rectangle("fill",30*i-30,-30*j,30,30)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local function drawField(P)
|
||||||
|
local ENV=P.gameEnv
|
||||||
|
local V,F=P.visTime,P.field
|
||||||
|
local start=int((P.fieldBeneath+P.fieldUp)/30+1)
|
||||||
|
|
||||||
|
--Sorry, I think using FLAG & GOTO is the easiest way to make this simple.
|
||||||
|
--I just want reuse the for-block without using function, because this
|
||||||
|
--is called EXTREME FREQUENTLY, and PASSING VARIABLES IS TOO COMPLEX.
|
||||||
|
--[[
|
||||||
|
Normal style:
|
||||||
|
if ENV.upEdge then
|
||||||
|
{set shader and coords};
|
||||||
|
<< draw field block >> (FOR-block)
|
||||||
|
{restore shader and coords};
|
||||||
|
end
|
||||||
|
<< draw field block >> (FOR-block)
|
||||||
|
|
||||||
|
Simplified by me:
|
||||||
|
flag=ENV.upEdge
|
||||||
|
if flag then
|
||||||
|
{set shader and coords};
|
||||||
|
end
|
||||||
|
::label::
|
||||||
|
<< draw field block >> (FOR-block)
|
||||||
|
if flag then
|
||||||
|
{restore shader and coords};
|
||||||
|
flag=false
|
||||||
|
goto label
|
||||||
|
end
|
||||||
|
]]
|
||||||
|
local flag=ENV.upEdge
|
||||||
|
if P.falling==-1 then--Blocks only
|
||||||
|
if flag then
|
||||||
|
gc.setShader(SHADER.lighter)
|
||||||
|
gc.translate(0,-4)
|
||||||
|
end
|
||||||
|
::edgeFinished::
|
||||||
|
for j=start,min(start+21,#F)do drawRow(j,V[j],F[j])end
|
||||||
|
if flag then
|
||||||
|
gc.setShader()
|
||||||
|
gc.translate(0,4)
|
||||||
|
flag=false
|
||||||
|
goto edgeFinished
|
||||||
|
end
|
||||||
else--With falling animation
|
else--With falling animation
|
||||||
local ENV=P.gameEnv
|
|
||||||
local stepY=ENV.smooth and(P.falling/(ENV.fall+1))^2.5*30 or 30
|
local stepY=ENV.smooth and(P.falling/(ENV.fall+1))^2.5*30 or 30
|
||||||
local A=P.falling/ENV.fall
|
local A=P.falling/ENV.fall
|
||||||
local h=1
|
local h=1
|
||||||
gc_push("transform")
|
gc_push("transform")
|
||||||
for j=start,min(start+21,#F)do
|
if flag then
|
||||||
while j==P.clearingRow[h]do
|
gc_push("transform")
|
||||||
h=h+1
|
gc.setShader(SHADER.lighter)
|
||||||
gc_translate(0,-stepY)
|
gc.translate(0,-4)
|
||||||
gc_setColor(1,1,1,A)
|
end
|
||||||
gc_rectangle("fill",0,30-30*j,300,stepY)
|
::edgeFinished::
|
||||||
end
|
for j=start,min(start+21,#F)do
|
||||||
for i=1,10 do
|
while j==P.clearingRow[h]do
|
||||||
if F[j][i]>0 then
|
h=h+1
|
||||||
if V[j][i]>0 then
|
gc_translate(0,-stepY)
|
||||||
gc_setColor(1,1,1,V[j][i]*.05)
|
gc_setColor(1,1,1,A)
|
||||||
gc_draw(texture[F[j][i]],30*i-30,-30*j)-- drawCell(j,i,F[j][i])
|
gc_rectangle("fill",0,30-30*j,300,stepY)
|
||||||
if edge and(not F[j+1]or F[j+1][i]<=0)then
|
|
||||||
local r,g,b=unpack(SKIN.libColor[F[j][i]])
|
|
||||||
gc_setColor((r+2)/3,(g+2)/3,(b+2)/3,V[j][i]*.05)
|
|
||||||
gc_rectangle("fill",30*i-30,-30*j,30,-4)
|
|
||||||
end
|
|
||||||
elseif rep then
|
|
||||||
gc_setColor(1,1,1,.2)
|
|
||||||
gc_rectangle("fill",30*i-30,-30*j,30,30)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
drawRow(j,V[j],F[j])
|
||||||
|
end
|
||||||
|
if flag then
|
||||||
|
gc_pop()
|
||||||
|
gc.setShader()
|
||||||
|
flag=false
|
||||||
|
h=1
|
||||||
|
goto edgeFinished
|
||||||
|
end
|
||||||
gc_pop()
|
gc_pop()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
extern float a;
|
extern float a;
|
||||||
vec4 effect(vec4 color,Image text,vec2 pos,vec2 scr_pos){
|
vec4 effect(vec4 color,Image tex,vec2 tex_coords,vec2 scr_coords){
|
||||||
return vec4(1.,1.,1.,sign(Texel(text,pos).a)*a);
|
return vec4(1.,1.,1.,sign(Texel(tex,tex_coords).a)*a);
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
#define PI 3.1415926535897932384626
|
#define PI 3.1415926535897932384626
|
||||||
extern float w,h;
|
extern float w,h;
|
||||||
extern float t;
|
extern float t;
|
||||||
vec4 effect(vec4 color,Image text,vec2 pos,vec2 scr_pos){
|
vec4 effect(vec4 color,Image tex,vec2 tex_coords,vec2 scr_coords){
|
||||||
float x=scr_pos.x/w;
|
float x=scr_coords.x/w;
|
||||||
float y=scr_pos.y/h;
|
float y=scr_coords.y/h;
|
||||||
float dx,dy;
|
float dx,dy;
|
||||||
vec3 V=vec3(0.);
|
vec3 V=vec3(0.);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
extern float t,w;
|
extern float t,w;
|
||||||
vec4 effect(vec4 color,Image text,vec2 pos,vec2 scr_pos){
|
vec4 effect(vec4 color,Image tex,vec2 tex_coords,vec2 scr_coords){
|
||||||
float x=scr_pos.x/w;
|
float x=scr_coords.x/w;
|
||||||
return vec4(
|
return vec4(
|
||||||
.8-x*.6,
|
.8-x*.6,
|
||||||
.3+.2*sin(t),
|
.3+.2*sin(t),
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
extern float t,h;
|
extern float t,h;
|
||||||
vec4 effect(vec4 color,Image text,vec2 pos,vec2 scr_pos){
|
vec4 effect(vec4 color,Image tex,vec2 tex_coords,vec2 scr_coords){
|
||||||
float y=scr_pos.y/h;
|
float y=scr_coords.y/h;
|
||||||
return vec4(
|
return vec4(
|
||||||
.8-y*.6,
|
.8-y*.6,
|
||||||
.2+y*.4,
|
.2+y*.4,
|
||||||
|
|||||||
9
parts/shaders/lighter.glsl
Normal file
9
parts/shaders/lighter.glsl
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
vec4 effect(vec4 color,Image tex,vec2 tex_coords,vec2 scr_coords){
|
||||||
|
vec4 texcolor=Texel(tex,tex_coords);
|
||||||
|
return vec4(
|
||||||
|
pow(texcolor.r+.26,.7023),
|
||||||
|
pow(texcolor.g+.26,.7023),
|
||||||
|
pow(texcolor.b+.26,.7023),
|
||||||
|
texcolor.a
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
extern float t,w,h;
|
extern float t,w,h;
|
||||||
vec4 effect(vec4 color,Image text,vec2 pos,vec2 scr_pos){
|
vec4 effect(vec4 color,Image tex,vec2 tex_coords,vec2 scr_coords){
|
||||||
float x=scr_pos.x/w;
|
float x=scr_coords.x/w;
|
||||||
float y=scr_pos.y/h;
|
float y=scr_coords.y/h;
|
||||||
return vec4(
|
return vec4(
|
||||||
.8-y*.7+.2*sin(t/6.26),
|
.8-y*.7+.2*sin(t/6.26),
|
||||||
.2+y*.5+.15*sin(t/4.),
|
.2+y*.5+.15*sin(t/4.),
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
extern float t,w,h;
|
extern float t,w,h;
|
||||||
vec4 effect(vec4 color,Image text,vec2 pos,vec2 scr_pos){
|
vec4 effect(vec4 color,Image tex,vec2 tex_coords,vec2 scr_coords){
|
||||||
float x=scr_pos.x/w;
|
float x=scr_coords.x/w;
|
||||||
float y=scr_pos.y/h;
|
float y=scr_coords.y/h;
|
||||||
return vec4(
|
return vec4(
|
||||||
.8-y*.8-.1*sin(t/6.26),
|
.8-y*.8-.1*sin(t/6.26),
|
||||||
.4+.1*sin(t/4.)*(y+2.)/(y+5.),
|
.4+.1*sin(t/4.)*(y+2.)/(y+5.),
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
extern float w,h;
|
extern float w,h;
|
||||||
extern float level;
|
extern float level;
|
||||||
vec4 effect(vec4 color,Image text,vec2 pos,vec2 scr_pos){
|
vec4 effect(vec4 color,Image tex,vec2 tex_coords,vec2 scr_coords){
|
||||||
float dx=abs(scr_pos.x/w-0.5);
|
float dx=abs(scr_coords.x/w-0.5);
|
||||||
float dy=abs(scr_pos.y/h-0.5);
|
float dy=abs(scr_coords.y/h-0.5);
|
||||||
float a=(max(dx*2.6,dy*1.8)-.626)*level;
|
float a=(max(dx*2.6,dy*1.8)-.626)*level;
|
||||||
return vec4(1.,0.,0.,a);
|
return vec4(1.,0.,0.,a);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user