PDA

View Full Version : PatternSurfaces[0].Pixels[X,Y] MORE SLOW



kotai
01-03-2007, 12:08 AM
Hi.

I'm simulate rain in my game: http://www.miniracingonline.com

I convert to gray scale in TBakground to simulate gray day. ValueRain is for more or slow rain (slow or more color)


// DXImageList.Items[1] = Original color Background, not change
// DXImageList.Items[2] = Final Background (chage color)

// for eah pixel X,Y:
ColorPixel := DXImageList.Items[1].PatternSurfaces[0].Pixels[X,Y]; //original color image
R := GetRValue(ColorPixel);
G := GetGValue(ColorPixel);
B := GetBValue(ColorPixel);
ColorAver := (R + G + B) div 3;
if R < ColorAver then
R := Min(R+ValueRain ,ColorAver)
else
R := Max(R-ValueRain ,ColorAver);
if G < ColorAverthen
G := Min(G+ValueRain ,ColorAver)
else
G := Max(G-ValueRain ,ColorAver);
if B < ColorAverthen
B := Min(B+ValueRain ,ColorAver)
else
B := Max(B-ValueRain ,ColorAver);
// aply new color to background
DXImageList.Items[2].PatternSurfaces[0].Pixels[X,Y] := RGB(R,G,B);


I paint 8 pixels by milisec but is MORE slow (100 fps to 20 fps :x ). Normally Background is 5000x3500 pixels :shock:

Another tecnique to change color faster ?

Thanks :wink:

Original color image:
http://www.cpce.es/original.JPG

Color of Full Rain:
http://www.cpce.es/fullrain.JPG

seiferalmasy
01-03-2007, 03:04 AM
sorry I know this is offtopic, but what are you using for netplay? since delphix's only uses tcp and doesn't work with routers/?

kotai
01-03-2007, 08:44 AM
For netplay I use DirectPlay of unDelphiX. Work open TPC port (6666 TCP in my game) in router, server and clients :?

DirectPlay 8 no need to open ports for clients, but delphix use DirectPlay7. I prove convert to directplay 8 but not work :evil:

Kotai.

kotai
01-03-2007, 09:19 AM
I have testing rain change:

Track 1024 x 768 pixels --> 2 minutes :?
Track 4000 x 4000 pixels --> 55 minutes :x (race long are 20 or 30 minutes)

I change in real time, but 1 change are 55 minutes :shock: ... I need one change each 1 or 2 minutes...

I change 8 pixels by milisec and FPS down 100 to 40... This not work fine :cry: I need change minium 100 pixels by milisec

:idea: I can change palette ? In my game Tbackground are in 16bits color... ¬ø pallete are only for 256 colors ?

Kotai

cairnswm
01-03-2007, 10:04 AM
Cant you draw a semi transparent alpha scaled image over the background instead? Wont this be significantly faster?

Nitrogen
01-03-2007, 12:22 PM
Yes, undoubtedly.

Draw your background again, but with transparency and using the rainy-track texture instead!

kotai
01-03-2007, 01:08 PM
with DrawAlpha( ) ? I will probe, but efect rain isn't a semi transparent alpha scaled, is convert to gray scale.

If I draw a semi transparent alpha scaled image, who restore original colors (gradually) when rain finish ? :?

I test this night and coment.

Thanks.

cairnswm
01-03-2007, 01:44 PM
Add the original colors back by slowly removing the alpha value to white - this means less and less alpha value.

ijcro
01-03-2007, 03:43 PM
Off way?

You can use PokeBlendPixel() function or direct commit property Pixel (assembler based routines, feature from unDelphiX) to DXDraw Surface. But the Surface has to locked. And can be effective set up the SystemMemory flag.

Illustrate code here:

DXDraw.Surface.Lock;
DXDraw.Surface.Pixel&#91;X, Y&#93; &#58;= TheColor;
TheColor &#58;= DXDraw.Surface.Pixel&#91;X+1, Y+1&#93;;
DXDraw.Surface.Unlock;


Regards

kotai
01-03-2007, 05:54 PM
I can 2 problems with pixel

1) when SystemMemory flag is set FPS down 100 to 18 :shock: (with out rain, when rain down to 16 fps)

2) This method are not persistent. In next frame i lost all pixel

if not set systemmemory not work, but all code execute and speed is fantastic, I put 320 pixel by milisecond and frames down 100 to 70. Pixel[] are 40 times more rapid than Pixels[]



I will test DrawAlpha.

Kotai.

kotai
05-03-2007, 01:09 PM
ijcro you are the best :P

DXDraw.Surface.Pixel[X, Y] not persistent, but I not change DxDraw.Surface, I change DXImageList.Items[1].PatternSurfaces[0] and work very fast (100 times or more than Pixels), now change 256 pixels eah milisecond and FPS down 100 to 90.

But I have 2 problems :cry:

* In 32bits color work fine, but in 16bits color return a green image:

ORIGINAL IMAGE:
http://www.cpce.es/normal.JPG

FULL RAIN 32 BITS COLOR:
http://www.cpce.es/32bits.JPG

FULL RAIN 16 BITS COLOR:
http://www.cpce.es/16bits.JPG


I testing:

// read pixel color
ColorPixel := DXImageList.Items[1].PatternSurfaces[0].Pixel[X,Y]; //original color image
R := GetRValue(ColorPixel);
G := GetGValue(ColorPixel);
B := GetBValue(ColorPixel);
// efect color over R, G, B
// ..........
// write pixel color
DXImageList.Items[2].PatternSurfaces[0].Pixel[X,Y] := RGB(R,G,B);


In 32 bits first pixel return R=41, G=106, B=137 and 16 bits return R=69, G=139, B=0. In 16 bits all Blue Pixel return 0. I'm test with ColorToRGB and same result:

// read pixel color
ColorPixel := ColorToRGB(DXImageList.Items[1].PatternSurfaces[0].Pixel[X,Y]); //original color image
R := GetRValue(ColorPixel);
G := GetGValue(ColorPixel);
B := GetBValue(ColorPixel);
// efect color over R, G, B
// ..........
// write pixel color
DXImageList.Items[2].PatternSurfaces[0].Pixel[X,Y] := RGB(R,G,B);



2¬? Problem is when change full screen to windowed mode or viveversa or I move window (in windowed mode) arround desktop, image restore to original image, lost new color :shock: DrawAlpha efects also get lost.

¬ø Any solution to 2 problems ?

Thanks.

savage
05-03-2007, 02:07 PM
What happened to your kotai login?

kotai
05-03-2007, 02:43 PM
I change email in profile and new activation email not recived.

I send 2 emails to admin for activate, but not response.

I create a new profile.

Kotai.

JernejL
05-03-2007, 03:49 PM
you could just use another set of rainy textures.

Traveler
05-03-2007, 03:54 PM
I change email in profile and new activation email not recived.

To whom did you send the request?

In any case, I have reactivated your original account.

kotai
05-03-2007, 04:49 PM
Thanks for reactivate my account. I send request to admin@pascalgamedevelopment.com and raproductions@hotmail.com

In static image rainy textures not pretty, but in fast movement is good. Best solution are a line but, more angle positions. This rain only have 7 positions (up big to down small)

Now convert dry track 1024 x 768 to wet track (gradually) only 9 secons.

In 16bits color more fast than 32bits color but color change to green :x.

Kotai.

savage
05-03-2007, 04:56 PM
You old activation email may have been lost in the last deluge of spam.

kotai
07-03-2007, 08:17 AM
To do a lightning or flash (rain) for a few milisec changed the black color to white. There is some way of it doing that does not consume very much resources?

And problem of lost all changes when swich to full screen or windowed or when move window game arround desktop, can someone help me?

Thanks.

seiferalmasy
07-03-2007, 10:14 AM
kotai try this for me with regards to moving windows:

In object inspector, set dragkind to DOCK.

I had similar problems with the app pausing/ bad refresh/ hangs , this solved it. But obv this isnt a fix for your other problems and may not be a fix of any kind

I am also assuming you are reinitialising dxdraw on window change.

kotai
07-03-2007, 11:09 AM
I do not like very much this solution because it does not leave you to move the window.

What I do not understand is because the color gets lost if I am modifying the image of the DXImageList and not the screen. In the DXImageList they should not lose the changes though it returns to initialize the DXDraw.

Can be for changing the surface of the image and not the image directly in DXImageList?

Thanks

seiferalmasy
07-03-2007, 03:32 PM
You should still be able to move window but yes you are right. Something fundamentally wrong somewhere...

ijcro
07-03-2007, 11:28 PM
I am not sure that change image resp. change surface of image in DXImageList is right way.

kotai
09-03-2007, 06:48 PM
Color Bug solved.

I convert 16 to 24 bits:

Solved:

function RGBTo16bit(R,G,B: Byte): Integer;
begin
Result:= ((B shr 3) shl 11) + ((G shr 2) shl 5) + (R shr 3);
end;


function ToRGB(Color: Integer): Integer;
begin
Result:= ((Color and $F800) shl 8) + ((Color and $7E0) shl 5) +
((Color and $1F) shl 3)
end;


Now only bug when window moved or swich fullscreen, I lost all modified colors, all DXImageList restore to defaults color :cry: , can help me ?

Kotai. :roll: