更真实的3D方块
This commit is contained in:
@@ -4,9 +4,9 @@ extern float xresolution;
|
||||
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){
|
||||
vec4 effect(vec4 color,Image tex,vec2 tex_coords,vec2 screen_coords){
|
||||
// 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.);
|
||||
float r=length(norm);
|
||||
|
||||
@@ -15,14 +15,14 @@ vec4 effect(vec4 color,Image texture,vec2 texture_coords,vec2 screen_coords){
|
||||
|
||||
// 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(vec2(tc.x-3.*blur,tc.y),r,tex)*0.1
|
||||
+samp(vec2(tc.x-2.*blur,tc.y),r,tex)*0.13
|
||||
+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(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;
|
||||
+samp(tc,r,tex)*0.2// The center tex coord, which gives us hard shadows.
|
||||
+samp(vec2(tc.x+1.*blur,tc.y),r,tex)*0.17
|
||||
+samp(vec2(tc.x+2.*blur,tc.y),r,tex)*0.13
|
||||
+samp(vec2(tc.x+3.*blur,tc.y),r,tex)*0.1;
|
||||
|
||||
// Multiply the distance to get a soft fading
|
||||
return vec4(vec3(1.),sum*smoothstep(1.,0.,r));
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
#define PI 3.14
|
||||
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.
|
||||
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.;
|
||||
vec2 norm=vec2(tex_coords.s,y/yresolution)*2.-1.;
|
||||
float theta=PI*1.5+norm.x*PI;
|
||||
float r=(1.+norm.y)*0.5;
|
||||
|
||||
//sample from solid
|
||||
if(
|
||||
Texel(texture,(
|
||||
Texel(tex,(
|
||||
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
|
||||
|
||||
@@ -44,62 +44,93 @@ local function boardTransform(mode)
|
||||
end
|
||||
end
|
||||
end
|
||||
local function drawField(P)
|
||||
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 function drawRow(h,V,L)
|
||||
local texture=SKIN.curText
|
||||
if P.falling==-1 then--Blocks only
|
||||
local t=TIME()*4
|
||||
for j=start,min(start+21,#F)do
|
||||
for i=1,10 do
|
||||
if F[j][i]>0 then
|
||||
if V[j][i]>0 then
|
||||
gc_setColor(1,1,1,V[j][i]*.05)
|
||||
gc_draw(texture[F[j][i]],30*i-30,-30*j)-- drawCell(j,i,F[j][i])
|
||||
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,.3+.08*sin(.5*(j-i)+t))
|
||||
gc_rectangle("fill",30*i-30,-30*j,30,30)
|
||||
end
|
||||
end
|
||||
local t=TIME()*4
|
||||
for i=1,10 do
|
||||
if L[i]>0 then
|
||||
if V[i]>0 then
|
||||
local a=V[i]*.05
|
||||
gc_setColor(1,1,1,a)
|
||||
gc_draw(texture[L[i]],30*i-30,-30*h)-- drawCell(j,i,L[i])
|
||||
elseif GAME.replaying then
|
||||
gc_setColor(1,1,1,.3+.08*sin(.5*(h-i)+t))
|
||||
gc_rectangle("fill",30*i-30,-30*h,30,30)
|
||||
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
|
||||
local ENV=P.gameEnv
|
||||
local stepY=ENV.smooth and(P.falling/(ENV.fall+1))^2.5*30 or 30
|
||||
local A=P.falling/ENV.fall
|
||||
local h=1
|
||||
gc_push("transform")
|
||||
for j=start,min(start+21,#F)do
|
||||
while j==P.clearingRow[h]do
|
||||
h=h+1
|
||||
gc_translate(0,-stepY)
|
||||
gc_setColor(1,1,1,A)
|
||||
gc_rectangle("fill",0,30-30*j,300,stepY)
|
||||
end
|
||||
for i=1,10 do
|
||||
if F[j][i]>0 then
|
||||
if V[j][i]>0 then
|
||||
gc_setColor(1,1,1,V[j][i]*.05)
|
||||
gc_draw(texture[F[j][i]],30*i-30,-30*j)-- drawCell(j,i,F[j][i])
|
||||
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
|
||||
if flag then
|
||||
gc_push("transform")
|
||||
gc.setShader(SHADER.lighter)
|
||||
gc.translate(0,-4)
|
||||
end
|
||||
::edgeFinished::
|
||||
for j=start,min(start+21,#F)do
|
||||
while j==P.clearingRow[h]do
|
||||
h=h+1
|
||||
gc_translate(0,-stepY)
|
||||
gc_setColor(1,1,1,A)
|
||||
gc_rectangle("fill",0,30-30*j,300,stepY)
|
||||
end
|
||||
drawRow(j,V[j],F[j])
|
||||
end
|
||||
if flag then
|
||||
gc_pop()
|
||||
gc.setShader()
|
||||
flag=false
|
||||
h=1
|
||||
goto edgeFinished
|
||||
end
|
||||
gc_pop()
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
extern float a;
|
||||
vec4 effect(vec4 color,Image text,vec2 pos,vec2 scr_pos){
|
||||
return vec4(1.,1.,1.,sign(Texel(text,pos).a)*a);
|
||||
vec4 effect(vec4 color,Image tex,vec2 tex_coords,vec2 scr_coords){
|
||||
return vec4(1.,1.,1.,sign(Texel(tex,tex_coords).a)*a);
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
#define PI 3.1415926535897932384626
|
||||
extern float w,h;
|
||||
extern float t;
|
||||
vec4 effect(vec4 color,Image text,vec2 pos,vec2 scr_pos){
|
||||
float x=scr_pos.x/w;
|
||||
float y=scr_pos.y/h;
|
||||
vec4 effect(vec4 color,Image tex,vec2 tex_coords,vec2 scr_coords){
|
||||
float x=scr_coords.x/w;
|
||||
float y=scr_coords.y/h;
|
||||
float dx,dy;
|
||||
vec3 V=vec3(0.);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
extern float t,w;
|
||||
vec4 effect(vec4 color,Image text,vec2 pos,vec2 scr_pos){
|
||||
float x=scr_pos.x/w;
|
||||
vec4 effect(vec4 color,Image tex,vec2 tex_coords,vec2 scr_coords){
|
||||
float x=scr_coords.x/w;
|
||||
return vec4(
|
||||
.8-x*.6,
|
||||
.3+.2*sin(t),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
extern float t,h;
|
||||
vec4 effect(vec4 color,Image text,vec2 pos,vec2 scr_pos){
|
||||
float y=scr_pos.y/h;
|
||||
vec4 effect(vec4 color,Image tex,vec2 tex_coords,vec2 scr_coords){
|
||||
float y=scr_coords.y/h;
|
||||
return vec4(
|
||||
.8-y*.6,
|
||||
.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;
|
||||
vec4 effect(vec4 color,Image text,vec2 pos,vec2 scr_pos){
|
||||
float x=scr_pos.x/w;
|
||||
float y=scr_pos.y/h;
|
||||
vec4 effect(vec4 color,Image tex,vec2 tex_coords,vec2 scr_coords){
|
||||
float x=scr_coords.x/w;
|
||||
float y=scr_coords.y/h;
|
||||
return vec4(
|
||||
.8-y*.7+.2*sin(t/6.26),
|
||||
.2+y*.5+.15*sin(t/4.),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
extern float t,w,h;
|
||||
vec4 effect(vec4 color,Image text,vec2 pos,vec2 scr_pos){
|
||||
float x=scr_pos.x/w;
|
||||
float y=scr_pos.y/h;
|
||||
vec4 effect(vec4 color,Image tex,vec2 tex_coords,vec2 scr_coords){
|
||||
float x=scr_coords.x/w;
|
||||
float y=scr_coords.y/h;
|
||||
return vec4(
|
||||
.8-y*.8-.1*sin(t/6.26),
|
||||
.4+.1*sin(t/4.)*(y+2.)/(y+5.),
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
extern float w,h;
|
||||
extern float level;
|
||||
vec4 effect(vec4 color,Image text,vec2 pos,vec2 scr_pos){
|
||||
float dx=abs(scr_pos.x/w-0.5);
|
||||
float dy=abs(scr_pos.y/h-0.5);
|
||||
vec4 effect(vec4 color,Image tex,vec2 tex_coords,vec2 scr_coords){
|
||||
float dx=abs(scr_coords.x/w-0.5);
|
||||
float dy=abs(scr_coords.y/h-0.5);
|
||||
float a=(max(dx*2.6,dy*1.8)-.626)*level;
|
||||
return vec4(1.,0.,0.,a);
|
||||
}
|
||||
Reference in New Issue
Block a user