Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

 
Reply to this topicStart new topic
> Bump Mapping, Help me to get it real time!
-dah0rst-
post Jan 5 2012, 01:06 AM
Post #1


Level 11
Group Icon

Group: Revolutionary
Posts: 174
Type: Scripter
RM Skill: Advanced




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 wink.gif


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:

Code
CODE
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 wink.gif


__________________________
You want Next Gen graphic algorithms in RPG VX? Ask the horst :P


But don't expect this in real time ;)
Go to the top of the page
 
+Quote Post
   

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 23rd May 2013 - 01:17 AM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker