Author Topic: Get a pixel color from and object 3d texture?  (Read 4255 times)

Offline Ulrick

  • byte
  • *
  • Posts: 18
    • View Profile
Get a pixel color from and object 3d texture?
« on: November 11, 2010, 05:28:01 pm »
Hi Egon,

I cannot find information regarding this matter on the forum, so I write this.

Is there a way to get a pixel color from an Object3D? It would be nice to have it when colliding two object, get the color of the collision point and/or some points with a coordinate system.

Thanks in advance,

Ulrick

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Get a pixel color from and object 3d texture?
« Reply #1 on: November 11, 2010, 05:42:01 pm »
No, that's simply not possible.

Offline Ulrick

  • byte
  • *
  • Posts: 18
    • View Profile
Re: Get a pixel color from and object 3d texture?
« Reply #2 on: November 12, 2010, 10:38:42 am »
What about something like this?

SimpleVector Point22D =  Interact2D.project3D2D(camera, FrameBuffer, PointOfImpact);

int IntColor=FrameBuffer.getPixel(Point22D.x, Pint22D.y); //   this function is just missing, but would be usefull. The getPixels
                                                                             //   just take too long and get too many             
                                                                             //   not-required data.

RGBColor PixColor = new RGBColor(  (IntColor>> 16) & 255, (IntColor>> 8) & 255, IntColor & 255);

Iti shouldn't be difficult to write a function like the getPixel (x,y) that will be faster than the getPixels().

With that, it should be possible to get it nearly right.

What do you think?

Thanks,

Ulrick

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Get a pixel color from and object 3d texture?
« Reply #3 on: November 12, 2010, 11:10:09 am »
Every read from gpu's memory is slow, even if you just read one pixel. But that's not the point. The problem is, that this will work only if the collision point is actually visible on screen. That's a very special case. In most cases, one of the collision partners or some other entity will hide the actual collision point, so you would get a more or less random colored point.
Another problem is that the color in the framebuffer doesn't reflect the original color of the texture, because it's influenced by lighting, filtering...
Maybe the better question is, what problem you are actually facing that you want to solve this way? Maybe there's another solution to that than this way!?
« Last Edit: November 12, 2010, 11:57:25 am by EgonOlsen »

Offline Ulrick

  • byte
  • *
  • Posts: 18
    • View Profile
Re: Get a pixel color from and object 3d texture?
« Reply #4 on: November 12, 2010, 11:55:58 am »
Yes,

you are right, probably is better explain my case.

what I would like to do is to implement a particle system that creates "dirt" when a surface is hit by (i.e.) a missile.

In that case, would be nice to have some particle present a portion of the texture of the original Object been hit.

Is there a way to implement it? As I cannot find a way to get the texture used by an object and as I cannot get portion of it, what could be a nice solution for this kind of issue?

Thanks a lot Egon,

Ulrick

UPDATE:

No solution for this ?

Thanks Egon
« Last Edit: November 19, 2010, 01:19:06 pm by Ulrick »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Get a pixel color from and object 3d texture?
« Reply #5 on: November 20, 2010, 09:12:39 pm »
You can get the texture of an object by using the PolygonManager...however, i wouldn't worry too much about this. IMHO, a basic dirt texture that blends nicely with the object's texture should do fine.

Offline Ulrick

  • byte
  • *
  • Posts: 18
    • View Profile
Re: Get a pixel color from and object 3d texture?
« Reply #6 on: November 22, 2010, 10:48:59 am »
Ok, thanks, but just a consideration.

What if you have a plane where you have water, snow, rocks, dirts and green? What should you take into account when moving "dirts"?

Thanks,

Ulrick