Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  ( almost :) ) Realtime Java Raytracing  (Read 1884 times)
0 Members and 1 Guest are viewing this topic.
Offline JuMisMa

Senior Newbie


Medals: 1



« Posted 2013-07-12 18:44:35 »

Hy everyone.

First, please sorry for my poor english but i’m french.

Here is my first raytracer in java. With low parameters, i’m close to realtime. On my computer - core
i5 2500K 4 cores at 4.2ghz - the demo’s scene - 17762 triangles - is about 3 fps with a screen at 600x400.
With higher parameters (anti-alliasing, smooth shadows, higher recursion), it can be very, very slow.

You can configure the raytracer with the « Param.txt » configuration file in "_Param" directory. All the
parameters are explained and easy to understand.

Some coding tips :

KDTREE:
I’m using 2 kdtree for this demo.
- 1 for static objects that use SAH optimisation.
- 1 for dynamic objects, that must be rebuilt on each frame, with middle splitting axe. With « symetric »
objects, it’s not very much slower than SAH.

The KDTree build is multithreaded. At level 2, 4 threads are created. After, for the SAH version only,
if there are enough faces, 3 threads are created, one for each plane to check.

I use another optimization : as the triangles coordinate are sorted on the current axe, we don’t just use
left and right child, but i introduce a middle child, that was copied to the right child.

ANTI-ALIASING:
When turn on, the rendering is made twice :
- The standart one
- One the second pass, each pixel is compared to the 4 around. A delta is computed. If this delta
is higher the a value (AA_DELTA_COLOR in parameter’s file) then AA_LEVEL rays are fired.

SMOOTH SHADOW:
For smooth shadow, i’m using a poisson distribution on light area (each light have is own rectangular
area) to avoid banding.


I’m a developper, not a graphist, so sorry for the demo’s scene that I know to be awful. All the
algorithms used come from the web. I’m just tried to use the best. I'm not a great programmer, as
i can see in this forum, so, please, be gentle with me and thank’s for reading my code and give
me you’re feedback and what can be improved. In particular, the normal mapping part, that i'm pretty
sure to be false. The most important classes are RT_SCENE.java and RT_KDTREE.java

Java 7 is required (i think)

Thank'you.
Fred

The executable jar
The eclipse jar (kepler)


Offline matheus23

JGO Kernel


Medals: 106
Projects: 3


You think about my Avatar right now!


« Reply #1 - Posted 2013-07-12 21:23:30 »

Well... yeah. Almost Cheesy

Get 1 FPS when minimized and with the lowest settings.

4 cores, 8 threads, 3.3 GHz.

Each frame takes about 10 seconds, when I turn on antialiasing and especially when I turn on smooth shadows. Looks really, really nice tho, and runs fast for what it shows!

Keep it up!

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline HeroesGraveDev

JGO Kernel


Medals: 238
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #2 - Posted 2013-07-12 22:52:24 »

Shocked

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ra4king

JGO Kernel


Medals: 339
Projects: 2
Exp: 5 years


I'm the King!


« Reply #3 - Posted 2013-07-12 23:21:41 »

i7 2600K @ 4.5GHz: 3 FPS \o/

Offline relminator
« Reply #4 - Posted 2013-07-13 05:57:40 »

Might not be useful in games but it looks darn beautiful!
Offline kpars

JGO Wizard


Medals: 75
Projects: 4
Exp: 3 years


Radirius Software Developer


« Reply #5 - Posted 2013-07-13 17:07:46 »

I just tried it.
I win with 4 FPS! Looks great  Grin

Check out #JGO on EsperNet IRC! | Check out the MERCury 2D Java Game Library! | Also, Check out My Site
Offline moogie

JGO Knight


Medals: 12
Projects: 6
Exp: 10 years


Java games rock!


« Reply #6 - Posted 2013-07-14 10:26:19 »

good work! back in the day I attempted to make a real time ray tracer for a java4k competition... I did get it to fit in 4k... but with no room for game play Tongue

I did have an interesting ( and to my knowledge novel ) idea for ray triangle intersection test which may be quite fast... i never did follow it up, but if you want i can outline the algorithm to see if it gives any speed improvements.

Oh I found a version of that realtime raytracer: (well before i started shrinking it Tongue )
[applet archive=jrtrtapplet.jar class=org.moogiesoft.JRTRT.TestApplet width=800 height=600]
Up/down arrow = thrust
left / rigth = roll
Mouse drag = move mouse view.

(Not sure why the Embeded applet tag is not working Sad )
Offline JuMisMa

Senior Newbie


Medals: 1



« Reply #7 - Posted 2013-07-14 18:14:35 »

Thank's.

I'm using barycentric coordinates algo for ray-triangles intersections from :

http://www.flipcode.com/archives/Raytracing_Topics_Techniques-Part_7_Kd-Trees_and_More_Speed.shtml
Offline moogie

JGO Knight


Medals: 12
Projects: 6
Exp: 10 years


Java games rock!


« Reply #8 - Posted 2013-07-15 01:40:09 »

Hehe, that site looks familiar Smiley I think i have used it in the past.

The ray/triangle intersection method that I had though up is to replace the barycentric coordinates conversion and subsequent tests with three simple distance tests.

The main thought is to approximate the triangle vertices as arcs on large radius circles: as the radius of a circle gets larger, an arc of of that circle of a fixed length starts to look like a straight line.

So to perform a ray-triangle intersection test:
1. calculate the intersection with the plane of the triangle
2. test to see whether the origin-intersection distance is less than the radius. If greater then stop as it does not intersect the triangle.
3. repeat 2 for remaining vertices.
4. ray does intersect the triangle.

Of course to speed up this algorithm i was planning to precompute and store the origins for each of the circles with the triangle and to only compare the squared distances (i.e. no square roots necessary)

To calculate the origins for each of the circles:
-take the 2D normal of a triangle vertex and project inward from the mid point of the vertex by a sufficiently large radius.
-for optimisation, the radius would be a constant and used for all triangles.

This algorithm is not limited to just triangles, any convex polygon can be represented by simply increasing the vertices checks.

There is a potential bonus property of this method, it should reduce the visibility of seams between triangles in a mesh as the triangles will be slightly bulging.

However this method may have some strange effects due to floating point precision between large and small numbers.

I never implemented it so if you do I would love to hear if it works and if it provides any speed boost.
Offline moogie

JGO Knight


Medals: 12
Projects: 6
Exp: 10 years


Java games rock!


« Reply #9 - Posted 2013-07-15 01:55:59 »

Infact I was going to use a modified version of this algorithm for the java 4k real time ray tracer. To help save code size I was was only going replace the ray-plane intersection test with a ray-sphere intersection test. In the same way as a arc of a large circle can approximate a vertex, a large radius sphere can approximate a polygon face.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline moogie

JGO Knight


Medals: 12
Projects: 6
Exp: 10 years


Java games rock!


« Reply #10 - Posted 2013-07-15 23:45:48 »

I just had a thought: it is probable that you can skip calculating step the mid point of a vertex: given sufficiently large radius, and arc will approximate a straight line and thus the difference in distance between a triangle vertex of an edge and the origin as compared to the mid point of the edge to the origin will be minuscule.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Riven (18 views)
2014-07-29 18:09:19

Riven (13 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (31 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (42 views)
2014-07-24 01:59:36

Riven (41 views)
2014-07-23 21:16:32

Riven (28 views)
2014-07-23 21:07:15

Riven (29 views)
2014-07-23 20:56:16

ctomni231 (60 views)
2014-07-18 06:55:21
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!