Giter VIP home page Giter VIP logo

Comments (14)

MasDennis avatar MasDennis commented on June 1, 2024

What if you try mod( vTextureCoord.y + uTime, 1.0)?
On Jun 2, 2012 6:07 PM, "lacasrac" <
[email protected]>
wrote:

I just wrote a little material, that is scrolling fromright to left

package lacroix3d.materials;

import rajawali.materials.AMaterial;
import android.opengl.GLES20;

public class ScrollLeftRightMaterial extends AMaterial {
protected int muTimeHandle;

   protected static final String mVShader =
           "uniform mat4 uMVPMatrix;\n" +

           "attribute vec4 aPosition;\n" +
           "attribute vec2 aTextureCoord;\n" +
           "attribute vec4 aColor;\n" +

           "varying vec2 vTextureCoord;\n" +
           "varying vec4 vColor;\n" +

           "void main() {\n" +
           "       gl_Position = uMVPMatrix * aPosition;\n" +
           "       vTextureCoord = aTextureCoord;\n" +
           "       vColor = aColor;\n" +
           "}\n";

   protected static final String mFShader =
           "precision mediump float;\n" +

           "varying vec2 vTextureCoord;\n" +
           "uniform sampler2D uDiffuseTexture;\n" +
           "uniform float uTime;\n" +
           "varying vec4 vColor;\n" +

           "void main() {\n" +
           "#ifdef TEXTURED\n" +
           "       gl_FragColor = texture2D(uDiffuseTexture,

vec2(vTextureCoord.x, vTextureCoord.y + uTime));\n" +
"#else\n" +
" gl_FragColor = vColor;\n" +
"#endif\n" +
"}\n";

   public ScrollLeftRightMaterial() {
           super(mVShader, mFShader, true);
           setShaders(mUntouchedVertexShader,

mUntouchedFragmentShader);
}

   public ScrollLeftRightMaterial(String vertexShader, String

fragmentShader) {
super(vertexShader, fragmentShader, true);
setShaders(mUntouchedVertexShader,
mUntouchedFragmentShader);
}

   public void setShaders(String vertexShader, String fragmentShader)
 {
           super.setShaders(vertexShader, fragmentShader);
           muTimeHandle = getUniformLocation("uTime");
   }

   public void setTime(float time) {
           GLES20.glUniform1f(muTimeHandle, time);
   }

   then:

mTime+=0.005f; planematerial.setTime(mTime);

the error: after a while the picture quality will be very bad (pixelate),
why?


Reply to this email directly or view it on GitHub:
#53

from rajawali.

 avatar commented on June 1, 2024

not work too

On Sun, Jun 3, 2012 at 6:33 AM, Dennis Ippel <
[email protected]

wrote:

What if you try mod( vTextureCoord.y + uTime, 1.0)?
On Jun 2, 2012 6:07 PM, "lacasrac" <
[email protected]>
wrote:

I just wrote a little material, that is scrolling fromright to left

package lacroix3d.materials;

import rajawali.materials.AMaterial;
import android.opengl.GLES20;

public class ScrollLeftRightMaterial extends AMaterial {
protected int muTimeHandle;

   protected static final String mVShader =
           "uniform mat4 uMVPMatrix;\n" +

           "attribute vec4 aPosition;\n" +
           "attribute vec2 aTextureCoord;\n" +
           "attribute vec4 aColor;\n" +

           "varying vec2 vTextureCoord;\n" +
           "varying vec4 vColor;\n" +

           "void main() {\n" +
           "       gl_Position = uMVPMatrix * aPosition;\n" +
           "       vTextureCoord = aTextureCoord;\n" +
           "       vColor = aColor;\n" +
           "}\n";

   protected static final String mFShader =
           "precision mediump float;\n" +

           "varying vec2 vTextureCoord;\n" +
           "uniform sampler2D uDiffuseTexture;\n" +
           "uniform float uTime;\n" +
           "varying vec4 vColor;\n" +

           "void main() {\n" +
           "#ifdef TEXTURED\n" +
           "       gl_FragColor = texture2D(uDiffuseTexture,

vec2(vTextureCoord.x, vTextureCoord.y + uTime));\n" +
"#else\n" +
" gl_FragColor = vColor;\n" +
"#endif\n" +
"}\n";

   public ScrollLeftRightMaterial() {
           super(mVShader, mFShader, true);
           setShaders(mUntouchedVertexShader,

mUntouchedFragmentShader);
}

   public ScrollLeftRightMaterial(String vertexShader, String

fragmentShader) {
super(vertexShader, fragmentShader, true);
setShaders(mUntouchedVertexShader,
mUntouchedFragmentShader);
}

   public void setShaders(String vertexShader, String fragmentShader)
 {
           super.setShaders(vertexShader, fragmentShader);
           muTimeHandle = getUniformLocation("uTime");
   }

   public void setTime(float time) {
           GLES20.glUniform1f(muTimeHandle, time);
   }

   then:

mTime+=0.005f; planematerial.setTime(mTime);

the error: after a while the picture quality will be very bad (pixelate),
why?


Reply to this email directly or view it on GitHub:
#53


Reply to this email directly or view it on GitHub:
#53 (comment)

from rajawali.

MasDennis avatar MasDennis commented on June 1, 2024

What if you change "precision mediump float;\n" + into "precision highp
float;\n" +
On Jun 3, 2012 6:58 AM, "lacasrac" <
[email protected]>
wrote:

not work too

On Sun, Jun 3, 2012 at 6:33 AM, Dennis Ippel <
[email protected]

wrote:

What if you try mod( vTextureCoord.y + uTime, 1.0)?
On Jun 2, 2012 6:07 PM, "lacasrac" <
[email protected]>
wrote:

I just wrote a little material, that is scrolling fromright to left

package lacroix3d.materials;

import rajawali.materials.AMaterial;
import android.opengl.GLES20;

public class ScrollLeftRightMaterial extends AMaterial {
protected int muTimeHandle;

   protected static final String mVShader =
           "uniform mat4 uMVPMatrix;\n" +

           "attribute vec4 aPosition;\n" +
           "attribute vec2 aTextureCoord;\n" +
           "attribute vec4 aColor;\n" +

           "varying vec2 vTextureCoord;\n" +
           "varying vec4 vColor;\n" +

           "void main() {\n" +
           "       gl_Position = uMVPMatrix * aPosition;\n" +
           "       vTextureCoord = aTextureCoord;\n" +
           "       vColor = aColor;\n" +
           "}\n";

   protected static final String mFShader =
           "precision mediump float;\n" +

           "varying vec2 vTextureCoord;\n" +
           "uniform sampler2D uDiffuseTexture;\n" +
           "uniform float uTime;\n" +
           "varying vec4 vColor;\n" +

           "void main() {\n" +
           "#ifdef TEXTURED\n" +
           "       gl_FragColor = texture2D(uDiffuseTexture,

vec2(vTextureCoord.x, vTextureCoord.y + uTime));\n" +
"#else\n" +
" gl_FragColor = vColor;\n" +
"#endif\n" +
"}\n";

   public ScrollLeftRightMaterial() {
           super(mVShader, mFShader, true);
           setShaders(mUntouchedVertexShader,

mUntouchedFragmentShader);
}

   public ScrollLeftRightMaterial(String vertexShader, String

fragmentShader) {
super(vertexShader, fragmentShader, true);
setShaders(mUntouchedVertexShader,
mUntouchedFragmentShader);
}

   public void setShaders(String vertexShader, String

fragmentShader)
{
super.setShaders(vertexShader, fragmentShader);
muTimeHandle = getUniformLocation("uTime");
}

   public void setTime(float time) {
           GLES20.glUniform1f(muTimeHandle, time);
   }

   then:

mTime+=0.005f; planematerial.setTime(mTime);

the error: after a while the picture quality will be very bad
(pixelate),
why?


Reply to this email directly or view it on GitHub:
#53


Reply to this email directly or view it on GitHub:
#53 (comment)


Reply to this email directly or view it on GitHub:
#53 (comment)

from rajawali.

 avatar commented on June 1, 2024

mTime+=0.005f; if (mTime>1) mTime-=1;

it was the issue:)

from rajawali.

 avatar commented on June 1, 2024

by the way in your code:

planematerial.setTime((System.currentTimeMillis() - mStartTime) / 1000f);

there is the issue too, so after a while, the texture pixelating...why? any solution on this?

from rajawali.

MasDennis avatar MasDennis commented on June 1, 2024

How long does it take before it gets pixelated? What device are you using?

from rajawali.

xroberx avatar xroberx commented on June 1, 2024

Hi there lacasrac, I can confirm this issue. I guess it is due to a variable overflow, right ? Simply substracting 1 when you reach 1 is not working for me though, because my custom shader depends on the value of mTime for its presentation, and when you restart the variable it gets visibly noticeable...

from rajawali.

 avatar commented on June 1, 2024

yeah, after 1.0 it will be pixelate...and pixelating MORE when the time variable just increases

SG1, SG2, Tab10.1v

from rajawali.

xroberx avatar xroberx commented on June 1, 2024

Also, it does not seem to be equally noticeable in all devices. In my SE Xperia Neo V I hardly notice the pixelation but on the LG Optimus 3D P920 it is more noticeable.

Also you think restarting the variable in java code is fixing the issue but take a look at the code you posted:
gl_FragColor = texture2D(uDiffuseTexture, vec2(vTextureCoord.x, vTextureCoord.y + uTime));\n"

Since uTime can take values between 0.0 and 1.0, and you are adding it to vTextureCoord.y (which is also normalized), the maximum value you can get is 2.0 which is not in the [0.0, 1.0] range. So, what about using clamp instead ? (i.e clamp(vTextureCoord.y + uTime, 0.0, 1.0)....

from rajawali.

 avatar commented on June 1, 2024

it is right, in this case, but what about a complex shader where you need the time bigger then 1?

plasma by the way or other things

from rajawali.

 avatar commented on June 1, 2024
protected static final String mVShader = 
    "uniform mat4 uMVPMatrix;\n" +

    "attribute vec4 aPosition;\n" +
    "attribute vec2 aTextureCoord;\n" +
    "attribute vec4 aColor;\n" +

    "varying vec2 vTextureCoord;\n" +
    "varying vec4 vColor;\n" +      

    "void main() {\n" +
    "   gl_Position = uMVPMatrix * aPosition;\n" +
    "   vTextureCoord = aTextureCoord;\n" +
    "   vColor = aColor;\n" +
    "}\n";


//
protected static final String mFShader = 
    "precision mediump float;\n" +

    "varying vec2 vTextureCoord;\n" +

    "uniform sampler2D uDiffuseTexture;\n" +
    "uniform float time;\n" +
    "uniform vec2 resolution;\n" +

    "varying vec4 vColor;\n" +

    "void main() {\n" +
    "   float x = gl_FragCoord.x;\n"+
    "   float y = gl_FragCoord.y;\n"+
    "   float mov0 = x+y+time;\n"+
    "   float mov1 = time;\n"+
    "   float mov2 = x / resolution.x / 0.2;\n"+
    "   float c1 = abs(cos(mov1+time)/2.+mov2/2.-mov1-mov2+time);\n"+
    "   float c2 = abs(sin(c1+sin(mov0/1000.+time)+cos(y/40.+time)+sin((x+y)/100.)*3.));\n"+
    "   float c3 = abs(cos(c2+cos(mov1+mov2+c2)+cos(mov2)+sin(x/1000.)));\n"+
    "   gl_FragColor = texture2D(uDiffuseTexture, vTextureCoord)*vec4(c1,c2,c3, 0.1); \n"+
    "}\n";

here is the plasma material

from rajawali.

xroberx avatar xroberx commented on June 1, 2024

I don't really know lacasrac, I just started using OpenGL a couple of months ago :)

But I think we have two problems with the timer:

1- Java float variable overflow. (We really need to restart the variable at some point because java won't do it for us. Look here: http://javapapers.com/core-java/java-overflow-and-underflow/).
2- GLSL variable overflow. This case is not a problem if we restart the counter in java before it gets to the limits of highp float.

So it seems what we need to do is restart the java time counter before it reaches the limits of a highp float (which can be seen here: http://stackoverflow.com/a/4430934)

What do you think lacasrac ?

from rajawali.

 avatar commented on June 1, 2024

Hy, I using OpenGL a while (fixed pipeline, 5-6 years ago), but shaders only a couple of weeks, so I dont know how this works.

from rajawali.

xroberx avatar xroberx commented on June 1, 2024

Hi lacasrac,

The solution seems to be to pass an uniform variable to the shader that is restarted in java when it overflows the expected range.

For example, if you expect a shader variable in the range [0, 1], restart the java variable when it reaches 1. If your shader expects a variable in the range [0, 2_PI], create another java variable that is restared when it reaches 2_PI. This is usually the case in sin/cos functions.

from rajawali.

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.