Giter Site home page Giter Site logo

Comments (3)

crykn avatar crykn commented on May 10, 2024

Which shader are you using? The library itself doesn't offer any and the GLTransitionsShaderTransition class doesn't add any constants to the shaders it is provided with:

private static final String VERT_SHADER =
"#ifdef GL_ES\n" +
"precision mediump float;\n" +
"#endif\n" +
"\n" +
"attribute vec3 a_position;\n" +
"attribute vec2 a_texCoord0;\n" +
"\n" +
"uniform mat4 u_projTrans;\n" +
"\n" +
"varying vec3 v_position;\n" +
"varying vec2 v_texCoord0;\n" +
"\n" +
"void main() {\n" +
" v_position = a_position;\n" +
" v_texCoord0 = a_texCoord0;\n" +
" gl_Position = u_projTrans * vec4(a_position, 1.0);\n" +
"}";
private static final String FRAG_SHADER_PREPEND =
"#ifdef GL_ES\n" +
"precision mediump float;\n" +
"#endif\n" +
"\n" +
"varying vec3 v_position;\n" +
"varying vec2 v_texCoord0;\n" +
"\n" +
"\n" +
"\n" +
"uniform sampler2D lastScreen;\n" +
"uniform sampler2D currScreen;\n" +
"uniform float progress;\n" +
"\n" +
"vec4 getToColor(vec2 uv) {\n" +
" return texture2D(currScreen, uv);\n" +
"}\n" +
"\n" +
"vec4 getFromColor(vec2 uv) {\n" +
" return texture2D(lastScreen, uv);\n" +
"}\n";
private static final String FRAG_SHADER_POSTPEND = "\nvoid main() {\n"
+ " gl_FragColor = transition(v_texCoord0);\n" +
"}\n";

from libgdx-screenmanager.

dkoding avatar dkoding commented on May 10, 2024

You are right.

The problem was in the following shader:

  private String circleCropText =
            "uniform vec4 bgcolor; // = vec4(0.0, 0.0, 0.0, 1.0)\n" +
                    "\n" +
                    "vec2 ratio2 = vec2(1.0, 1.0 / ratio);\n" +
                    "float s = pow(2.0 * abs(progress - 0.5), 3.0);\n" +
                    "\n" +
                    "vec4 transition(vec2 p) {\n" +
                    "  float dist = length((vec2(p) - 0.5) * ratio2);\n" +
                    "  return mix(\n" +
                    "    progress < 0.5 ? getFromColor(p) : getToColor(p), bgcolor, step(s, dist)\n" +
                    "  );\n" +
                    "}\n";

I think I found it in one of your examples?

Changing it to this:

            "uniform vec4 bgcolor; // = vec4(0.0, 0.0, 0.0, 1.0)\n" +
                    "vec4 transition(vec2 p) {\n" +
                    "  vec2 ratio2 = vec2(1.0, 1.0 / ratio);\n" +
                    "  float s = pow(2.0 * abs(progress - 0.5), 3.0);\n" +
                    "  float dist = length((vec2(p) - 0.5) * ratio2);\n" +
                    "  return mix(\n" +
                    "    progress < 0.5 ? getFromColor(p) : getToColor(p), bgcolor, step(s, dist)\n" +
                    "  );\n" +
                    "}\n";

...fixed the problem.

The shader compiler is opinionated about constants. Variables defined outside the main method are considered constants I think... So in this case ratio2 and s would be constants in the first example.

from libgdx-screenmanager.

crykn avatar crykn commented on May 10, 2024

I think global variable initializers must be constant expressions means that ratio2 and s can't use uniforms and must be constant values instead. Anyways, I mentioned on the wiki that there can be platform-specific limitations to compiling shaders.

from libgdx-screenmanager.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.