Scene fades out as view distance becomes greater.

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
Nic0Nic0Nii 3 years ago
parent 2868869bdd
commit 048c8fd983
  1. 37
      src/sig/Panel.java
  2. 4
      src/sig/SigRenderer.java
  3. 73
      src/sig/TestKernel.java

@ -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,DrawUtils.NORMAL_RENDERING,SigRenderer.RESOLUTION);
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,SigRenderer.RESOLUTION);
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,SigRenderer.RESOLUTION);
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());
}
@ -562,6 +551,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();
}

@ -44,6 +44,10 @@ public class SigRenderer implements WindowFocusListener,KeyListener,MouseListene
public static float DRAWTIME=0;
public static float DRAWLOOPTIME=0;
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<>();

@ -1,73 +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;
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;
}
}
Loading…
Cancel
Save