I'm working on a big script including lots of advanced lighting algorithms for a RPGVX lighting engine. Of course you have 2 major problems with VX: -it's very abstract and runs a virtual machine (-> slow code) -As far as i know,you can't direct access the GPU in any way (only via sprites etc.), so you can't use GPU 2D acceleration, scalar units etc.
Screenshot of Bumpmap lighting- only a demo, my heightmaps will soon become better
But as I'm someone who never is willing to give up, I want to ask you guys i someone knows any workarounds/ hacks to get tis code faster:
def create_environment_map() #this one is only created once so you don't need to #calculate it everytime you create a bump map environment_map=Table.new(256,256); for x in 0...128 for y in 0...128 value=256-(Math.sqrt(x*x+y*y)*2); environment_map[128-x,128+y]=value; environment_map[128+x,128+y]=value; environment_map[128+x,128-y]=value; environment_map[128-x,128-y]=value; end end return environment_map; end
def create_image() $scene.spriteset.bump_mode; #loading height map bumpmap=Graphics.snap_to_bitmap; $scene.spriteset.normal_mode; heightmap=Table.new(bumpmap.width,bumpmap.height); #this is used to decrease the amount of pixels calculated @cx>128 ? a=@cx-128 : a=0; @cy>128 ? c=@cy-128 : c=0; @cx+128 > Graphics.width ? b=Graphics.width : b= @cx+128; @cy+128 > Graphics.height ? d=Graphics.height : d= @cy+128; for x in a...(b+1) #<- this loop uses a lot of calculation time for y in c...(d+1) pixel=bumpmap.get_pixel(x,y); heightmap[x,y]=(pixel.green).to_i; #gets the data out of the heightmap end end for x in a...(b) #<- this loop uses a lot of calculation time for y in c...(d) dx=heightmap[x+1,y]-heightmap[x,y]+128+(x-@cx); #the actual algorithm for dx dy=heightmap[x,y+1]-heightmap[x,y]+128+(y-@cy); #the actual algorithm for dy if !(dx<0 || dx>255 || dy<0 || dy>255) #check table bounds @color.alpha=$game_temp.environment_map[dx,dy]; #get the color self.bitmap.set_pixel(x,y,@color); #set the bitmap pixel end end end @image_created=true; #so you have to calculate the map only once end
At least do you know if: $game_temp.blabla needs more time then blabla=$game_temp.blabla and then use blabla? is a table faster then Bumpmap.get_pixel? is Color.new faster then @color.alpha= and then using @color?
And why do I need so much calculation time in the first place? To create a bitmap out of a Table that is screen height x screen width can easily be done in real time, why this can't?
I hope some of you can help me here, thanks
You want Next Gen graphic algorithms in RPG VX? Ask the horst :P