Shaders and SetTransparency

Started by K24A3, September 24, 2012, 04:12:57 PM

Previous topic - Next topic

K24A3

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.

Thomas.

You have to use transparency (=alpha) and additionalColor (=additionalColor) in your vertex shader


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);

K24A3

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..

K24A3

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?

EgonOlsen

Order shouldn't matter here. The value will be injected into the shader at render time. Are you using the latest version?

K24A3

Yes, 1.25 and 1.26 beta.

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


K24A3

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]

EgonOlsen

That strange "lightning bolt" effect reminds me of normals not being calculated correctly...What happens if you rely on the default shaders instead?

K24A3

#8
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)

EgonOlsen

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).

K24A3

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.

EgonOlsen

That would be helpful...i'm not going to debug a wallpaper... ;)