www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: K24A3 on September 24, 2012, 04:12:57 pm

Title: Shaders and SetTransparency
Post by: K24A3 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.
Title: Re: Shaders and SetTransparency
Post by: Thomas. 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);
Title: Re: Shaders and SetTransparency
Post by: K24A3 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..
Title: Re: Shaders and SetTransparency
Post by: K24A3 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?
Title: Re: Shaders and SetTransparency
Post by: EgonOlsen 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?
Title: Re: Shaders and SetTransparency
Post by: K24A3 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.

Title: Re: Shaders and SetTransparency
Post by: K24A3 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]
Title: Re: Shaders and SetTransparency
Post by: EgonOlsen 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?
Title: Re: Shaders and SetTransparency
Post by: K24A3 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)
Title: Re: Shaders and SetTransparency
Post by: EgonOlsen 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).
Title: Re: Shaders and SetTransparency
Post by: K24A3 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.
Title: Re: Shaders and SetTransparency
Post by: EgonOlsen on September 25, 2012, 08:45:17 pm
That would be helpful...i'm not going to debug a wallpaper... ;)