Today, I want to read the color from scene-objects so that I have their color as RGBAColor in my Program. I dont want do display it on the screen. Has anyone an Idea how I can do that? I tried 2 ways so far… without success
My first try:
I use raycasting
I can compute the collisions between ray and seen
I can compute the triangle which has been hit
Works fine… but Triangles does not provide any methods like “readColor” or “getColor”. How can I go on?
[java]
CollisionResults results = new CollisionResults();
Ray ray = new Ray(this.position, this.orientation);
My second try was to use a camera. I have been thinking that I can read the pixels from the 2D Projection which is computed by the camera.
This is very nice. The camera films the scene and I also have it on my screen. But how do I find the matrix with the color values that are displayed on my screen?
Cameras do have some interesting functions which may be helpful. read(JMEImporter …), getScreenCoordinates(Vector3f), getWorldCoordonates(Vector3f),…
What you are trying to do is not simple - quite apart from anything else the “colour” of something depends entirely on the fragment shader used to render it.
This can include material colour, textures, lighting, shadows, potentially even other opaque objects partially in front of it or transparent/translucent objects in front of it…etc…etc.
This may be easier if you take a step back and explain what you are trying to achieve by doing this as there may be a simpler solution.
I write a software simulation of small robots. These robots shell navigate through the scene and they shell use several sensors for that, including a lightsensor and a colorsensor.
I can imagine that there are much parameters which influence the color of a polygon in 3D-space. But if this polygon is already rendered into 2D (which should be done by the “camera”)? Is it not possible to access the rendered 2D projection?
Its inside the graphics card, thats the issue. As mentined you have to render it back to a texture and getting that out of the graphics card is the issue.
Raycasting (and getting the hit-geometry and the hit-point)
Accessing the pixel of the texture (which is mapped to that geometry) at the hitpoint?
I would ignore shadows, lighting, other opaque objects ect. ect. in that case. I would read the value of the texture only! Is that simpler to do? What do I have to do?
Sorry to bother again… just for my understanding: Is the computation of the (final) color of a polygon only DIFFICULT (but possible) to do in software or is it IMPOSSIBLE without graphic card support (when using an OpenGL & LWJGL based rendering system)?
The final color yes, i’m pretty sure that’s nearly impossible without graphics card support. Unless you create some sort of universal graphics card emulator.
If your just using simple colors and texture maps then you can get that information from raycasting like you suggested. Just get the color from the texture at the texCoord of the ray intersection and add any additional colors you used with that material.
First of all; big thanks for your reply and your code!
Unfortunately I dont get it running. Can you please tell me if I use your function correct?
I am working with raycasting ect. … so “closest” is the collisionresult of the raycasting and “hitgeo” is the geometry which has been hit by the ray.
[java]
Vector3f position = hitgeo.worldToLocal(closest.getContactPoint(), null);
And can you tell me… I newer saw this before (and my compiler as well): A closing i-tag opening i tag. Is this the same like A[i]?
And what is tx1.y - ? Is it decrementing ( tx1.y - -)?
Well you just give it the mesh that was hit, the localhitpos and the triindex, all should be in the collisionresult, or reachble from it. ith then calcualtes the exact position for it, based on the three nearest vertexes.
Ok i think that this is what I do. I think that I still dont understand what the return value exacty is. I have assumed that the return value is the pixel index of the texture. Is that correct?
And again… one reason why I dont get it running (perhaps) is because I dont understand this code in your GaussJordan (my compiler also cannot compile it):