Author Topic: Changing PNG texture brightness  (Read 1541 times)

Offline bfreuden

  • byte
  • *
  • Posts: 6
    • View Profile
Changing PNG texture brightness
« on: May 31, 2014, 03:54:23 pm »
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.

Offline sushobhit

  • long
  • ***
  • Posts: 109
  • future is now
    • View Profile
    • ANDROID APPS
Re: Changing PNG texture brightness
« Reply #1 on: June 01, 2014, 07:35:52 am »
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

Offline bfreuden

  • byte
  • *
  • Posts: 6
    • View Profile
Re: Changing PNG texture brightness
« Reply #2 on: June 01, 2014, 01:54:00 pm »
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!



Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11746
    • View Profile
    • http://www.jpct.net
Re: Changing PNG texture brightness
« Reply #3 on: June 01, 2014, 09:00:53 pm »
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.

Offline bfreuden

  • byte
  • *
  • Posts: 6
    • View Profile
Re: Changing PNG texture brightness
« Reply #4 on: June 01, 2014, 11:04:27 pm »
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,



Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11746
    • View Profile
    • http://www.jpct.net
Re: Changing PNG texture brightness
« Reply #5 on: June 02, 2014, 10:39:17 am »
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.

Offline bfreuden

  • byte
  • *
  • Posts: 6
    • View Profile
Re: Changing PNG texture brightness
« Reply #6 on: June 02, 2014, 11:04:34 pm »
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:
Code: [Select]
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,

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11746
    • View Profile
    • http://www.jpct.net
Re: Changing PNG texture brightness
« Reply #7 on: June 02, 2014, 11:15:43 pm »
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.

Offline bfreuden

  • byte
  • *
  • Posts: 6
    • View Profile
Re: Changing PNG texture brightness
« Reply #8 on: June 03, 2014, 07:21:08 pm »
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:
Code: [Select]
// 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,

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11746
    • View Profile
    • http://www.jpct.net
Re: Changing PNG texture brightness
« Reply #9 on: June 03, 2014, 07:30:11 pm »
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...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11746
    • View Profile
    • http://www.jpct.net
Re: Changing PNG texture brightness
« Reply #10 on: June 03, 2014, 08:50:35 pm »
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.

Offline bfreuden

  • byte
  • *
  • Posts: 6
    • View Profile
Re: Changing PNG texture brightness
« Reply #11 on: June 15, 2014, 10:30:16 am »
You're welcome! Thanks again for your help and for your work on jPCT.