Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (494)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  quickest most effecient way to darken/lighten image on the fly?  (Read 2840 times)
0 Members and 1 Guest are viewing this topic.
Offline LordChandar

Junior Member


Projects: 1



« Posted 2012-12-14 15:09:40 »

Good morning.

I have a shading system in my game that currently I do it in an old school way.  I have the tiles basically 4 times (in three different shades.)

Is there an efficient way to shade (or lighten) tiles in 2D on the fly in java?  The one method I found seems quite expensive.
Offline davedes
« Reply #1 - Posted 2012-12-14 15:28:01 »

Java2D isn't so great at doing things "on the fly" -- for that you should be using OpenGL and GLSL.

The easiest and most efficient thing would be to construct the four texture atlases at creation/loading time. I say texture atlases because they should have the potential for more hardware acceleration than individual buffered images... Smiley

Of course, if you want your high performance active rendering, you shouldn't be using Java2D in the first place.

Offline counterp

Senior Member


Medals: 11



« Reply #2 - Posted 2012-12-14 15:37:09 »

You could always draw a slightly transparent white (lighten) or black (darken) rectangle over a tile if the light is uniform
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline The-Next

Senior Member


Medals: 7
Projects: 2



« Reply #3 - Posted 2012-12-29 08:09:59 »

In my opinion, an efficient way of doing this in java2D/windows is using the drawImage with a LookupOp operation


 LookupOp LU;
...
g.drawImage(image,LU,posX,posY);

by modifying the LookupOp you can change the image brightness:


e.g. Darken image, half of the brightness:

            brightnessBloq=new byte[256];
        for(int i=0;i<256;i++){brightnessBloq=(byte)(i/2);
        LU = new LookupOp( new ByteLookupTable(0,brightnessBloq), null);

later, by just modifying values of brightnessBloq array, it automatically change the brigtness fo the next painted image.

Also, I agree that if you want good performance with high resolutions, java2D can be a little bit problematic Tongue

BR



Offline P0jahn

Senior Member


Projects: 3



« Reply #4 - Posted 2012-12-30 18:11:53 »

I advise you to stay away from Java2D when creating games. Java2D spend more time rendering than for example Slick2D does and, having fps such as 60 or higher is going to cause lag because Java2D can not render so many times per frame. So what is going to happen that it is going to skip rendering some frames, making the game look laggy, but in reality it is just rendering operation that are being aborted. Note that this do not happen on all computers, but you wanna make a game that looks the same on all computer, right?
Offline The-Next

Senior Member


Medals: 7
Projects: 2



« Reply #5 - Posted 2013-01-06 18:41:29 »

I agree that, for a serious game, Java2D is not the best option, as it has several serious flaws. But it is perfectly able to handle 60 frames per second when the graphics are not very complicated.

<a href="http://www.youtube.com/v/wfh_jN23jfA?version=3&amp;hl=en_US&amp;start=" target="_blank">http://www.youtube.com/v/wfh_jN23jfA?version=3&amp;hl=en_US&amp;start=</a>

In this video I use two techniques for changing object brightness on the fly. The orange region has on top a layer wich alpha is changed dynamically. The gray part uses the technique I mentioned before.  

Offline alesky

Junior Member


Medals: 3
Exp: 15 years


mmm....


« Reply #6 - Posted 2013-01-06 19:06:36 »

In this video I use two techniques for changing object brightness on the fly.  

whot are the two techniques that you mentioned?Huh

In my experiences with Java2D, working with buffere images operation like LookupOp to perform process of the immage on the fly
is extremely heavy!

looking at the Garbage collection log, my games was using more that 10-15 time the memory with the effect!!!!
for sure, depend from the use that u did of the effect, but it is without doubt a heavy operation

 
Offline The-Next

Senior Member


Medals: 7
Projects: 2



« Reply #7 - Posted 2013-01-06 19:18:48 »

One is using LookUpOp operations. The other is just draw something on top (like a rectangle, or initialized VolatileImage) filled with a certain color with a certain alpha. You fill it each time so the alpha can be changed anytime.

Interesting what you are saying. TBH I just look at the rendering time of my loops for evaluating the algorithms.  I didn't got any noticeable FPS drop with the lookupOp. Drawing a layer over caused more FPS drops, specially in low end GPUs like an intel HD3000.  My desktop uses a mid/high-range GPU: a GTX460.


Offline alesky

Junior Member


Medals: 3
Exp: 15 years


mmm....


« Reply #8 - Posted 2013-01-06 20:39:54 »

ok now is clear, thanks
in your example you use on the top of your image a rectangle filled with a RadialGradientPaint
and you change just the alpha channel of the color,

now comparing the two solutions:
- 1) LookUpOp (that works at the pixel level so is for any pixel the operation must be performed)
- 2) rectangle filled with same Paint (like Gradient)

what is the best solution?

your experience say the first one, without your response my natural answer instead is the second, because I imagine that at low level the second one must use same low level directive to draw the rect.
but i don't know,i never tryed the second solution.
Do you know how works Graphics2D.fillRect method?


regarding the verify of the Garbage collection try to pass this parameter to your java command
-verbose:gc

this is the official link
http://www.oracle.com/technetwork/java/javase/gc-tuning-6-140523.html

if u works with eclipse in the console you will see the output of the GC
Offline davedes
« Reply #9 - Posted 2013-01-07 02:07:54 »

I agree that, for a serious game, Java2D is not the best option, as it has several serious flaws. But it is perfectly able to handle 60 frames per second when the graphics are not very complicated.
Have you tested this on a variety of machines? And without the "OpenGL" VM flag?

I ask this because Java2D performance varies a lot from system to system. What might get 100 FPS on one will lead to 2 FPS on another. I'd love to test it out and see how it fares. Smiley

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ReBirth
« Reply #10 - Posted 2013-01-07 02:33:07 »

I just lowing the r,g,b channel value together. It turns darker.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Dwinin (19 views)
2014-09-12 09:08:26

Norakomi (54 views)
2014-09-10 13:57:51

TehJavaDev (63 views)
2014-09-10 06:39:09

Tekkerue (31 views)
2014-09-09 02:24:56

mitcheeb (53 views)
2014-09-08 06:06:29

BurntPizza (37 views)
2014-09-07 01:13:42

Longarmx (23 views)
2014-09-07 01:12:14

Longarmx (26 views)
2014-09-07 01:11:22

Longarmx (26 views)
2014-09-07 01:10:19

mitcheeb (34 views)
2014-09-04 23:08:59
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!