Environment reflection on a textured objects

Started by Promyclon, August 28, 2017, 01:33:51 PM

Previous topic - Next topic

Promyclon

Hi,

I managed so far to write couple of shaders for my model. Some of them add environment reflection to plain color element and it looks fine. I'm trying to find a way to to the same with textured elements.

Even this wasn't easy. I added environment texture to materials (.mtl) to make it accessible in fragment shader and found that an object loaded from .obj loses its color information from Kd field, that was available in color attribute. Color was got from (I guess) left top pixel of the texture. This color I had to hardcode in shaders and I could because I have distinct shader for every material that needs a non-different one.  I got to the point where I'd like to add a reflection to textured elements.

I open .obj and .mtl files in Java on PC to serialize it and use on Android. I decided to put my processing here to feed model's elements with additional data. I've extracted texture ID from elements to replace it with TextureInfo containing original texture and reflection texture. But as I could get texture using PolygonManager, I cannot find how can I get a vertex color. I think putting it in the additionalColor would preserve this color and I could have .mtl colored elements back.

But I cannot find how to extract from Object3D a Kd color from .mtl. How to preserve Kd color when a texture is added to an object?

At the moment of converting objects I don't know which ones will be reflective - this depends on their shaders in apk. So I'd add environment texture to all of them and remove the texture from map_Kd in .mtl. It's overfluous for sure (I know the map id is assigned to every polygon), but is there another way? Could I inject env map into the shaders in some other way?

EgonOlsen

I'm not sure, if that's what you actually want...but you can obtain a texture-ID for a polygon via the PolygonManager and then go to the TextureManager and ask for the name of that texture. Textures created from color materials follow a specific naming convention (you'll notice it when you it). Maybe that helps...

Promyclon

Knowing that objects always have a texture was all I needed. Just adding environment to the second channel should does the job. Thank you!