You can help CodeWalrus stay online by donating here. | New CodeWalrus | Old (dark mode) | Old (light) | Discord server

[Java] OpenGL ray tracer

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

0
b/PC, Mac & Vintage Computers publicado por u/Snektron 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
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.
Inicia sesión o crea una cuenta para dejar un comentario
u/Dream of Omnimaga 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?
u/Snektron April 13, 2016, 06:32:18 PM
WASD, space and shift to fly around. YTou can use control to get a speed boost.
u/Dream of Omnimaga 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
u/Dudeman313 April 13, 2016, 07:41:52 PM
That's cool!
That dragon's really neat. :)
u/ben_g April 15, 2016, 04:07:32 AM
Quote from: Cumred_Snektron on April 13, 2016, 08:49:18 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).
u/Dream of Omnimaga 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...
u/Snektron April 15, 2016, 08:37:51 AM
Quote from: ben_g on April 15, 2016, 04:07:32 AM
Quote from: Cumred_Snektron on April 13, 2016, 08:49:18 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)

Quote from: DJ Omnimaga 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...

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
u/ben_g 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.
u/Snektron April 15, 2016, 10:19:23 AM
Have you tried to run it from the commandline?

java -jar RayTracer.jar
u/Dream of Omnimaga April 15, 2016, 04:01:43 PM
@Cumred_Snektron have you checked http://www.archive.org for Brigade?
u/ben_g April 17, 2016, 03:07:13 AM
Quote from: Cumred_Snektron on April 15, 2016, 10:19:23 AM
Have you tried to run it from the commandline?

java -jar RayTracer.jar

When just running it from the command prompt:
error log

Unimplemented element: s
Size:
        Shapes (4179): 200592.0 bytes
        Triangles (2090): 66880.0 bytes
        Vertices (1017): 16272.0 bytes
        Total: 283744.0 bytes
Max depth: 13
java.lang.IllegalStateException: This functionality is not available.
        at org.lwjgl.system.Checks.checkFunctionality(Checks.java:57)
        at org.lwjgl.opengl.GL44.getInstance(GL44.java:137)
        at org.lwjgl.opengl.GL44.getInstance(GL44.java:132)
        at org.lwjgl.opengl.GL44.nglBindBuffersBase(GL44.java:363)
        at org.lwjgl.opengl.GL44.glBindBuffersBase(GL44.java:397)
        at net.quantuminfinity.engine.gl.shader.compute.ShaderStorageBuffer.bind(ShaderStorageBuffer.java:38)
        at net.quantuminfinity.bvh.CSTracer.render(CSTracer.java:54)
        at net.quantuminfinity.bvh.BVH.onRender(BVH.java:71)
        at net.quantuminfinity.engine.Engine.render(Engine.java:127)
        at net.quantuminfinity.engine.Engine.loop(Engine.java:90)
        at net.quantuminfinity.engine.Engine.start(Engine.java:65)
        at net.quantuminfinity.bvh.BVH.main(BVH.java:87)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)

But it works when I run the command prompt with the dedicated GPU and then start it from there.
u/Snektron 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...
u/Dream of Omnimaga 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?
u/Snektron 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).
Start a Discussion

b/PC, Mac & Vintage Computers

Computer programming discussion and project showcase

132
Topics
Explore Board
Website statistics


MyCalcs | Ticalc.org | Cemetech | Omnimaga | TI-Basic Developer | MaxCoderz | TI-Story | Casiocalc.org | Casiopeia | The Museum of HP Calculators | HPCalc.org | CnCalc.org | Music 2000 Community | TI Education | Casio Education | HP Calcs | NumWorks | SwissMicros | Sharp Calculators
Powered by EzPortal