Results 1 to 15 of 15

Thread: DX8 - Getting a pixel colour and Thanks to all for help

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    118

    DX8 - Getting a pixel colour and Thanks to all for help

    OK all this should be pretty much my last question for these forums (phew says Z) unless I get stuck coding my project although Im feeling pretty confident now (even though it will probably only run at 1 FPS ).

    Is there any FAST way of returning the pixel colour of a screen coordinate? I know it can be done by locking the backbuffer although as far as I am aware this is a v slow process and I dont know how to do it anyway. If not I guess I can live without it.

    Cheers all and especially to Z thanks very much for all your help, I couldnt have done it wivout u .

    Dan

    PS I will be back to help others as my way of saying thanks so dont think u can get rid of me that easy .

  2. #2
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Other then locking the backbuffer, no, there is no way to do it.

    Z.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    118
    Z

    Would u agree that this method is slow?

  4. #4
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Pretty slow... but if you need to do it, do it. Experiment =).

    Z.

  5. #5
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Using the array is fast, using GetLockedPixel is slower.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    118
    Well I wanna do it to check wether the 'sun' is visible or not. If the pixel colour at the suns screen pos is not that of the sun then I know it is obscured otherwise it is visible. If so draw a lens flare if not dont.

    Can any1 give me some VB code for this please (just the locking the backbuffer and getting the pixel colour part).

    Cheers

    Dan

  7. #7
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Ack! BAD reason to lock the back buffer... To see if the sun is onscreen, just use the D3DXVec3Project() function, and project the sun's position onto the screen. Then just check to see if the returned point is within the screen's boundries.

    Z.

  8. #8
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    As far as I can see, there are only 2 reasons that you would lock the back buffer. The first, is to apply some sort of post render image filter (like a blur). You could blur by using a texture as a render target, and then using that texture to cover a screen-sized quad, scaled up (the texture filter will blur for you).

    The other is to take a screen shot.

    Some people will use the abck buffer to do culling, but I think this is a bad method.

    Z.

  9. #9
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    The blur would look pretty bad though, Zaei!!
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  10. #10
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Depends on the card, and the blur filter applied =).

    Z.

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    118
    D3dXVec3Project would tell u if it was on screen or not but it wouldnt tell u if it was obscured by other geometry or not right? You wouldnt want a lens flare showing if u couldnt see the sun even if it was on screen.

    Probably is a bad approach though.

    Dan

  12. #12
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    That is what ray casting is for =). Use D3DXVec3Project, and find the screen coordinates of the sun. If it is onscreen, use D3DXVec3Unproject to find the point on the near clip plane (z==0.0). Create a ray using the sun pos, and the point you just found, and see if that ray intersects any geometry. If it does not, draw your flare.

    Z.

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    118
    lol @ z==0.0 u C++ man .

    Can I be cheeky and ask for code for that please Z its just that Im desperate to have tomorrow off Ive been stuck to this thing all week and its back to college on Monday.

    Cheers

    Dan

  14. #14
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Its an engine thing. You are starting to realize why game engine design is such a hot topic. You need a way to get at your geometry, so that you can create planes from it, and then check to see if the intersection point on that plane is inside of the geometry triangle. You can use the D3DXLineIntersectPlane() function to check plane intersection, and D3DXPlaneFromPoints() to create the plane. Do a google search for a function to find out if a point is within a plane. Other then that, it is simply a matter of looping through each triangle in your geometry, and see if it is intersected by the ray.

    And yes, C++ smacks VB around =).

    Z.

    [edit]
    At lease I didnt use == 0.0f =).

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    118
    lol yeah dont I know it, why on earth did I start learning DX in VB O well no time to change now .

    Those function names will give me something to work on. Cheers

    Dan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width