Changing PNG texture brightness

Started by bfreuden, May 31, 2014, 03:54:23 PM

Previous topic - Next topic

bfreuden

Hi,

I am writing both my first Android and first OpenGL ES application and I am happy because I have the feeling it would have been much more complex without jPCT-AE :)
I am here because I have a problem changing the brightness of a png texture.

I have successfully managed to modify the jPCT-AE HelloWorld project in order to load an obj+mtl+png combo, and to add a SeekBar that modifies the intensity of the Light object (sun) and the color of the background (back).
It works great when I don't add the texture to my object: I can see the object becoming brighter or darker (good!).
However if I add the texture to my object (object.setTexture(ti)), it is no longer affected by the brightness: its appearance does not change at all, only the background color changes.

Do you know why it is so, and how I can solve my problem?
Thanks in advance,

Bruno.

sushobhit

try playing with the world's ambient light settings

something like world.setambientlight(changeRhere,changeGhere,changeBhere);

increasing decreasing this would give you the effect you desire

bfreuden

Thanks for the fast reply!
Unfortunately it didn't do the trick. I have modified my lighting modification function according to your suggestion:



And this is the result depending on whether I add a texture or not to my object:



I actually wonder if the default shader handles this. However as I am an OpenGL+jPCT-AE+Android newbie, I also wonder if I missed something obvious :)
Thanks again in advance for any tip!



EgonOlsen

It might help to see that your "ti" actually is that you set as a texture. The default lighting formula of OpenGL (which is also the one that the default shader mimic) is that the vertex color affects only the first texture stage. All other texture stages are then applied to the result according to their blending modes.

bfreuden

Hi,

Thanks a lot for your answer!
Here is the code of my OnSurfaceChanged method (I removed try/catch and streams close() for the sake of readability).
It is widely based on the HelloWorld-AE project (having the same "problem" btw):



This is easy to reproduce using the HelloWorld-AE project:

  • Comment the /cube.calcTextureWrapSpherical();/ and /cube.setTexture(ti);/ lines
  • Observe the lighting
  • Change the sun intensity /sun.setIntensity(2, 2, 2);/
  • Observe the change of the lighting 
  • =>This change can no longer be observed if you uncomment the first two lines (well... at least on my device and on my emulator)

Thanks in advance for your help,



EgonOlsen

That texture info makes no sense. Just remove the "texture" texture and use your own texture as the single layer and all should be fine.

bfreuden

Hi,
You're right! Thank you very much!
Shall I post a (minor) bug since this is a copy/paste of the HelloWorld-AE (cube) example delivered in the jpct-ae.zip file?



In case others might find it useful, here is the code working correctly:

Texture texture =  new Texture(getResources().getAssets().open("Turret_01.bmp"), true);
TextureManager.getInstance().addTexture("texture", texture);
TextureInfo ti=new TextureInfo(TextureManager.getInstance().getTextureID("texture"));
turret.setTexture(ti);



Best regards,

EgonOlsen

No, it's not a bug. The HelloWorld example uses its own icon to create a texture to keep things simple. You added another texture as the second layer that completely hides the first layer because of the chosen blending mode. Lighting only affects the first stage as mentioned above, so the result was to be expected.

bfreuden

Hi,
You might think I'm obtuse :( but I really have the impression the HelloWorld-AE project also adds another texture (the aquarium) to the one created from the icon (the gear). Here is the code:

// Create a texture out of the icon...:-)
Texture texture = new Texture(BitmapHelper.rescale(BitmapHelper.convert(getResources().getDrawable(R.drawable.icon)), 64, 64));
TextureManager.getInstance().addTexture("texture", texture);

try {
Texture texture2=new Texture(getResources().getAssets().open("alpha.png"), true);
TextureManager.getInstance().addTexture("texture2", texture2);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
TextureInfo ti=new TextureInfo(TextureManager.getInstance().getTextureID("texture"));
ti.add(TextureManager.getInstance().getTextureID("texture2"), TextureInfo.MODE_DECAL);

And changing the ambiant light or the light values have no effect on the texture lighting in the HelloWorld-AE project (as downloaded from http://www.jpct.de/download/net/jpct-ae.zip).
Best regards,

EgonOlsen

Oops, it's not supposed to do that. Seems like as if some test code accidently made it into the zip. I'll look at it...

EgonOlsen

Yes, the version in the zip was one that i made to test out decal blending mode in OpenGL ES 2.0...i don't know how it managed to get into this zip, but i've updated it with the proper one. Thanks for pointing it out.

bfreuden

You're welcome! Thanks again for your help and for your work on jPCT.