Author Topic: Shaders and SetTransparency  (Read 1620 times)

Offline K24A3

  • long
  • ***
  • Posts: 231
    • View Profile
Shaders and SetTransparency
« on: September 24, 2012, 04:12:57 pm »
I've just started learning ES2.0 using the included HelloShader example as a base, I'm trying to make the shaded face texture transparent using the usual Object3D.SetTransparency but it doesn't work at all. SetAdditionalColor also doesn't work.

Do these functions only work with standard non-shaded textures?

I'm guessing you would need to add these functions as code in the shader program.

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Shaders and SetTransparency
« Reply #1 on: September 24, 2012, 07:54:08 pm »
You have to use transparency (=alpha) and additionalColor (=additionalColor) in your vertex shader

Code: [Select]
uniform vec4 additionalColor;
uniform float alpha;
...
vec4 color = vec4(0.5, 0.5, 0.5, 1.0); // your color
color += additionalColor;
color = vec4(color.rgb, alpha);

Offline K24A3

  • long
  • ***
  • Posts: 231
    • View Profile
Re: Shaders and SetTransparency
« Reply #2 on: September 25, 2012, 02:10:19 am »
I see, thanks Thomas.

My main goal is to implement Volumetric Clouds and Mega Particles to my app using Shaders but not sure how to proceed. Time for some research..

Offline K24A3

  • long
  • ***
  • Posts: 231
    • View Profile
Re: Shaders and SetTransparency
« Reply #3 on: September 25, 2012, 05:15:39 am »
For some reason the shaded textures are very dark and appear to be heavily shadowed when the app is launched. If I jump into another app then back into my app, the scene is reloaded and the shaded textures become bright and normal.

I'm creating the ambient light and sun light _before_ creating and setting the shader, am I supposed to load things in a particular order to get the lighting working properly?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11747
    • View Profile
    • http://www.jpct.net
Re: Shaders and SetTransparency
« Reply #4 on: September 25, 2012, 01:26:54 pm »
Order shouldn't matter here. The value will be injected into the shader at render time. Are you using the latest version?

Offline K24A3

  • long
  • ***
  • Posts: 231
    • View Profile
Re: Shaders and SetTransparency
« Reply #5 on: September 25, 2012, 01:35:03 pm »
Yes, 1.25 and 1.26 beta.

I'll post up a screenshot of before and after in a moment.


Offline K24A3

  • long
  • ***
  • Posts: 231
    • View Profile
Re: Shaders and SetTransparency
« Reply #6 on: September 25, 2012, 01:40:14 pm »
Left image is before, right is after.

The globe on the left is a normal texture with transparency. Globe on the right has the shader.

Notice the first image is missing transparency of the normal texture, and heavy shadows on the shaded globe.

[attachment deleted by admin]

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11747
    • View Profile
    • http://www.jpct.net
Re: Shaders and SetTransparency
« Reply #7 on: September 25, 2012, 01:46:21 pm »
That strange "lightning bolt" effect reminds me of normals not being calculated correctly...What happens if you rely on the default shaders instead?

Offline K24A3

  • long
  • ***
  • Posts: 231
    • View Profile
Re: Shaders and SetTransparency
« Reply #8 on: September 25, 2012, 01:51:47 pm »
I'm very new to ES2.0, how do I set it to a default shader?

shader = new GLSLShader("defaultVertexShader.src","defaultFragmentShader.src");
.. throws an exception.

If I set a normal texture to the Object3D, wouldn't that use the default shader? If yes, the globe on the left has a normal texture.

It's happening on both the phone and emulator by the way. Both are Jellybean (4.1.x)
« Last Edit: September 25, 2012, 02:21:31 pm by K24A3 »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11747
    • View Profile
    • http://www.jpct.net
Re: Shaders and SetTransparency
« Reply #9 on: September 25, 2012, 03:20:53 pm »
Default shader means that you don't assign a shader yourself but let the engine choose of out of its set of shaders. If the problem persists and you are sure that it isn't your fault, feel free to create a test case and send it to me so that i can have a look. It might happen that under some conditions the user defined shaders don't get the data injected that they should...albeit i'm not aware of such a problem ATM (had them in the past).

Offline K24A3

  • long
  • ***
  • Posts: 231
    • View Profile
Re: Shaders and SetTransparency
« Reply #10 on: September 25, 2012, 03:30:27 pm »
I see a lot of "Loading default shaders (...)" in the logs so I assume calling setTexture() with no call to setShader on objects will use a default shader.

I am using jPCT in a Live Wallpaper so perhaps that has something to do with it. The code logic looks fine to me but I'll persist and look into making a test case as an App.

Appreciate the help.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11747
    • View Profile
    • http://www.jpct.net
Re: Shaders and SetTransparency
« Reply #11 on: September 25, 2012, 08:45:17 pm »
That would be helpful...i'm not going to debug a wallpaper... ;)