Compare commits

...

7 Commits
new2 ... main

Author SHA1 Message Date
Nic0Nic0Nii af6908808e Fixing aliasing issues. 3 years ago
Nic0Nic0Nii cc3a6baf15 Corrected error in pixel interpolating. 3 years ago
Nic0Nic0Nii 23fdde1a2f Add in one blending pass to reduce gaps. 3 years ago
Nic0Nic0Nii 8cc20d4518 Snap pixel to nearest region for cleaner tiling. 3 years ago
Nic0Nic0Nii f7c532e759 Fix click detection. 3 years ago
Nic0Nic0Nii 048c8fd983 Scene fades out as view distance becomes greater. 3 years ago
Joshua Sigona 2868869bdd Everything 3 years ago
  1. 58
      src/sig/Panel.java
  2. 8
      src/sig/SigRenderer.java
  3. 76
      src/sig/TestKernel.java
  4. 253
      src/sig/utils/DrawUtils.java

@ -101,7 +101,7 @@ public class Panel extends JPanel implements Runnable {
if(p.length != width * height) return;
for (int x=0;x<width;x++) {
for (int y=0;y<height;y++) {
p[ (int)(x*SigRenderer.RESOLUTION) + (int)(y*SigRenderer.RESOLUTION) * width] = 0;
p[ x + y * width] = 0;
SigRenderer.depthBuffer[x+y*width]=0;
SigRenderer.depthBuffer_tri[x+y*width]=null;
SigRenderer.translucencyBuffer[x+y*width]=false;
@ -234,6 +234,7 @@ public class Panel extends JPanel implements Runnable {
prepareTriForRender(matWorld, matView, t.unmodifiedTri, newTris, true);
}
currentRender=newTris;
Vector newCamera = Vector.add(SigRenderer.vCamera,SigRenderer.vCameraOffset);
for (Triangle t : currentRender) {
Triangle[] clipped = new Triangle[]{new Triangle(),new Triangle()};
List<Triangle> triList = new ArrayList<>();
@ -269,11 +270,7 @@ public class Panel extends JPanel implements Runnable {
tt.unmodifiedTri.nextRenderTime2=System.currentTimeMillis()+50;
}
SigRenderer.temp_request=SigRenderer.request;
DrawUtils.TexturedTriangle(p,
(int)tt.A.x,(int)tt.A.y,tt.T.u,tt.T.v,tt.T.w,
(int)tt.B.x,(int)tt.B.y,tt.U.u,tt.U.v,tt.U.w,
(int)tt.C.x,(int)tt.C.y,tt.V.u,tt.V.v,tt.V.w,
tt.tex,(tt.col&0xFF0000)>>16,tt);
RenderTriangle(p,tt,DrawUtils.NORMAL_RENDERING,newCamera);
} else {
DrawUtils.FillTriangle(p,(int)tt.A.x,(int)tt.A.y,(int)tt.B.x,(int)tt.B.y,(int)tt.C.x,(int)tt.C.y,tt.getColor());
}
@ -338,11 +335,7 @@ public class Panel extends JPanel implements Runnable {
}
for (Triangle tt : triList) {
if (tt.tex!=null) {
DrawUtils.TexturedTriangle(p,
(int)tt.A.x,(int)tt.A.y,tt.T.u,tt.T.v,tt.T.w,
(int)tt.B.x,(int)tt.B.y,tt.U.u,tt.U.v,tt.U.w,
(int)tt.C.x,(int)tt.C.y,tt.V.u,tt.V.v,tt.V.w,
tt.tex,(tt.col&0xFF0000)>>16,tt,DrawUtils.IGNORE_TRANSLUCENT_RENDERING);
RenderTriangle(p,tt,DrawUtils.IGNORE_TRANSLUCENT_RENDERING,newCamera);
} else {
DrawUtils.FillTriangle(p,(int)tt.A.x,(int)tt.A.y,(int)tt.B.x,(int)tt.B.y,(int)tt.C.x,(int)tt.C.y,tt.getColor());
}
@ -384,11 +377,7 @@ public class Panel extends JPanel implements Runnable {
for (Triangle tt : triList) {
if (tt.tex!=null) {
tt.unmodifiedTri.nextRenderTime=tt.unmodifiedTri.nextRenderTime2=-1;
DrawUtils.TexturedTriangle(p,
(int)tt.A.x,(int)tt.A.y,tt.T.u,tt.T.v,tt.T.w,
(int)tt.B.x,(int)tt.B.y,tt.U.u,tt.U.v,tt.U.w,
(int)tt.C.x,(int)tt.C.y,tt.V.u,tt.V.v,tt.V.w,
tt.tex,(tt.col&0xFF0000)>>16,tt,DrawUtils.TRANSLUCENT_ONLY_RENDERING);
RenderTriangle(p,tt,DrawUtils.TRANSLUCENT_ONLY_RENDERING,newCamera);
} else {
DrawUtils.FillTriangle(p,(int)tt.A.x,(int)tt.A.y,(int)tt.B.x,(int)tt.B.y,(int)tt.C.x,(int)tt.C.y,tt.getColor());
}
@ -411,6 +400,25 @@ public class Panel extends JPanel implements Runnable {
}
}
for (int x=0;x<width;x++) {
for (int y=0;y<height;y++) {
if (SigRenderer.depthBuffer[x+y*width]==0) {
if (y-1>=0&&SigRenderer.depthBuffer[x+(y-1)*width]!=0) {
p[x+y*width]=p[x+(y-1)*width];
}else
if (y+1<SigRenderer.SCREEN_HEIGHT&&SigRenderer.depthBuffer[x+(y+1)*width]!=0) {
p[x+y*width]=p[x+(y+1)*width];
}else
if (x+1<SigRenderer.SCREEN_WIDTH&&SigRenderer.depthBuffer[x+1+y*width]!=0) {
p[x+y*width]=p[x+1+y*width];
}else
if (x-1>=0&&SigRenderer.depthBuffer[x-1+y*width]!=0) {
p[x+y*width]=p[x-1+y*width];
}
}
}
}
SigRenderer.request=null;
SigRenderer.answer=SigRenderer.tempAnswer;
if (SigRenderer.PROFILING) {
@ -562,6 +570,24 @@ public class Panel extends JPanel implements Runnable {
}
}
public void RenderTriangle(int[] pixels,Triangle tt,int renderMode,Vector newCamera) {
float distSquared = ((tt.b.pos.x-newCamera.x)*(tt.b.pos.x-newCamera.x)+
(tt.b.pos.y-newCamera.y)*(tt.b.pos.y-newCamera.y)+
(tt.b.pos.z-newCamera.z)*(tt.b.pos.z-newCamera.z));
int finalResolution = SigRenderer.MAPLV2_RESOLUTION;
if (distSquared<SigRenderer.MAPLV1_DISTANCE) {
finalResolution=SigRenderer.RESOLUTION;
} else
if (distSquared<SigRenderer.MAPLV2_DISTANCE) {
finalResolution=SigRenderer.MAPLV1_RESOLUTION;
}
DrawUtils.TexturedTriangle(pixels,
(int)tt.A.x,(int)tt.A.y,tt.T.u,tt.T.v,tt.T.w,
(int)tt.B.x,(int)tt.B.y,tt.U.u,tt.U.v,tt.U.w,
(int)tt.C.x,(int)tt.C.y,tt.V.u,tt.V.v,tt.V.w,
tt.tex,(tt.col&0xFF0000)>>16,tt,renderMode,finalResolution);
}
public void repaint() {
super.repaint();
}

@ -43,7 +43,11 @@ public class SigRenderer implements WindowFocusListener,KeyListener,MouseListene
public final static long TIMEPERTICK = 16666667l;
public static float DRAWTIME=0;
public static float DRAWLOOPTIME=0;
public static final float RESOLUTION=1;
public static final int RESOLUTION=2;
public static final int MAPLV1_RESOLUTION=4;
public static final int MAPLV1_DISTANCE=16;
public static final int MAPLV2_RESOLUTION=8;
public static final int MAPLV2_DISTANCE=256;
public static Robot myRobot;
public static float rot = (float)Math.PI/4; //In radians.
public static ConcurrentHashMap<String,Block> blockGrid = new ConcurrentHashMap<>();
@ -402,6 +406,7 @@ public class SigRenderer implements WindowFocusListener,KeyListener,MouseListene
for (int x=0;x<64;x++) {
for (int z=0;z<64;z++) {
addBlock(new Vector(x,0,z),Cube.class,BlockType.SOIL_WET,FacingDirection.SOUTH);
//addBlock(new Vector(x,1,z),Plant.class,BlockType.valueOf("WHEAT_"+(r.nextInt(7))),FacingDirection.SOUTH);
//addBlock(new Vector(x,1,z),Staircase.class,BlockType.JUNGLE_PLANK,FacingDirection.SOUTH);
//addBlock(new Vector(x,2,z),Staircase.class,BlockType.SPRUCE_PLANK,FacingDirection.SOUTH);
/*for (int y=1;y<r.nextInt(5);y++) {
@ -428,7 +433,6 @@ public class SigRenderer implements WindowFocusListener,KeyListener,MouseListene
}*/
}
}
addBlock(new Vector(31,1,31),Plant.class,BlockType.valueOf("WHEAT_"+(r.nextInt(7))),FacingDirection.SOUTH);
/*addBlock(new Vector(31,2,32),Staircase.class,BlockType.PLANKS,FacingDirection.EAST);
addBlock(new Vector(31,3,33),Staircase.class,BlockType.PLANKS,FacingDirection.WEST);
addBlock(new Vector(31,4,34),Staircase.class,BlockType.PLANKS,FacingDirection.SOUTH);

@ -1,76 +0,0 @@
package sig;
import java.util.Arrays;
import com.aparapi.Kernel;
import com.aparapi.Range;
import com.aparapi.device.Device;
public class TestKernel extends Kernel{
int[] a,b;
float[] sum;
boolean test1,test2;
final int val=55555555;
TestKernel(int[] a,int[] b,float[] sum,boolean test1,boolean test2) {
this.a=a;
this.b=b;
this.sum=sum;
this.test1=test1;
this.test2=test2;
}
public static void main(String[] args) {
int size = 1024;
final int[] a = new int[size];
int[] b = new int[size];
for (int i = 0; i < size; i++) {
a[i] = (int) (Math.random() * 100);
b[i] = (int) (Math.random() * 100);
}
float[] sum = new float[size];
TestKernel kernel = new TestKernel(a,b,sum,true,false);
//System.out.println("Start...");
kernel.execute(Range.create(size));
//System.out.println("Running...");
//size=5;
kernel.b[0]=50;
kernel.b[1]=45;
/*for (int i = 0; i < size; i++) {
b[i] = (int) (Math.random() * 100);
}*/
long timer1=System.nanoTime();
for (int i=0;i<900;i++) {
kernel.execute(Range.create(size));
}
System.out.println((System.nanoTime()-timer1)+"ns");
kernel.dispose();
System.out.println(Arrays.toString(sum));
timer1=System.nanoTime();
for (int j=0;j<900;j++) {
for (int i=0;i<sum.length;i++) {
sum[i]=a[i]+b[i];
}
}
System.out.println((System.nanoTime()-timer1)+"ns");
}
@Override
public void run() {
int gid = getGlobalId();
sum[gid] = a[gid]+b[gid];
}
void addExtra(int numb,int id) {
a[id]+=numb;
b[id]+=numb;
}
}

@ -18,19 +18,69 @@ public class DrawUtils {
Draw(canvas,i,ny,col);
}
}
private static boolean CheckAllTexels(float tex_w, float[] buffer, int x,int y, int texelSize) {
for (int xx=0;xx<texelSize;xx++) {
for (int yy=0;yy<texelSize;yy++) {
if (x+xx>=0&&x+xx<SigRenderer.SCREEN_WIDTH&&
y+yy>=0&&y+yy<SigRenderer.SCREEN_HEIGHT&&
tex_w<=buffer[(y+yy)*SigRenderer.SCREEN_WIDTH+(x+xx)]) {
return false;
}
}
}
return true;
}
private static void setArrayTexels(float[] buffer, int x,int y,float value,int texelSize) {
for (int xx=0;xx<texelSize;xx++) {
for (int yy=0;yy<texelSize;yy++) {
if (x+xx>=0&&x+xx<SigRenderer.SCREEN_WIDTH&&
y+yy>=0&&y+yy<SigRenderer.SCREEN_HEIGHT) {
buffer[(y+yy)*SigRenderer.SCREEN_WIDTH+(x+xx)]=value;
}
}
}
}
private static void setArrayTexels(Triangle[] buffer, int x,int y,Triangle value,int texelSize) {
for (int xx=0;xx<texelSize;xx++) {
for (int yy=0;yy<texelSize;yy++) {
if (x+xx>=0&&x+xx<SigRenderer.SCREEN_WIDTH&&
y+yy>=0&&y+yy<SigRenderer.SCREEN_HEIGHT) {
buffer[(y+yy)*SigRenderer.SCREEN_WIDTH+(x+xx)]=value;
}
}
}
}
private static void setArrayTexels(boolean[] buffer, int x,int y,boolean value,int texelSize) {
for (int xx=0;xx<texelSize;xx++) {
for (int yy=0;yy<texelSize;yy++) {
if (x+xx>=0&&x+xx<SigRenderer.SCREEN_WIDTH&&
y+yy>=0&&y+yy<SigRenderer.SCREEN_HEIGHT) {
buffer[(y+yy)*SigRenderer.SCREEN_WIDTH+(x+xx)]=value;
}
}
}
}
public static void TexturedTriangle(int[] canvas,
int x1, int y1, float u1,float v1,float w1,
int x2, int y2, float u2,float v2,float w2,
int x3, int y3, float u3,float v3,float w3,
Texture texture, int colorMult,Triangle ref) {
TexturedTriangle(canvas,x1,y1,u1,v1,w1,x2,y2,u2,v2,w2,x3,y3,u3,v3,w3,texture,colorMult,ref,NORMAL_RENDERING);
TexturedTriangle(canvas,x1,y1,u1,v1,w1,x2,y2,u2,v2,w2,x3,y3,u3,v3,w3,texture,colorMult,ref,NORMAL_RENDERING,1);
}
public static void TexturedTriangle(int[] canvas,
int x1, int y1, float u1,float v1,float w1,
int x2, int y2, float u2,float v2,float w2,
int x3, int y3, float u3,float v3,float w3,
Texture texture, int colorMult,Triangle ref,
int rendering_state) {
TexturedTriangle(canvas,x1,y1,u1,v1,w1,x2,y2,u2,v2,w2,x3,y3,u3,v3,w3,texture,colorMult,ref,rendering_state,1);
}
public static void TexturedTriangle(int[] canvas,
int x1, int y1, float u1,float v1,float w1,
int x2, int y2, float u2,float v2,float w2,
int x3, int y3, float u3,float v3,float w3,
Texture texture, int colorMult,Triangle ref,
int rendering_state
int rendering_state,int texelSize
) {
if (y2<y1) {int t=y1;y1=y2;y2=t;t=x1;x1=x2;x2=t;float u=u1;u1=u2;u2=u;float v=v1;v1=v2;v2=v;float w=w1;w1=w2;w2=w;}
if (y3<y1) {int t=y1;y1=y3;y3=t;t=x1;x1=x3;x3=t;float u=u1;u1=u3;u3=u;float v=v1;v1=v3;v3=v;float w=w1;w1=w3;w3=w;}
@ -63,7 +113,7 @@ public class DrawUtils {
if (dy2!=0) {dw2_step=dw2/((float)Math.abs(dy2));}
if (dy1!=0) {
for (int i=y1;i<=y2;i+=4) {
for (int i=y1;i<((y1+texelSize)/texelSize)*texelSize;i++) {
int ax=(int)(x1+((float)(i-y1))*dax_step);
int bx=(int)(x1+((float)(i-y1))*dbx_step);
@ -88,39 +138,103 @@ public class DrawUtils {
float tstep = 1.0f/(float)(bx-ax);
float t=0.0f;
for (int j=ax;j<=bx;j+=4) {
for (int j=ax;j<((ax+texelSize)/texelSize)*texelSize;j++) {
tex_u=(1.0f-t)*tex_su+t*tex_eu;
tex_v=(1.0f-t)*tex_sv+t*tex_ev;
tex_w=(1.0f-t)*tex_sw+t*tex_ew;
if (SigRenderer.temp_request!=null) {
if (tex_w>SigRenderer.depthBuffer_noTransparency[i*SigRenderer.SCREEN_WIDTH+j]) {
SigRenderer.depthBuffer_noTransparency[i*SigRenderer.SCREEN_WIDTH+j]=tex_w;
if (CheckAllTexels(tex_w,SigRenderer.depthBuffer_noTransparency,j,i,1)) {
setArrayTexels(SigRenderer.depthBuffer_noTransparency,j,i,tex_w,1);
if (j==SigRenderer.temp_request.getX()&&i==SigRenderer.temp_request.getY()) {
SigRenderer.tempAnswer=new MouseHandler(SigRenderer.temp_request,ref);
}
}
}
if (tex_w>SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+j]) {
if (CheckAllTexels(tex_w,SigRenderer.depthBuffer,j,i,1)) {
int col = texture.getColor(tex_u/tex_w,tex_v/tex_w,colorMult/255f);
if (((col&0xFF000000)>>>24)!=0) {
if (((col&0xFF000000)>>>24)!=255) {
if (rendering_state==TRANSLUCENT_ONLY_RENDERING||
rendering_state==NORMAL_RENDERING) {
Draw(canvas,j,i,col,1);
setArrayTexels(SigRenderer.depthBuffer,j,i,tex_w,1);
if (rendering_state!=TRANSLUCENT_ONLY_RENDERING) {
setArrayTexels(SigRenderer.depthBuffer_tri,j,i,ref.unmodifiedTri,1);
}
setArrayTexels(SigRenderer.translucencyBuffer,j,i,true,1);
}
} else {
if (rendering_state!=TRANSLUCENT_ONLY_RENDERING) {
Draw(canvas,j,i,col,1);
setArrayTexels(SigRenderer.depthBuffer,j,i,tex_w,1);
setArrayTexels(SigRenderer.depthBuffer_tri,j,i,ref.unmodifiedTri,1);
}
}
}
}
t+=tstep*1;
}
}
for (int i=((y1+texelSize)/texelSize)*texelSize;i<=y2;i+=texelSize) {
int ax=(int)(x1+((float)(i-y1))*dax_step);
int bx=(int)(x1+((float)(i-y1))*dbx_step);
float tex_su=u1+((float)(i-y1))*du1_step;
float tex_sv=v1+((float)(i-y1))*dv1_step;
float tex_sw=w1+((float)(i-y1))*dw1_step;
float tex_eu=u1+((float)(i-y1))*du2_step;
float tex_ev=v1+((float)(i-y1))*dv2_step;
float tex_ew=w1+((float)(i-y1))*dw2_step;
if (ax>bx) {
int t=ax;ax=bx;bx=t;
float u=tex_su;tex_su=tex_eu;tex_eu=u;
float v=tex_sv;tex_sv=tex_ev;tex_ev=v;
float w=tex_sw;tex_sw=tex_ew;tex_ew=w;
}
tex_u=tex_su;
tex_v=tex_sv;
tex_w=tex_sw;
float tstep = 1.0f/(float)(bx-ax);
float t=0.0f;
for (int j=((ax+texelSize)/texelSize)*texelSize;j<=bx;j+=texelSize) {
tex_u=(1.0f-t)*tex_su+t*tex_eu;
tex_v=(1.0f-t)*tex_sv+t*tex_ev;
tex_w=(1.0f-t)*tex_sw+t*tex_ew;
if (SigRenderer.temp_request!=null) {
if (CheckAllTexels(tex_w,SigRenderer.depthBuffer_noTransparency,j,i,texelSize)) {
setArrayTexels(SigRenderer.depthBuffer_noTransparency,j,i,tex_w,texelSize);
if (SigRenderer.temp_request.getX()-j<=texelSize&&SigRenderer.temp_request.getY()-i<=texelSize) {
SigRenderer.tempAnswer=new MouseHandler(SigRenderer.temp_request,ref);
}
}
}
if (CheckAllTexels(tex_w,SigRenderer.depthBuffer,j,i,texelSize)) {
int col = texture.getColor(tex_u/tex_w,tex_v/tex_w,colorMult/255f);
if (((col&0xFF000000)>>>24)!=0) {
if (((col&0xFF000000)>>>24)!=255) {
if (rendering_state==TRANSLUCENT_ONLY_RENDERING||
rendering_state==NORMAL_RENDERING) {
Draw(canvas,j,i,col,4);
SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+j] = tex_w;
SigRenderer.depthBuffer_tri[i*SigRenderer.SCREEN_WIDTH+j] = ref.unmodifiedTri;
SigRenderer.translucencyBuffer[i*SigRenderer.SCREEN_WIDTH+j] = true;
Draw(canvas,j,i,col,texelSize);
setArrayTexels(SigRenderer.depthBuffer,j,i,tex_w,texelSize);
if (rendering_state!=TRANSLUCENT_ONLY_RENDERING) {
setArrayTexels(SigRenderer.depthBuffer_tri,j,i,ref.unmodifiedTri,texelSize);
}
setArrayTexels(SigRenderer.translucencyBuffer,j,i,true,texelSize);
}
} else {
if (rendering_state!=TRANSLUCENT_ONLY_RENDERING) {
Draw(canvas,j,i,col,4);
SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+j] = tex_w;
SigRenderer.depthBuffer_tri[i*SigRenderer.SCREEN_WIDTH+j] = ref.unmodifiedTri;
Draw(canvas,j,i,col,texelSize);
setArrayTexels(SigRenderer.depthBuffer,j,i,tex_w,texelSize);
setArrayTexels(SigRenderer.depthBuffer_tri,j,i,ref.unmodifiedTri,texelSize);
}
}
}
}
t+=tstep*4;
t+=tstep*texelSize;
}
}
}
@ -139,7 +253,7 @@ public class DrawUtils {
if (dy1!=0) {dw1_step=dw1/((float)Math.abs(dy1));}
if (dy1!=0) {
for (int i=y2;i<=y3;i+=4) {
for (int i=y2;i<((y2+texelSize)/texelSize)*texelSize;i++) {
int ax=(int)(x2+((float)(i-y2))*dax_step);
int bx=(int)(x1+((float)(i-y1))*dbx_step);
@ -164,41 +278,106 @@ public class DrawUtils {
float tstep = 1.0f/(float)(bx-ax);
float t=0.0f;
for (int j=ax;j<=bx;j+=4) {
for (int j=ax;j<=((ax+texelSize)/texelSize)*texelSize;j++) {
tex_u=(1.0f-t)*tex_su+t*tex_eu;
tex_v=(1.0f-t)*tex_sv+t*tex_ev;
tex_w=(1.0f-t)*tex_sw+t*tex_ew;
if (SigRenderer.temp_request!=null) {
if (tex_w>SigRenderer.depthBuffer_noTransparency[i*SigRenderer.SCREEN_WIDTH+j]) {
SigRenderer.depthBuffer_noTransparency[i*SigRenderer.SCREEN_WIDTH+j]=tex_w;
if (j==SigRenderer.temp_request.getX()&&i==SigRenderer.temp_request.getY()) {
if (CheckAllTexels(tex_w,SigRenderer.depthBuffer_noTransparency,j,i,1)) {
setArrayTexels(SigRenderer.depthBuffer_noTransparency,j,i,tex_w,1);
if (SigRenderer.temp_request.getX()==j&&SigRenderer.temp_request.getY()==i) {
SigRenderer.tempAnswer=new MouseHandler(SigRenderer.temp_request,ref);
}
}
}
if (CheckAllTexels(tex_w,SigRenderer.depthBuffer,j,i,1)) {
int col = texture.getColor(tex_u/tex_w,tex_v/tex_w,colorMult/255f);
if (((col&0xFF000000)>>>24)!=0) {
if (((col&0xFF000000)>>>24)!=255) {
if (rendering_state==TRANSLUCENT_ONLY_RENDERING||
rendering_state==NORMAL_RENDERING) {
Draw(canvas,j,i,col,1);
setArrayTexels(SigRenderer.depthBuffer,j,i,tex_w,1);
if (rendering_state!=TRANSLUCENT_ONLY_RENDERING) {
setArrayTexels(SigRenderer.depthBuffer_tri,j,i,ref.unmodifiedTri,texelSize);
}
setArrayTexels(SigRenderer.translucencyBuffer,j,i,true,1);
}
} else {
if (rendering_state!=TRANSLUCENT_ONLY_RENDERING) {
Draw(canvas,j,i,col,1);
setArrayTexels(SigRenderer.depthBuffer,j,i,tex_w,1);
setArrayTexels(SigRenderer.depthBuffer_tri,j,i,ref.unmodifiedTri,1);
}
}
}
}
t+=tstep*1;
}
}
for (int i=((y2+texelSize)/texelSize)*texelSize;i<=y3;i+=texelSize) {
int ax=(int)(x2+((float)(i-y2))*dax_step);
int bx=(int)(x1+((float)(i-y1))*dbx_step);
float tex_su=u2+((float)(i-y2))*du1_step;
float tex_sv=v2+((float)(i-y2))*dv1_step;
float tex_sw=w2+((float)(i-y2))*dw1_step;
float tex_eu=u1+((float)(i-y1))*du2_step;
float tex_ev=v1+((float)(i-y1))*dv2_step;
float tex_ew=w1+((float)(i-y1))*dw2_step;
if (ax>bx) {
int t=ax;ax=bx;bx=t;
float u=tex_su;tex_su=tex_eu;tex_eu=u;
float v=tex_sv;tex_sv=tex_ev;tex_ev=v;
float w=tex_sw;tex_sw=tex_ew;tex_ew=w;
}
tex_u=tex_su;
tex_v=tex_sv;
tex_w=tex_sw;
float tstep = 1.0f/(float)(bx-ax);
float t=0.0f;
for (int j=((ax+texelSize)/texelSize)*texelSize;j<=bx;j+=texelSize) {
tex_u=(1.0f-t)*tex_su+t*tex_eu;
tex_v=(1.0f-t)*tex_sv+t*tex_ev;
tex_w=(1.0f-t)*tex_sw+t*tex_ew;
if (SigRenderer.temp_request!=null) {
if (CheckAllTexels(tex_w,SigRenderer.depthBuffer_noTransparency,j,i,texelSize)) {
setArrayTexels(SigRenderer.depthBuffer_noTransparency,j,i,tex_w,texelSize);
if (Math.abs(j-SigRenderer.temp_request.getX())<=texelSize/2+1&&
Math.abs(i-SigRenderer.temp_request.getY())<=texelSize/2+1) {
SigRenderer.tempAnswer=new MouseHandler(SigRenderer.temp_request,ref);
}
}
}
if (tex_w>SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+j]) {
if (CheckAllTexels(tex_w,SigRenderer.depthBuffer,j,i,texelSize)) {
int col = texture.getColor(tex_u/tex_w,tex_v/tex_w,colorMult/255f);
if (((col&0xFF000000)>>>24)!=0) {
if (((col&0xFF000000)>>>24)!=255) {
if (rendering_state==TRANSLUCENT_ONLY_RENDERING||
rendering_state==NORMAL_RENDERING) {
Draw(canvas,j,i,col,4);
SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+j] = tex_w;
Draw(canvas,j,i,col,texelSize);
setArrayTexels(SigRenderer.depthBuffer,j,i,tex_w,texelSize);
if (rendering_state!=TRANSLUCENT_ONLY_RENDERING) {
SigRenderer.depthBuffer_tri[i*SigRenderer.SCREEN_WIDTH+j] = ref.unmodifiedTri;
setArrayTexels(SigRenderer.depthBuffer_tri,j,i,ref.unmodifiedTri,texelSize);
}
SigRenderer.translucencyBuffer[i*SigRenderer.SCREEN_WIDTH+j] = true;
setArrayTexels(SigRenderer.translucencyBuffer,j,i,true,texelSize);
}
} else {
if (rendering_state!=TRANSLUCENT_ONLY_RENDERING) {
Draw(canvas,j,i,col,4);
SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+j] = tex_w;
SigRenderer.depthBuffer_tri[i*SigRenderer.SCREEN_WIDTH+j] = ref.unmodifiedTri;
Draw(canvas,j,i,col,texelSize);
setArrayTexels(SigRenderer.depthBuffer,j,i,tex_w,texelSize);
setArrayTexels(SigRenderer.depthBuffer_tri,j,i,ref.unmodifiedTri,texelSize);
}
}
}
}
t+=tstep*4;
t+=tstep*texelSize;
}
}
}
@ -407,15 +586,19 @@ public class DrawUtils {
int new_r=(int)(ratio*r+(1-ratio)*prev_r);
int new_g=(int)(ratio*g+(1-ratio)*prev_g);
int new_b=(int)(ratio*b+(1-ratio)*prev_b);
for (int xx=-texelSize/2;xx<(texelSize+1)/2;xx++) {
for (int yy=-texelSize/2;yy<(texelSize+1)/2;yy++) {
canvas[((x+xx)*texelSize)/texelSize+(((y+yy)*texelSize)/texelSize)*SigRenderer.SCREEN_WIDTH]=new_r+(new_g<<8)+(new_b<<16)+(col&0xFF000000);
for (int xx=0;xx<texelSize;xx++) {
for (int yy=0;yy<texelSize;yy++) {
if (x+xx>=0&&x+xx<SigRenderer.SCREEN_WIDTH&&y+yy>=0&&y+yy<SigRenderer.SCREEN_HEIGHT) {
canvas[x+xx+(y+yy)*SigRenderer.SCREEN_WIDTH]=new_r+(new_g<<8)+(new_b<<16)+(col&0xFF000000);
}
}
}
} else {
for (int xx=-texelSize/2;xx<(texelSize+1)/2;xx++) {
for (int yy=-texelSize/2;yy<(texelSize+1)/2;yy++) {
canvas[((x+xx)*texelSize)/texelSize+(((y+yy)*texelSize)/texelSize)*SigRenderer.SCREEN_WIDTH]=col;
for (int xx=0;xx<texelSize;xx++) {
for (int yy=0;yy<texelSize;yy++) {
if (x+xx>=0&&x+xx<SigRenderer.SCREEN_WIDTH&&y+yy>=0&&y+yy<SigRenderer.SCREEN_HEIGHT) {
canvas[x+xx+(y+yy)*SigRenderer.SCREEN_WIDTH]=col;
}
}
}
}

Loading…
Cancel
Save