Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (773)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (856)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1] 2
  ignore  |  Print  
  Global Illumination via Voxel Cone Tracing in LWJGL  (Read 60117 times)
0 Members and 1 Guest are viewing this topic.
Offline openvisiongames

Junior Newbie


Medals: 7



« Posted 2015-10-04 23:51:56 »

Hi all - I've already posted this on gamedev.net today, but I figured I may as well post to JGO as well, seeing as I implemented this in LWJGL!  Grin

I was inspired to implement this into my game engine after watching Unreal Engine footage.
After finding some sample code for OpenGL in C++, I was more intrigued and decided to implement my own version.

Here are some screenshots to show off the effect:





Here is some of my code for building the textures:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
for (int i = 0; i < 2; i++) {
         textures[i] = GL11.glGenTextures();
         glBindTexture(GL_TEXTURE_3D, textures[i]);
         glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, TextureFilter.LinearMipMapLinear);
         glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, TextureFilter.LinearMipMapLinear);
         glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
         glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
         glTexStorage3D(GL_TEXTURE_3D, 1, GL_RGBA32F, 128, 128, 128);
         GL30.glGenerateMipmap(GL_TEXTURE_3D);
         glBindTexture(GL_TEXTURE_3D, 0);
         gilight[i] = new GIRenderer(rm, textures, voxelShader, i, viewCam, camDir[i]);
         gilight[i].init();
      }



This is where I set up the two (for now) 3D textures. I have a camera facing one side of the scene, and another facing the opposite side of the scene.
When the scene is rendered for each camera, the pixels that are rendered are stored into it's respective 3D texture.
 
I then bind the 3D textures to the forward lighting shader, here is what this looks like.

1  
uniform sampler3D tex[2];


I then trace a cone into the 3D texture to retrieve reflections. (Credit to Alex Nankervis, found this code on Geeks3D)

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
vec4 voxelTraceCone(float minVoxelDiameter, vec3 origin, vec3 dir, float coneRatio, float maxDist)
{
   float minVoxelDiameterInv = 1.0/minVoxelDiameter;
   vec3 samplePos = origin;
   vec4 accum = vec4(0.0);
   float minDiameter = minVoxelDiameter;
   float startDist = minDiameter;
   float dist = startDist;
   vec4 fadeCol = ambientLight.color*0.2;
   while (dist <= maxDist && accum.w < 1.0)
   {
      float sampleDiameter = max(minDiameter, coneRatio * dist);
      float sampleLOD = log2(sampleDiameter * minVoxelDiameterInv);
      vec3 samplePos = origin + dir * dist;
      vec4 sampleValue = voxelFetch(samplePos, -dir, sampleLOD);
      sampleValue = mix(sampleValue,fadeCol, clamp(dist/maxDist-0.25, 0.0, 1.0));
      float sampleWeight = (1.0 - accum.w);
      accum += sampleValue * sampleWeight;
      dist += sampleDiameter;
   }
   return accum;
}


I hope this helped some people understand how voxel cone tracing works in some more simpler terms. It was a real task to implement this and I still have some work to do, but as you can see from my screenshots, it works well so far!
Offline theagentd
« Reply #1 - Posted 2015-10-05 01:40:37 »

This is really cool!

Are you using sparse textures? What memory usage are you getting? How are you voxelizing the game world? Are you revoxelizing dynamic objects each frame? Performance at different resolutions?

Myomyomyo.
Offline theagentd
« Reply #2 - Posted 2015-10-06 11:35:37 »

No update? =<

Myomyomyo.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline deepthought
« Reply #3 - Posted 2015-10-19 16:51:29 »

Mind uploading you program to shared code or JGO files?

Mad Scientist
Offline KaiHH

JGO Kernel


Medals: 635



« Reply #4 - Posted 2015-10-19 18:26:45 »

OpenGL Insights has some very nice paper about the general algorithm: http://www.seas.upenn.edu/~pcozzi/OpenGLInsights/OpenGLInsights-SparseVoxelization.pdf
Offline h.pernpeintner

JGO Ninja


Medals: 106



« Reply #5 - Posted 2015-12-11 13:54:35 »

Is there any news from the thread creator? Smiley I would like to see more stuff, especially videos from your demo app or even an executable, since I'm going to implement VCT soon with LWJGL, too.
Offline Kefwar
« Reply #6 - Posted 2015-12-11 15:48:29 »

Is there any news from the thread creator? Smiley I would like to see more stuff, especially videos from your demo app or even an executable, since I'm going to implement VCT soon with LWJGL, too.

I found the gamedev.net thread with a simple google search on the IMG url used in this thread xD
You can find it here.

Offline h.pernpeintner

JGO Ninja


Medals: 106



« Reply #7 - Posted 2015-12-24 13:05:27 »

I implemented this with LWJGL too, but used a 256*256*256 3d texture. The (automatic) mipmapping takes unbelievable 500ms on my GTX 770 and therefore destroys the whole approach. I'm using

GL11.glTexParameteri(GL12.GL_TEXTURE_3D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
GL11.glTexParameteri(GL12.GL_TEXTURE_3D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);

Can anyone share a similar experience - or give me some info about how to speed things up a bit (different filters?)? I would implement compute shader based mipmapping otherwise.
Offline theagentd
« Reply #8 - Posted 2015-12-24 16:01:52 »

Automatic mipmapping is slow. Also, 256^3 is 8x the pixels of 1920x1080, so generating the first mipmap (the 128^3 one) is a huge amount of work: around 2 million pixels reading 128MBs of data assuming GL_RGB16F.

I'd try using GL_R11F_G11F_B10F to halve the bandwidth and memory cost and do the downsampling of mipmaps in a shader instead.

Myomyomyo.
Offline h.pernpeintner

JGO Ninja


Medals: 106



« Reply #9 - Posted 2015-12-24 22:12:38 »

Ok, limiting the bandwidth is the next thing i will try but i wonder how everyone is talking about voxel cone tracing with 256 * 256 * 256 3d textures if it isn't even possible to mipmap it automatically... I'm pretty sure i can mipmap 8 fullhd textures per frame, but i may be wrong. More results coming.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline theagentd
« Reply #10 - Posted 2015-12-24 23:06:53 »

Doing it manually is easy. Just render a fullscreen quad to each layer of the mipmap and do a single GL_LINEAR texture sample to sample all 8 parent texels with one sample.

Myomyomyo.
Offline h.pernpeintner

JGO Ninja


Medals: 106



« Reply #11 - Posted 2015-12-25 00:44:53 »

Yes, its Not the Problem, did it often, the Problem is that i have to do it Cheesy and of course its a pity that automatic mipmapping Performance is so poor.
Offline h.pernpeintner

JGO Ninja


Medals: 106



« Reply #12 - Posted 2016-01-11 11:53:08 »

A pity that there is so little time to work on private projects. I managed to implement a basic voxel cone tracing approach with LWJGL with compute shader based mipmapping, so that it can be done in realtime now. Very unoptimized, very ugly, some parts are actually WRONG and overall far from completed, but I thought you guys like to see something done with Java.

pure specular tracing


emmissive material applied to have arealight
Offline theagentd
« Reply #13 - Posted 2016-01-11 13:39:17 »

The second image isn't loading, but... Damn! Looks good!

Myomyomyo.
Offline EgonOlsen
« Reply #14 - Posted 2016-01-11 18:00:05 »

The second image isn't loading, but... Damn! Looks good!
It loads if you copy the URL directly into the browser.

Offline theagentd
« Reply #15 - Posted 2016-01-11 18:11:00 »

emmissive material applied to have arealight

Damn. What really gets me is the colored reflection on the arcs...

Myomyomyo.
Offline h.pernpeintner

JGO Ninja


Medals: 106



« Reply #16 - Posted 2016-01-11 21:26:47 »

More love for you



pretty cool results so far.
Offline theagentd
« Reply #17 - Posted 2016-01-12 03:52:06 »

Daaaaaaamn...

How dynamic is this? Are you voxelizing the world every frame or using a precomputed voxel world?

Myomyomyo.
Offline h.pernpeintner

JGO Ninja


Medals: 106



« Reply #18 - Posted 2016-01-12 08:08:58 »

Completely dynamic: voxelization is done every frame, lighting is done every frame, filtering is done every frame. I'm not yet using a sparse data structure so that won't change in the near future.
Offline Roquen

JGO Kernel


Medals: 518



« Reply #19 - Posted 2016-01-12 12:21:28 »

The second image isn't loading, but... Damn! Looks good!
What's strange for me is that none of these pictures are showing up and there isn't even any indication that there's anything I'm missing (no empty box or anything...just whitespace like a text only post)
Offline theagentd
« Reply #20 - Posted 2016-01-12 14:21:49 »

Completely dynamic: voxelization is done every frame, lighting is done every frame, filtering is done every frame. I'm not yet using a sparse data structure so that won't change in the near future.
Oww, that sounds slow? Triangle count? Voxelization timings? Total frame timings? Are you using conservative rasterization for it? Voxel resolution? Memory usage?

Myomyomyo.
Offline Riven
Administrator

« JGO Overlord »


Medals: 1356
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #21 - Posted 2016-01-12 19:40:43 »

The second image isn't loading, but... Damn! Looks good!
What's strange for me is that none of these pictures are showing up and there isn't even any indication that there's anything I'm missing (no empty box or anything...just whitespace like a text only post)
It's because even though the URL ends with .jpg, the http-response is actually HTML, which contains an img-tag to http://s14.postimg.org/azy70ypnz/vct_arealight.jpg


Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Offline theagentd
« Reply #22 - Posted 2016-01-14 03:02:41 »

Awww, don't leave us hanging! q.q I-if it's medals you want, I'm sure we can agree on a price.......  Roll Eyes

Myomyomyo.
Offline Riven
Administrator

« JGO Overlord »


Medals: 1356
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #23 - Posted 2016-01-14 05:53:59 »

postimg.org is quite insidious. every direct link to an image eventually turns into an HTML page with a new direct link to the image... Please use imgur.com instead.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Offline h.pernpeintner

JGO Ninja


Medals: 106



« Reply #24 - Posted 2016-01-14 10:45:52 »

Sorry, haven't uploaded something for a long time. I changed the latest image to use imgur. Thanks.

@theagentd: Of course it's slow, it's voxel cone tracing Cheesy Sorry, can't give you timings right now, busy. I'm currently using a 256^3 grid, voxelizing sponza which has ~ 250k triangles, I think, the ferrari has a dozen thousend k triangles...I'm doing some post processing and using a custom deferred renderer. Getting frames per second around 35-40 or something on my GTX 770. No conservative rasterization of course, I don't think one would use this on a gpu slower than a gtx 970, because it's quite performance heavy.

If somewhen the time is given, I implement sparse voxelization with static/dynamic geometry. Long way to go, the current implementation should just give the java guys an impression of what could be done.
Offline h.pernpeintner

JGO Ninja


Medals: 106



« Reply #25 - Posted 2016-05-26 22:14:04 »

Finally had time to implement it more properly - can look pretty good

Offline orange451

JGO Kernel


Medals: 439
Projects: 7
Exp: 7 years


Your face? Your ass? What's the difference?


« Reply #26 - Posted 2016-05-26 22:15:59 »

Looks absolutely fantastic!

First Recon. A java made online first person shooter!
Offline Kefwar
« Reply #27 - Posted 2016-05-26 23:17:34 »

Looks awesome. Let the medal slam begin  Wink

Offline VaTTeRGeR
« Reply #28 - Posted 2016-05-27 08:59:59 »

HHNNNNNNNGNGGGGGG

what about the framerate? Grin
Offline h.pernpeintner

JGO Ninja


Medals: 106



« Reply #29 - Posted 2016-06-02 06:42:15 »

sorry, can't say much about it right now, because my gpu got busted and I haven't had time yet to buy a new pc - I'm currently working on my notebook with a geforce 730m, which is so sad...needless to say my framerate is not above 20.
Pages: [1] 2
  ignore  |  Print  
 
 

 
EgonOlsen (1850 views)
2018-06-10 19:43:48

EgonOlsen (1879 views)
2018-06-10 19:43:44

EgonOlsen (1245 views)
2018-06-10 19:43:20

DesertCoockie (1680 views)
2018-05-13 18:23:11

nelsongames (1345 views)
2018-04-24 18:15:36

nelsongames (1963 views)
2018-04-24 18:14:32

ivj94 (2736 views)
2018-03-24 14:47:39

ivj94 (1938 views)
2018-03-24 14:46:31

ivj94 (3029 views)
2018-03-24 14:43:53

Solater (1078 views)
2018-03-17 05:04:08
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!