LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-28-2011, 04:06 PM   #16
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948

Here's an example of the shadowing mechanism I wrote about early in this thread.

Extract and compile the attachment using
Code:
tar -xzvf shadow.tar.gz.txt
cd shadow/
make
The example program creates a 510x510 grayscale PGM file test.pgm. Check out the example I attached.

The visibility() function in shadow.h can create a visibility map up to 255 tiles away from the origin. The origin must be within the map. Usage:
Code:
visibility(width, height, origin_x, origin_y,
result_map, result_x_stride, result_y_stride,
obstacle_map, obstacle_x_stride, obstacle_y_stride);
The _x_stride parameters define the size of each tile, and _y_stride parameters define the size of each row of tiles.

obstacle_map defines the opacity of the obstacles, 0 for totally transparent, 255 for totally opaque. This map is only read, never modified.

The resulting visibility map is saved in result_map, where 255 indicates fully visible and 0 indicates hidden.

Note that the weights in shadow.h are not truly accurate; visibility is not uniform in all directions. This is not too difficult to fix; I just didn't bother since I don't actually need this for anything myself. (I used a quick script to calculate the weights.)

The key feature in this method is speed. Running time of the visibility() function depends only on the size of the map (i.e. it is O(width×height)), not on the number or type of the obstacles in it. On my machine, visibility() takes about 80 clock cycles per tile, or about 20 million clock cycles for the 510x510 tile map in the example program. Optimizing the arrays for each specific use case would make it even faster.

Note that this same function can be used to implement point lights: allocate a temporary light map, apply visibility() to the obstacles around the light, saving the result to the temporary light map, then sum (with clamping) the temporary light map to the overall light map. Although the current weights do not have distance attenuation, another weight table can be easily created for each light type; with a bit of code tweaking, you could even do directional lights.
Attached Thumbnails
Click image for larger version

Name:	shadow.png
Views:	14
Size:	45.8 KB
ID:	6568  
Attached Files
File Type: txt shadow.tar.gz.txt (165.3 KB, 7 views)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Eye of Gnome Image View taking 100% CPU and tripping my thermal sensor MikeyCarter Linux - Software 5 04-28-2008 09:03 AM
LXer: A hacker's-eye view of Nokia's N800 Internet Tablet LXer Syndicated Linux News 0 02-07-2007 05:03 AM
LXer: Linux Distributions Bird's Eye View - a Mind Map LXer Syndicated Linux News 0 04-13-2006 10:33 PM
Non root user to View \etc\shadow dhammika Linux - Security 3 04-05-2006 10:06 PM
LXer: Browser developers meet, see eye to eye on security LXer Syndicated Linux News 0 12-26-2005 02:31 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration