Math Is Fun Forum

  Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °

You are not logged in.

#1 2006-05-26 06:07:26

luca-deltodesco
Member
Registered: 2006-05-05
Posts: 1,470

ray-traced heightmap terrain with simple shading and texturing

ive know finished and tested out my algorithm for intersecting a ray with a heightmapped terrain

(check image, heightmap and texture shown at top, the rendering is blurred slightly to make it look nicer)

i havnt tested with shadow rays, so its a little bit difficult to properly pick out the shape of the terrain

. anyways

in the rendering the heightmap is 512*512
and instead of intersecting with 522242 (2*511*511) triangles, which would be INCREDIBLY slow, i use an algorithm that does this

first it finds the first intersection with the bounding cuboid, (if the ray origin is inside, that is used)
and then it finds the first intersection with the grid (by checking the next vertical,horizontal line and getting the closest)
from there it finds the amount needed to get to the next vertical and horizontal intersection, but instead of just going through the horizontals, through the verticals, it just always moves to the next nearest grid intersection

with the two intersections (or not intersections) it checks the two triangles underneath for an intersection using a ray plane intersection, and then checking the intersections coordinates to determine if its on the triangles projection.

the normals for the triangles are calculated in realtime, but the normals used for shading are precalculated in a normal map storing the average vertex normals which i made another tool for in my ray tracing package to be. from the intersection, it gets the 4 surrounding vertex normals, and then interpolates to the intersection given a smooth shading

im now going to try and package it into a function, and then add shadow rays.

the current texturing is just a single tiled texturing, but ive also developed another method where you would have an image like the second one below, where the two regions of each r,g,b channels corresponds to a percentage of one of six textures which are combined at the point which can be VERY useful, since you can just draw a colour map like the one below, quickly edited, and then you can just change the textures, and their tiling on the fly without editing the colour map, and like this you can get quality texturing with a map the same size as the heightmap, whereas having a complex single texture, youd need to have one atleast 10x bigger to get quality texturing, but thats for later


do you think i should also make it so that you can use another special normal map (which would be twice the size of the heightmap) to store the normal triangle normals for intersections? (i.e. increase rendering speed, but with a file size gain, which is the same for this other special normal map im using, which im going to have as optional)



------------


edit:

i rendered another one, same camera angle and everything using a sand texture, now you can really see the shape of the terrain, even without shadowing

Last edited by luca-deltodesco (2006-05-26 10:37:07)


The Beginning Of All Things To End.
The End Of All Things To Come.

Offline

#2 2006-05-26 12:28:19

MathsIsFun
Administrator
Registered: 2005-01-21
Posts: 7,711

Re: ray-traced heightmap terrain with simple shading and texturing

It is really worth the effort when you get results like that!

The sand one does show up the terrain well. I wonder if you could make it look like forested mountains?

luca-deltodesco wrote:

do you think i should also make it so that you can use another special normal map (which would be twice the size of the heightmap) to store the normal triangle normals for intersections? (i.e. increase rendering speed, but with a file size gain, which is the same for this other special normal map im using, which im going to have as optional)

Sure - file size is not really a problem, but rendering speed is (generally speaking). If you can load these into memory and speed it all up, all the better. I think some software even adopts a flexible approach, by letting the user configure how much memory to allow for temporary storage.


"The physicists defer only to mathematicians, and the mathematicians defer only to God ..."  - Leon M. Lederman

Offline

#3 2006-05-26 18:29:50

luca-deltodesco
Member
Registered: 2006-05-05
Posts: 1,470

Re: ray-traced heightmap terrain with simple shading and texturing

MathsIsFun wrote:

I think some software even adopts a flexible approach, by letting the user configure how much memory to allow for temporary storage.

yes i was just thinking about that. although i dont know if i would have a memory usage limit

rather, i would have different options for the primitaves, like for the heightmap for example, an option to say if calculated data that is reused, can be stored in memory, or should be recalculated.


anyways, my aim at the moment with the terrain is to be able to get my texturing method tested out on it, and then encapsulate it all, so i can add shadow rays and then test it with a water quad using normal mapped ripples reflecting the terrain tongue and then possibly have it refracting water into it aswell if i feel like it tongue but i might leave that till later since i still havnt got a proper method of refracting between surfaces yet


MathIsFun wrote:

I wonder if you could make it look like forested mountains?

well actually you could, you could either do it cheating, or realastic

obviously if the rendering is from close quarters, you would actually need to have a model of different trees copied around, which would be quite a slow rendering with all the triangles (or using primitaves, you could make it out of cones and cylinders and some polygons for leaves)

but if it was from far away, like a massive lake rendering, and you have trees on the far side, you could just edit the heightmap to the shape of the top of the trees, and edit the texture

one thing i need to learn, is the 3dsmax file format for its exported models so that i can have them loaded into the ray tracer


-------------------


ive made another two renderings, again with grass, with sand of a different terrain

Last edited by luca-deltodesco (2006-05-26 19:52:38)


The Beginning Of All Things To End.
The End Of All Things To Come.

Offline

#4 2006-05-27 04:17:29

John E. Franklin
Member
Registered: 2005-08-29
Posts: 3,588

Re: ray-traced heightmap terrain with simple shading and texturing

You should see Topo USA 6.0 by Delorme mapping software in Maine, USA.
I have it and it does this kind of stuff.  They might be happy to hear from you and see your work?
I like your green ones better than the sand ones, I can see more detail somehow, weird how the brain
can take a 2-D image mangled up and get the idea of 3-D without two eyes, just one monitor.


igloo myrtilles fourmis

Offline

#5 2006-05-27 11:32:49

MathsIsFun
Administrator
Registered: 2005-01-21
Posts: 7,711

Re: ray-traced heightmap terrain with simple shading and texturing

Good Idea John. And if Delorme aren't interested, maybe some competitors would be ... smile


"The physicists defer only to mathematicians, and the mathematicians defer only to God ..."  - Leon M. Lederman

Offline

#6 2006-05-27 18:14:16

luca-deltodesco
Member
Registered: 2006-05-05
Posts: 1,470

Re: ray-traced heightmap terrain with simple shading and texturing

the thing is, this is ray traced and is a slow process, wheras looking at the topo thing, it needs to be in real time, so no ray tracing


The Beginning Of All Things To End.
The End Of All Things To Come.

Offline

Board footer

Powered by FluxBB