Tutorial - Rendering A Shadow Map

Post Reply
DJ99X
Posts: 15523
Joined: Tue Jan 15, 2008 11:36 am
Location: Land Down Under

Tutorial - Rendering A Shadow Map

Post by DJ99X »

OK. As there is only a select few people on this forum that know how to render shadows, I thought I would make an attempt at a tutorial on how to render them. It can get a little tedious depending on how your track is set up. It is pretty simple if you have all of your object textures unsafed, and aren't using billboards (except JLV's billboards)

The overall process:

1) Download and install POVray

2) Once installed, set up a new resolution. Go Tools>Edit resolution INI file. Add this to the end of the file:

[2050, AA 0.3]
Width=2050
Height=2050
Antialias=On
Antialias_Threshold=0.3

If you are using a 2049 map, try this one (will take alot longer to render):

[4098, AA 0.3]
Width=4098
Height=4098
Antialias=On
Antialias_Threshold=0.3

You will need to restart the program to use it. Underneath the file/edit menu, set the render preset to [2050, AA 0.3]

3) Open your track in game, go into editor, and hit 'p' to export track.pov.

4) Take track.pov and terrain.png (copy this one) out of the folder. Put track.pov, terrain.png, a copy of your track folder, and this modified shadow.pov file into the same folder (make a new folder on the desktop if you want to). The purpose of having your track folder, is so that POVray can use your object textures. The textures need to be in the same directory as you have them in the statues file. So, if your texture is @tex1.png, you just need to have this in the same folder as the .pov files. If it is @texturefolder/tex2.png, you need to create a folder called texturefolder, and put the textures in this.

This is what you should have so far:

Image

5) Open shadow.pov file in POVray. There will be two lines with the following comments:

// PUT SUN CO-ORDINATE IN THE ARROW BRACKETS

// SCALE x (RESOLUTION - 1) = LENGTH & WIDTH ---> EG. 1.6 x (1025-1) = 1638.4

Follow these instructions. Save the file.

6) You should now be able to render the shadows. Have shadow.pov as the active window in POVray, and click the Run button (located underneath the help menu). After a few seconds, a message will pop up asking about I/O restrictions. Just click OK. You will probably get an error if something is missing. We will get to that later.

After a while, the shadow map will be rendered on screen. Once it is done, it will be saved as shadow.bmp

7) Open shadow.bmp in an image editing program. Resize it to the same size as your terrain.png image. Set it to grayscale, and save it as shadows.pgm (make sure you type in the .pgm part). Put it in your track folder, refresh the shading in game, and voila! Shadows. Make sure you save the track once you refresh. If the shadows seem too dark, make the image brighter in your image software.

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

If you got an error:
OK, so I'm gonna guess that you got an error message? This could be caused by one of the following reasons:
  • You are missing object textures
  • You have used billboards
If you are missing object textures because they are safed, there are a few options you can choose. If the object's texture doesn't have alpha, just make a dummy image, like a 1x1 black pixel. You can either give it the name of the missing file (and put it in the necessary folder), or just give it a random name, and replace the lines in track.pov to make them use this image. When you get the error message, it will highlight the missing texture. Say that you wanted to replace track/texture.png with dummy.png. Just go Search>Replace, and put the names into the necessary box. If you need to replace an image with a different format, ie blue.ppm with dummy.png, replace
ppm "blue.ppm"
with
png "dummy.png"

Save it once your done, and try running shadow.pov again.

_________________
The trickiest part of all, is if you need shadows for billboards. If you dont need shadows for billboards, just remove the billboards file before you export track.pov. But if you used billboard trees, this isn't really an option.

The easiest way to render shadows for billboard trees, is not really easy at all. We are going to convert the billboard to a 2 plane model.

You will need to backup your billboards and statues files. Then, you need to take all the billboard tree lines from the billboards file, and put them into the statues file.

A billboard line will be in the format:

[x y z] size aspectratio @trackname/texture.png

but for statues, it needs to be

[x y z] angle @trackname/model.jm @trackname/texture.png null

So, once the lines from the billboard file are in the statues file, just replace

size aspectratio @trackname/texture.png

with

angle @trackname/model.jm @trackname/texture.png null (set the angle to 0)

You will probably need a 2 plane model. Here are a few models at different sizes (the sizes should be similar to the size in the billboards file, ie if your billboard size is 60, use 2plane-60.jm). I've also included the blend file. It is currently on 6ft. Hit 's' to scale it, then go Object>Apply>Apply scale/rotation, then export.

http://www.mediafire.com/?hctvb56cxeob5hc

Once you have done this, save your statues file, delete your billboards file, export the track.pov file, then delete the statues file, and then put the backup statues and billboard files back in.

__________



Thats pretty much it. I think I have covered everything. There are other ways of avoiding the errors, but this is my way of doing things.

If you have any problems (non noobish problems hopefully), just post them here and I'll see if I can help.

Hopefully, people start attempting to render their own shadows instead of pestering me to do it :twisted:
yzmxer608
Posts: 15352
Joined: Mon Dec 29, 2008 4:30 am
Team: SYS
Location: Wisconsin, U.S.A

Re: Tutorial - Rendering A Shadow Map

Post by yzmxer608 »

Good tutorial DJ, hopefully more tracks will have them now. I did notice yesterday though, depending on the sun position and terrain file, you get big shadows on parts of the track. Can just edit them out if they look wierd, or replace the terrain.png with a flat one (probably 50% gray) so it doesn't render track shadows.
TeamHavocRacing wrote:If I had a nickel for every time someone asked for this, I would have a whole shitload of nickels.
haggqvist
Posts: 352
Joined: Sun Jan 31, 2010 11:44 am
Location: Sweden

Re: Tutorial - Rendering A Shadow Map

Post by haggqvist »

Have you tried the method of substituting billboards for statues on a track with lots of uneven ground?
I thought about using that method on sorketorp but decided against it for fear of the shadows getting visibly misplaced because of the right-angle-to-the-ground placement of statues.
Image
DJ99X
Posts: 15523
Joined: Tue Jan 15, 2008 11:36 am
Location: Land Down Under

Re: Tutorial - Rendering A Shadow Map

Post by DJ99X »

Oh, well in that case, you can set the angle to a number less than -2pi, and it will stand up right. This is a feature of the latest snapshot
haggqvist
Posts: 352
Joined: Sun Jan 31, 2010 11:44 am
Location: Sweden

Re: Tutorial - Rendering A Shadow Map

Post by haggqvist »

Thanks, I've completely missed that one, have to try that out.
Image
giopanda
Posts: 811
Joined: Sun Jul 05, 2009 8:08 am
Team: Privateer
Location: milano, italy
Contact:

Re: Tutorial - Rendering A Shadow Map

Post by giopanda »

i think every track maker was waiting for this tutorial!
now everything is easy as pie!
thanks dj
Image
DJ99X
Posts: 15523
Joined: Tue Jan 15, 2008 11:36 am
Location: Land Down Under

Re: Tutorial - Rendering A Shadow Map

Post by DJ99X »

I hope it is :lol:
giopanda
Posts: 811
Joined: Sun Jul 05, 2009 8:08 am
Team: Privateer
Location: milano, italy
Contact:

Re: Tutorial - Rendering A Shadow Map

Post by giopanda »

well it is for me..and i never been able to go past the missing startgate.ppm file!
now i have my shadows rendered in no time!
btw i found that is better to overlay the shadows bmp to the shadingx2 file, putting at multiply and changing from 45% to 55% depending on how they looks ingame.
shadows.pgm and and shadingx2.ppm doesn't get along very well in my 5 minutes experience..
Image
DJ99X
Posts: 15523
Joined: Tue Jan 15, 2008 11:36 am
Location: Land Down Under

Re: Tutorial - Rendering A Shadow Map

Post by DJ99X »

Yeah, thats what I did for Millville. But only because I had extra shadingx2 detail added by hand, which is removed if you need to bake the shadows in the editor
giopanda
Posts: 811
Joined: Sun Jul 05, 2009 8:08 am
Team: Privateer
Location: milano, italy
Contact:

Re: Tutorial - Rendering A Shadow Map

Post by giopanda »

DJ wrote:Yeah, thats what I did for Millville. But only because I had extra shadingx2 detail added by hand, which is removed if you need to bake the shadows in the editor
i did it for the same reason :wink:
Image
mace-x
Posts: 2303
Joined: Wed Jan 02, 2008 5:53 am
Team: your sister´s fan!
Location: candy planet.

Re: Tutorial - Rendering A Shadow Map

Post by mace-x »

hehe, gotta hate maths uh?
im here, what should i remplace this for in a 2049 map?

// SCALE x (RESOLUTION - 1) = LENGTH & WIDTH ---> EG. 1.6 x (1025-1) = 1638.4

thanks and sorry for the noobish question :lol:
Image
Massacre ftw!

the human stupidity and the universe are unlimited, and im not totally sure about the universe...
mace-x
Posts: 2303
Joined: Wed Jan 02, 2008 5:53 am
Team: your sister´s fan!
Location: candy planet.

Re: Tutorial - Rendering A Shadow Map

Post by mace-x »

ok, im not that stupid, the number was 3277.4

now i get this...
nvm, suddenly fixed? oh well, how do i know how long is going to take or how much it has done?
sorry for all the questions :lol:
Image
Massacre ftw!

the human stupidity and the universe are unlimited, and im not totally sure about the universe...
mace-x
Posts: 2303
Joined: Wed Jan 02, 2008 5:53 am
Team: your sister´s fan!
Location: candy planet.

Re: Tutorial - Rendering A Shadow Map

Post by mace-x »

dont read anything of the above ok'
i really need the edit post button goddamn!

had a problem :(

Code: Select all

Output Options
  Image resolution 4098 by 4098 (rows 1 to 4098, columns 1 to 4098).
  Output file: C:\Users\macex\Desktop\pov\shadow.bmp, 24 bpp (system format)
  Graphic display......On  (gamma: 2.2)
  Mosaic preview.......Off
  CPU usage histogram..Off
  Continued trace......Off
Tracing Options
  Quality:  9
  Bounding boxes.......On   Bounding threshold: 3
  Light Buffer.........On
  Vista Buffer.........On   Draw Vista Buffer....Off
  Antialiasing.........On
  AA Options: (Method 1, Threshold 0.300, Depth 3, Jitter 1.00, Unclipped)
  Clock value:    0.000  (Animation off)
File: track.pov  Line: 8454
File Context (5 lines):
		translate <1385.184570,5.167073,401.547852>
	}
	object {
		hillside_objects_kerb2
		texture { uv_mapping pigment { image_map { png "hillside\objects\kerb
Parse Error: Out of memory.  Cannot allocate 8192 bytes for PNG image line.
Total Scene Processing Times
  Parse Time:    0 hours  0 minutes  0 seconds (0 seconds)
  Photon Time:   0 hours  0 minutes  0 seconds (0 seconds)
  Render Time:   0 hours 17 minutes 48 seconds (1068 seconds)
  Total Time:    0 hours 17 minutes 48 seconds (1068 seconds)
CPU time used: kernel 83.05 seconds, user 303.28 seconds, total 386.34 seconds

POV-Ray finished
povray uses all my fricken memory untill runs out of it and almost makes all my comp crash, is there any way to limit how much memory does povray can use?
Image
Massacre ftw!

the human stupidity and the universe are unlimited, and im not totally sure about the universe...
mace-x
Posts: 2303
Joined: Wed Jan 02, 2008 5:53 am
Team: your sister´s fan!
Location: candy planet.

Re: Tutorial - Rendering A Shadow Map

Post by mace-x »

ok, i give up, fuck shadows!
tryed on an i5 460 with 4 ddr3 gb of ram and still getting out of memory, fuck this!
Image
Massacre ftw!

the human stupidity and the universe are unlimited, and im not totally sure about the universe...
DJ99X
Posts: 15523
Joined: Tue Jan 15, 2008 11:36 am
Location: Land Down Under

Re: Tutorial - Rendering A Shadow Map

Post by DJ99X »

Did you use my modified shadow.pov file?
Post Reply