* WalrusIRC

You need to have 5 posts and not be part of restricted usergroups in order to use the WalrusIRC embedded shoutbox. However, you can also access our IRC channel called #CodeWalrus via EFnet.

Author Topic: OpenGL ray tracer  (Read 2361 times)

0 Members and 1 Guest are viewing this topic.

Offline Snektron

  • Lvl 69 Russian Snake
  • Super User
  • Join Date: Dec 2014
  • Location: Netherlands
  • Posts: 3165
  • Post Rating Ratio: +32/-0
  • SSSssssss.....
    • RobinDeWalvis
    • Kzyrox
    • RobinDeWalvis
    • quantuminfinity
  • Gender: Male
OpenGL ray tracer
« on: April 13, 2016, 08:49:18 am »
This weekend i decided to try to make a ray tracer. It can render triangle meshes, loaded from wavefront obj files.
It works by having all triangles stored in a bounded volume hierarchy, so only a part of the mesh needs to be tested against
rays, instead of every triangle.



You can download it here:
http://quantuminfinity.space/files/RayTracer.jar

I highly recommend only running this if you have a modern GPU. It requires OpenGL 4.3 to run, and will eat a load of GPU processing power.
To run it, just double-click and everything should work fine (on most platforms). If you want to load your own wavefront object model, run
Code: [Select]
java -jar RayTracer.jar model.obj replace model.obj with the file name to load.
Make sure the object model has normals and is triangulated! (if you are unsure, open it in blender and export it with everything but triangulate and write normals disabled). Colors / textures etc are not supported.
It depends on the model and location, but most of the time i was able to achieve the 60 fps cap, though it gets a bit slower when the viewer is inside the object.
The default dragon has about 2000 faces and 1000 vertices, but i tried with a model with up to 24000 vertices too.

Im not really planning to release the source, but if you want you can decompile it :P
You can find the shader source in shaders/trace.csh when you open the jar as a zip file though.


  • Calculators owned: TI-84+
Legends say if you spam more than DJ Omnimaga, you will become a walrus...


Offline xlibman

  • Omni founder & CW co-founder
  • Super User
  • Original 5
  • CodeWalrus Supporter
  • *
  • Join Date: Nov 2014
  • Location: Quebec, Canada
  • Posts: 18909
  • Post Rating Ratio: +100/-5
    • dj_omnimaga
    • DJOmnimaga.music
    • @DJOmnimaga
    • dj_omnimaga
    • @DJOmnimaga
    • /u/DJ_Omnimaga
    • DJOmnimaga
    • 112/11286
    • @djomnimaga
    • @DJOmnimaga
    • DJ Omnimaga music store
  • Gender: Male
Re: OpenGL ray tracer
« Reply #1 on: April 13, 2016, 06:01:28 pm »
That looks great and I am surprised it ran somewhat fast despite being a ray tracer. I don't get 60 FPS but rather something around 15, but it was still cool.

What are the controls besides the mouse, though?
  • Calculators owned: TI-57, 73, TI-80 (broken), TI-81, TI-82, TI-83, TI-83+ (broken), TI-83+ (broken), TI-83+SE (broken), TI-84+, TI-84+CSE, TI-84+CE, TI-85, TI-86, TI-89T, TI-92, TI-Nspire, TI-Nspire CX (semi-broken), HP 39gII, HP Prime, Casio fx-7000G, fx-7400G+, fx-7700GE, fx-9750G+, fx-9750GII, fx-9860G, cfx-9850G, FX-1.0+, fx-CG10, fx-CP400
  • Consoles, mobile devices and vintage computers owned: Samsung i5510, Nexus 5, Atari 2600, Lynx, SMS, Game Gear, Genesis, Dreamcast, NES, SNES, N64, GCN, Wii, Wii U, GBA, DS, 3DS, PS2, PS3, PS4, PSP, PSVita, XBox 360, XBOne

Bandcamp|Reverbnation|Facebook|Youtube|Twitter
Retired Omnimaga admin (2001-11) and editor (2012-14)

Offline Snektron

  • Lvl 69 Russian Snake
  • Super User
  • Join Date: Dec 2014
  • Location: Netherlands
  • Posts: 3165
  • Post Rating Ratio: +32/-0
  • SSSssssss.....
    • RobinDeWalvis
    • Kzyrox
    • RobinDeWalvis
    • quantuminfinity
  • Gender: Male
Re: OpenGL ray tracer
« Reply #2 on: April 13, 2016, 06:32:18 pm »
WASD, space and shift to fly around. YTou can use control to get a speed boost.
  • Calculators owned: TI-84+
Legends say if you spam more than DJ Omnimaga, you will become a walrus...


Offline xlibman

  • Omni founder & CW co-founder
  • Super User
  • Original 5
  • CodeWalrus Supporter
  • *
  • Join Date: Nov 2014
  • Location: Quebec, Canada
  • Posts: 18909
  • Post Rating Ratio: +100/-5
    • dj_omnimaga
    • DJOmnimaga.music
    • @DJOmnimaga
    • dj_omnimaga
    • @DJOmnimaga
    • /u/DJ_Omnimaga
    • DJOmnimaga
    • 112/11286
    • @djomnimaga
    • @DJOmnimaga
    • DJ Omnimaga music store
  • Gender: Male
Re: OpenGL ray tracer
« Reply #3 on: April 13, 2016, 06:43:56 pm »
Thanks. At first I was gonna reply that the keys do nothing, until I realized we have to hold the mouse button down while pressing them. :P
  • Calculators owned: TI-57, 73, TI-80 (broken), TI-81, TI-82, TI-83, TI-83+ (broken), TI-83+ (broken), TI-83+SE (broken), TI-84+, TI-84+CSE, TI-84+CE, TI-85, TI-86, TI-89T, TI-92, TI-Nspire, TI-Nspire CX (semi-broken), HP 39gII, HP Prime, Casio fx-7000G, fx-7400G+, fx-7700GE, fx-9750G+, fx-9750GII, fx-9860G, cfx-9850G, FX-1.0+, fx-CG10, fx-CP400
  • Consoles, mobile devices and vintage computers owned: Samsung i5510, Nexus 5, Atari 2600, Lynx, SMS, Game Gear, Genesis, Dreamcast, NES, SNES, N64, GCN, Wii, Wii U, GBA, DS, 3DS, PS2, PS3, PS4, PSP, PSVita, XBox 360, XBOne

Bandcamp|Reverbnation|Facebook|Youtube|Twitter
Retired Omnimaga admin (2001-11) and editor (2012-14)

Offline Jkolade936

  • All Around Coolio
  • Super User
  • Join Date: Jan 2016
  • Location: Horseheads, NY
  • Posts: 1515
  • Post Rating Ratio: +9/-1
  • I'm an unknown loner. I try to change that.
    • Jkolade936
    • My Sprites and Walrii Collection
  • Gender: Male
Re: OpenGL ray tracer
« Reply #4 on: April 13, 2016, 07:41:52 pm »
That's cool!
That dragon's really neat. :)
  • Calculators owned: None of them. :'(
Does this qualify as a signature? 
The answer is "Sure."


Offline ben_g

  • Full User
  • Safe-haven access
  • Join Date: Dec 2014
  • Location:
  • Posts: 167
  • Post Rating Ratio: +12/-0
Re: OpenGL ray tracer
« Reply #5 on: April 15, 2016, 04:07:32 am »
It works by having all triangles stored in a bounded volume hierarchy, so only a part of the mesh needs to be tested against
rays, instead of every triangle.
So is it doing the kind of ray tracing that most engines use for collision and hit detection for every pixel to render the model?
Since it probably does almost all calculations per-pixel, does that mean that it can render insanely high-poly models with barely any slowdown?

It's a cool project, though it unfortunately doesn't seem to run on my laptop (since the 'run with powerfull graphics processor' option doesn't appear on .jar files, it's probably running on the on-board GPU, which is probably the cause).

Offline xlibman

  • Omni founder & CW co-founder
  • Super User
  • Original 5
  • CodeWalrus Supporter
  • *
  • Join Date: Nov 2014
  • Location: Quebec, Canada
  • Posts: 18909
  • Post Rating Ratio: +100/-5
    • dj_omnimaga
    • DJOmnimaga.music
    • @DJOmnimaga
    • dj_omnimaga
    • @DJOmnimaga
    • /u/DJ_Omnimaga
    • DJOmnimaga
    • 112/11286
    • @djomnimaga
    • @DJOmnimaga
    • DJ Omnimaga music store
  • Gender: Male
Re: OpenGL ray tracer
« Reply #6 on: April 15, 2016, 04:17:03 am »
I am curious personally about if this could be used to draw maps? Also raytracing is starting being used in game experiments such as Quake Wars: Raytraced. I am curious about when computers will be powerful enough to run high-quality raytracing at 60 FPS...
  • Calculators owned: TI-57, 73, TI-80 (broken), TI-81, TI-82, TI-83, TI-83+ (broken), TI-83+ (broken), TI-83+SE (broken), TI-84+, TI-84+CSE, TI-84+CE, TI-85, TI-86, TI-89T, TI-92, TI-Nspire, TI-Nspire CX (semi-broken), HP 39gII, HP Prime, Casio fx-7000G, fx-7400G+, fx-7700GE, fx-9750G+, fx-9750GII, fx-9860G, cfx-9850G, FX-1.0+, fx-CG10, fx-CP400
  • Consoles, mobile devices and vintage computers owned: Samsung i5510, Nexus 5, Atari 2600, Lynx, SMS, Game Gear, Genesis, Dreamcast, NES, SNES, N64, GCN, Wii, Wii U, GBA, DS, 3DS, PS2, PS3, PS4, PSP, PSVita, XBox 360, XBOne

Bandcamp|Reverbnation|Facebook|Youtube|Twitter
Retired Omnimaga admin (2001-11) and editor (2012-14)

Offline Snektron

  • Lvl 69 Russian Snake
  • Super User
  • Join Date: Dec 2014
  • Location: Netherlands
  • Posts: 3165
  • Post Rating Ratio: +32/-0
  • SSSssssss.....
    • RobinDeWalvis
    • Kzyrox
    • RobinDeWalvis
    • quantuminfinity
  • Gender: Male
Re: OpenGL ray tracer
« Reply #7 on: April 15, 2016, 08:37:51 am »
It works by having all triangles stored in a bounded volume hierarchy, so only a part of the mesh needs to be tested against
rays, instead of every triangle.
So is it doing the kind of ray tracing that most engines use for collision and hit detection for every pixel to render the model?
Since it probably does almost all calculations per-pixel, does that mean that it can render insanely high-poly models with barely any slowdown?

It's a cool project, though it unfortunately doesn't seem to run on my laptop (since the 'run with powerfull graphics processor' option doesn't appear on .jar files, it's probably running on the on-board GPU, which is probably the cause).

I don't know what most engines use, but my tracer uses a BVH tree for storage. And sadly its not entirely true that it takes almost no power to render. It takes very little time to calculate find a node that intersects with the ray, but you ofcourse have to traverse all children of the tree until you are sure it doesn't hit anything, which makes it take a little more time.

It should use your primary GPU, i have an internal one too and it doesn't use that... If you get an error message you can post it in pastebin and i can see what you can do.
I should actually implements some capabilities checks since it needs OpenGL 4.3 ( if you get an exception with the message "shader = 0" then your opengl version is not high enough since it can't create the compute shader)

I am curious personally about if this could be used to draw maps? Also raytracing is starting being used in game experiments such as Quake Wars: Raytraced. I am curious about when computers will be powerful enough to run high-quality raytracing at 60 FPS...

That's what i'm trying to find out too. There was Brigade engine too which could be used to make entirely raytraced games, but idk if it still exists. I do hear everywhere that raytracing is the future of game engines, since the traditional rasterizing is a cheat method...
« Last Edit: April 15, 2016, 08:39:46 am by Cumred_Snektron »
  • Calculators owned: TI-84+
Legends say if you spam more than DJ Omnimaga, you will become a walrus...


Offline ben_g

  • Full User
  • Safe-haven access
  • Join Date: Dec 2014
  • Location:
  • Posts: 167
  • Post Rating Ratio: +12/-0
Re: OpenGL ray tracer
« Reply #8 on: April 15, 2016, 09:18:12 am »
It just opens a window and closes it again, without any error message.

Also this is a laptop, so the on-board and dedicated GPU are in an 'optimus' configuration, and the on-board GPU always renders the desktop and non graphically-heavy programs, while programs that it recougnizes as needing extra GPU power should use the dedicated GPU instead, though this detection doesn't work well most of the time.

Offline Snektron

  • Lvl 69 Russian Snake
  • Super User
  • Join Date: Dec 2014
  • Location: Netherlands
  • Posts: 3165
  • Post Rating Ratio: +32/-0
  • SSSssssss.....
    • RobinDeWalvis
    • Kzyrox
    • RobinDeWalvis
    • quantuminfinity
  • Gender: Male
Re: OpenGL ray tracer
« Reply #9 on: April 15, 2016, 10:19:23 am »
Have you tried to run it from the commandline?
Code: [Select]
java -jar RayTracer.jar
  • Calculators owned: TI-84+
Legends say if you spam more than DJ Omnimaga, you will become a walrus...


Offline xlibman

  • Omni founder & CW co-founder
  • Super User
  • Original 5
  • CodeWalrus Supporter
  • *
  • Join Date: Nov 2014
  • Location: Quebec, Canada
  • Posts: 18909
  • Post Rating Ratio: +100/-5
    • dj_omnimaga
    • DJOmnimaga.music
    • @DJOmnimaga
    • dj_omnimaga
    • @DJOmnimaga
    • /u/DJ_Omnimaga
    • DJOmnimaga
    • 112/11286
    • @djomnimaga
    • @DJOmnimaga
    • DJ Omnimaga music store
  • Gender: Male
Re: OpenGL ray tracer
« Reply #10 on: April 15, 2016, 04:01:43 pm »
@Cumred_Snektron have you checked http://www.archive.org for Brigade?
  • Calculators owned: TI-57, 73, TI-80 (broken), TI-81, TI-82, TI-83, TI-83+ (broken), TI-83+ (broken), TI-83+SE (broken), TI-84+, TI-84+CSE, TI-84+CE, TI-85, TI-86, TI-89T, TI-92, TI-Nspire, TI-Nspire CX (semi-broken), HP 39gII, HP Prime, Casio fx-7000G, fx-7400G+, fx-7700GE, fx-9750G+, fx-9750GII, fx-9860G, cfx-9850G, FX-1.0+, fx-CG10, fx-CP400
  • Consoles, mobile devices and vintage computers owned: Samsung i5510, Nexus 5, Atari 2600, Lynx, SMS, Game Gear, Genesis, Dreamcast, NES, SNES, N64, GCN, Wii, Wii U, GBA, DS, 3DS, PS2, PS3, PS4, PSP, PSVita, XBox 360, XBOne

Bandcamp|Reverbnation|Facebook|Youtube|Twitter
Retired Omnimaga admin (2001-11) and editor (2012-14)

Offline ben_g

  • Full User
  • Safe-haven access
  • Join Date: Dec 2014
  • Location:
  • Posts: 167
  • Post Rating Ratio: +12/-0
Re: OpenGL ray tracer
« Reply #11 on: April 17, 2016, 03:07:13 am »
Have you tried to run it from the commandline?
Code: [Select]
java -jar RayTracer.jar
When just running it from the command prompt:
(click to show/hide)

But it works when I run the command prompt with the dedicated GPU and then start it from there.

Offline Snektron

  • Lvl 69 Russian Snake
  • Super User
  • Join Date: Dec 2014
  • Location: Netherlands
  • Posts: 3165
  • Post Rating Ratio: +32/-0
  • SSSssssss.....
    • RobinDeWalvis
    • Kzyrox
    • RobinDeWalvis
    • quantuminfinity
  • Gender: Male
Re: OpenGL ray tracer
« Reply #12 on: April 17, 2016, 08:40:30 am »
It looks like the integrated gpu does not support OpenGL 4.4, and i don't think Java programs get recognized as gpu intensive games by your system...
  • Calculators owned: TI-84+
Legends say if you spam more than DJ Omnimaga, you will become a walrus...


Offline xlibman

  • Omni founder & CW co-founder
  • Super User
  • Original 5
  • CodeWalrus Supporter
  • *
  • Join Date: Nov 2014
  • Location: Quebec, Canada
  • Posts: 18909
  • Post Rating Ratio: +100/-5
    • dj_omnimaga
    • DJOmnimaga.music
    • @DJOmnimaga
    • dj_omnimaga
    • @DJOmnimaga
    • /u/DJ_Omnimaga
    • DJOmnimaga
    • 112/11286
    • @djomnimaga
    • @DJOmnimaga
    • DJ Omnimaga music store
  • Gender: Male
Re: OpenGL ray tracer
« Reply #13 on: April 17, 2016, 09:57:17 pm »
WOuld there be a way to make this with an older OpenGL version that can run on a larger amount of computers?
  • Calculators owned: TI-57, 73, TI-80 (broken), TI-81, TI-82, TI-83, TI-83+ (broken), TI-83+ (broken), TI-83+SE (broken), TI-84+, TI-84+CSE, TI-84+CE, TI-85, TI-86, TI-89T, TI-92, TI-Nspire, TI-Nspire CX (semi-broken), HP 39gII, HP Prime, Casio fx-7000G, fx-7400G+, fx-7700GE, fx-9750G+, fx-9750GII, fx-9860G, cfx-9850G, FX-1.0+, fx-CG10, fx-CP400
  • Consoles, mobile devices and vintage computers owned: Samsung i5510, Nexus 5, Atari 2600, Lynx, SMS, Game Gear, Genesis, Dreamcast, NES, SNES, N64, GCN, Wii, Wii U, GBA, DS, 3DS, PS2, PS3, PS4, PSP, PSVita, XBox 360, XBOne

Bandcamp|Reverbnation|Facebook|Youtube|Twitter
Retired Omnimaga admin (2001-11) and editor (2012-14)

Offline Snektron

  • Lvl 69 Russian Snake
  • Super User
  • Join Date: Dec 2014
  • Location: Netherlands
  • Posts: 3165
  • Post Rating Ratio: +32/-0
  • SSSssssss.....
    • RobinDeWalvis
    • Kzyrox
    • RobinDeWalvis
    • quantuminfinity
  • Gender: Male
Re: OpenGL ray tracer
« Reply #14 on: April 18, 2016, 09:23:35 am »
I can replace some of the functionality, like the shader storage buffer objects (which were introduced in GL 4.4) with ordinary textures and the compute shader with a fragment shader (which appearantly would be a little slower),  allowing it to run on basically any hardware that supports OpenGL 2.0, but this is more a proof of concept program. I am actually plkanning on trying out if i can achieve this effect in Unreal Engine, which would allow it to run on anything that supports OpenGL ES 2 or DirectX 9 (i think).
  • Calculators owned: TI-84+
Legends say if you spam more than DJ Omnimaga, you will become a walrus...


 


You can also use the following HTML or bulletin board code to share it on your page or forum signature!


Also do not forget to check our affiliates below.
Planet Casio TI-Planet Calc.news BroniesQC BosaikNet Velocity Games