www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: lawless_c on March 09, 2016, 02:08:06 am

Title: How to set a blit shader?
Post by: lawless_c on March 09, 2016, 02:08:06 am
How and where should a shader be set for blitting?

I'm using a shader with fb.setBlittingShader but it get's ignored?

I'm trying to do this on an android device.

I'm trying to do a filtering effect kind of like this but it seems to just be ignored.

http://www.jpct.net/forum2/index.php?topic=4355.0
Title: Re: How to set a blit shader?
Post by: EgonOlsen on March 09, 2016, 08:49:22 am
It should work. At least I see no reason, why it shouldn't. Just make sure not to do this:

Code: [Select]
fb.setBlittingShader(...);
fb.blit(...);
fb.setBlittingShader(null);

That doesn't work, because blits are buffered but the shader isn't. If you need to reset the shader in the process, make sure to execute the blits before. You can force this by blitting a dummy blit from some other texture. Like:

Code: [Select]
fb.setBlittingShader(...);
fb.blit(...);
fb.blit(...); // <- Dummy-blit (1x1 transparent pixel with some other texture or something)
fb.setBlittingShader(null);
Title: Re: How to set a blit shader?
Post by: lawless_c on March 09, 2016, 11:16:25 pm
Yeah i was doing exactly what you said i shouldn't do  :P.   Got it working now though  8)

Game boy style pixelated shader.

Partially based on Lobby s here http://www.jpct.net/forum2/index.php?topic=4355.0
and this pixelation shader http://coding-experiments.blogspot.ie/2010/06/pixelation.html


(http://i.imgur.com/Do0guue.jpg)
Vertex Shader
Code: [Select]
precision lowp float;
uniform mat4 modelViewMatrix;
uniform mat4 modelViewProjectionMatrix;
uniform mat4 textureMatrix;
attribute vec4 position;
attribute vec2 texture0;
varying  lowp vec2 v_texCoord;
void main() {
v_texCoord  = (textureMatrix * vec4(texture0, 0, 1)).xy;
gl_Position = modelViewProjectionMatrix * position;
}




FragmentShader
Code: [Select]

precision lowp float;

uniform sampler2D textureUnit0;
varying  lowp vec2 v_texCoord;
//pallete
lowp vec3 lighthest  = vec3(0.61,0.74,0.06);
lowp vec3 light      = vec3(0.55,0.67,0.06);
lowp vec3 dark       = vec3(0.19,0.38,0.19);
lowp vec3 darkest    = vec3(0.06,0.22,0.06);

void main() {
    float dx = 0.005859375;//3.0*(1./512.);
    float dy = 0.00390625; //2.*(1./512.);
    vec2 coord = vec2(dx*floor(v_texCoord.x/dx),
                      dy*floor(v_texCoord.y/dy));
    vec4 col = texture2D(textureUnit0, coord);

    float ave = (col.r + col.g +col.b)/3.0;
    vec3 fin;

    if(ave < 0.25){fin =darkest;}
    if(ave >= 0.25){fin =dark;}
    if(ave >= 0.50){fin =light;}
    if(ave >= 0.75){fin =lighthest;}

gl_FragColor= vec4(fin,1.0);
}
Title: Re: How to set a blit shader?
Post by: lawless_c on March 11, 2016, 01:14:00 pm
Maybe have to update it though, shader works fine on an elephone p6000 but not on a HTC one.
Title: Re: How to set a blit shader?
Post by: EgonOlsen on March 11, 2016, 01:19:43 pm
What does it do wrong on the HTC?
Title: Re: How to set a blit shader?
Post by: lawless_c on March 11, 2016, 02:41:06 pm
screen just goes almost completely green and flickers. It doesn't crash. The HTC uses an Adreno GPU , whereas the ellephone p6000 uses a Mali one, that could be the issue.

Title: Re: How to set a blit shader?
Post by: lawless_c on March 11, 2016, 02:43:31 pm
I'll try later again when  i'm at home.
Title: Re: How to set a blit shader?
Post by: EgonOlsen on March 11, 2016, 02:59:51 pm
Adreno usually isn't a troublemaker in that regard...strange. My first try would be to up all low precision settings to high or at least medium to see if that helps.
Title: Re: How to set a blit shader?
Post by: lawless_c on March 16, 2016, 01:14:45 am
No that doesn't seem to be it. It does cause a weird visual echoing effect though i've noticed of things that should be drawn above it.
Title: Re: How to set a blit shader?
Post by: EgonOlsen on March 16, 2016, 09:31:04 am
Sounds like a depth buffer issue of some kind...
Title: Re: How to set a blit shader?
Post by: lawless_c on April 20, 2016, 04:02:39 pm
OK tried the app now

On a samsung s6 It works fine .
IT works fine on the elephone p6000

Both of these use Mali chips

On HTC the shader gets messed up , it doesn't crash.
What i have noticed is it causes a repeating effect on some ui elements that should be drawn after the shader had even been used.

This is an Adreno chip, probably 330
Title: Re: How to set a blit shader?
Post by: EgonOlsen on April 20, 2016, 08:25:21 pm
The shader itself looks fine to me. But you never know. Some shader compilers compile some shaders to crap even if there are actually correct.
It's hard to tell...do you have a test case to reproduce it? I've several Adreno based devices as well as PowerVR, Nvidia and Intel based ones to test it on.
Title: Re: How to set a blit shader?
Post by: EgonOlsen on April 20, 2016, 10:28:10 pm
Try this jar to see if it changes something: http://jpct.de/download/beta/jpct_ae.jar (http://jpct.de/download/beta/jpct_ae.jar)

There was small problem with setting the blitting shader correctly in some cases, but I'm not sure if it applies here. Anyway, it's worth a try.
Title: Re: How to set a blit shader?
Post by: lawless_c on April 22, 2016, 01:24:36 am
Tried that out , the shader still comes out messy on the adreno device.

However it also seems to get loaded before i chose to use it with this version. so things have a little green tint. which disappears when activate and then deactivate the blitter shader.


I'll work on a simple program to demo it. The shader does run, it just comes out messed up on that one device.
Title: Re: How to set a blit shader?
Post by: EgonOlsen on April 22, 2016, 08:33:00 am
However it also seems to get loaded before i chose to use it with this version. so things have a little green tint. which disappears when activate and then deactivate the blitter shader.
No, it actually can't. The only place that activates the blitting shader is the blitting...something is fishy here...
Title: Re: How to set a blit shader?
Post by: lawless_c on May 13, 2016, 05:02:00 pm
yeah i had accidentally pasted the code setting that shader to the blitter on startup. So that oddity doesn't happen.