Ripple Effect

  ... discussions about development with the GLES1 branch of AndEngine.

Ripple Effect

Postby siddharth3322 » Fri Jan 18, 2013 8:15 pm

I was developing tower of defense game for a long time.
It was about to complete but I have to create ripple effect for one of the weapon that I have used.

I don't able to think what I have to do for ripple effect that affect enemy wave.

So anybody have an idea then please share with me.

Thank for your kind support.
siddharth3322
 
Posts: 243
Joined: Thu Jan 03, 2013 10:10 am

Re: Ripple Effect

Postby thepi » Fri Jan 18, 2013 9:36 pm

gles2-shaderprograms/ripple-shader-t6150.html

EDIT: Sorry, I missed (again :oops: ) this is GLES1. I believe shaders work on GLES2 only.
Go and trap them... Trap Balls on Google Play
Play & reminisce... Treasure Island LCD Retro
thepi
 
Posts: 456
Joined: Sun Oct 09, 2011 9:30 pm

Re: Ripple Effect

Postby ViktorS » Sat Jan 19, 2013 2:10 am

I believe this question was asked on this forum several times, and I have never seen it resolved. It's just too much trouble for anyone to actually bother with this. Even though it should be possible by the means of OpenGL. The implementations I've seen of this for android using OpenGL ES1, were not good enough to bother to port for andengine. So please kindly rethink this choice. Even if you do manage to port it, I'm quite sure extensive rippling effects will lag as hell.
'Javelin OU' presents, my latest game - Joj the alien
ViktorS
 
Posts: 580
Joined: Thu Oct 27, 2011 2:18 pm

Re: Ripple Effect

Postby Siddharth » Sat Jan 19, 2013 5:12 am

thepi wrote:http://www.andengine.org/forums/gles2-shaderprograms/ripple-shader-t6150.html

EDIT: Sorry, I missed (again :oops: ) this is GLES1. I believe shaders work on GLES2 only.


If I port my game to GLES2 then this suggested example work for as weapon effect or not?
I was ready to convert my game into GLES2.

Please suggest me on this.
User avatar
Siddharth
 
Posts: 272
Joined: Thu May 03, 2012 12:11 pm
Location: Rajkot

Re: Ripple Effect

Postby ViktorS » Sat Jan 19, 2013 1:53 pm

Well if you don't mind ditching all gles2 incapable devices, I don't see why not.
'Javelin OU' presents, my latest game - Joj the alien
ViktorS
 
Posts: 580
Joined: Thu Oct 27, 2011 2:18 pm

Re: Ripple Effect

Postby Siddharth » Fri Feb 08, 2013 2:11 pm

I have created a ripple effect based on above suggestion.
But it was in live wall paper.

So I want to ask that is it possible that I can create same effect in normal activity?
And also is it feasible to apply ripple effect for weapon?

I was not able to understand many things from it. If any one has some knowledge on this then please provide.

I was developing another tower of defence type game.
User avatar
Siddharth
 
Posts: 272
Joined: Thu May 03, 2012 12:11 pm
Location: Rajkot

Re: Ripple Effect

Postby Siddharth » Wed Feb 13, 2013 7:16 pm

I finally decide to set as bounty to this question.
I hope I get some useful outcome from this and I definitely share this thing with you guys.

http://gamedev.stackexchange.com/questions/48973/programmatically-and-efficiently-create-a-graphical-ripple-effect
User avatar
Siddharth
 
Posts: 272
Joined: Thu May 03, 2012 12:11 pm
Location: Rajkot

Re: Ripple Effect

Postby thepi » Wed Feb 13, 2013 10:30 pm

I successfully used this shader with a GLES2 game. If you're interested exactly how, I'll have to dig a little bit, since it was a while ago.
It is true however, it dramatically reduces fps, so I suggest for an action game like defense, better use animated ripple sprite.
Go and trap them... Trap Balls on Google Play
Play & reminisce... Treasure Island LCD Retro
thepi
 
Posts: 456
Joined: Sun Oct 09, 2011 9:30 pm

Re: Ripple Effect

Postby siddharth3322 » Thu Feb 14, 2013 7:15 am

thepi wrote:I successfully used this shader with a GLES2 game. If you're interested exactly how, I'll have to dig a little bit, since it was a while ago.
It is true however, it dramatically reduces fps, so I suggest for an action game like defense, better use animated ripple sprite.


Thanks for your support.
Now you have to do this stuff for not me but also for lots of other users.
This problem cost my lot of time so I any how want this effect to work. I know this effect creates a lot of load. But now my sole purpose is to create this effect.

The thing does not matter you create it for GLES1 or GLES2.

Please do something for this.
siddharth3322
 
Posts: 243
Joined: Thu Jan 03, 2013 10:10 am

Re: Ripple Effect

Postby thepi » Tue Feb 19, 2013 12:46 am

This is how it works on GLES2.
The shader extends through whole screen. You need to tweak it for custom radius.

This code goes into main class/activity:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. private float mShockwaveTime = 0f;
  2.  
  3.  
  4. @Override
  5. public Engine onCreateEngine(final EngineOptions pEngineOptions) {
  6.         return new Engine(pEngineOptions) {
  7.                 private boolean mRenderTextureInitialized;
  8.  
  9.                 private RenderTexture mRenderTexture;
  10.                 private UncoloredSprite mRenderTextureSprite;
  11.                
  12.                 @Override
  13.                 public void onDrawFrame(GLState pGLState)
  14.                                 throws InterruptedException {
  15.                        
  16.                         if (mShockwaveTime > 0f && mShockwaveTime < 10f) {
  17.                                
  18.                                 if (!mRenderTextureInitialized) {
  19.                                         initRenderTexture(pGLState);
  20.                                         mRenderTextureInitialized = true;
  21.                                 }
  22.                                
  23.                                 mRenderTexture.begin(pGLState, false, true, Color.TRANSPARENT);
  24.                                 {              
  25.                                         super.onDrawFrame(pGLState);
  26.                                 }
  27.                                 mRenderTexture.end(pGLState);
  28.                                                                
  29.                                 pGLState.pushProjectionGLMatrix();
  30.                                 pGLState.orthoProjectionGLMatrixf(0, CAMERA_WIDTH, 0, CAMERA_HEIGHT, -1, 1);
  31.                                 {
  32.                                         mRenderTextureSprite.onDraw(pGLState, mCamera);
  33.                                 }
  34.                                 pGLState.popProjectionGLMatrix();      
  35.                         } else {
  36.                                 super.onDrawFrame(pGLState);
  37.                         }
  38.                 }
  39.                
  40.                 private void initRenderTexture(GLState pGLState) {
  41.                         mRenderTexture = new RenderTexture(getTextureManager(), mCamera.getSurfaceWidth(), mCamera.getSurfaceHeight(), PixelFormat.RGBA_4444);
  42.                         mRenderTexture.init(pGLState);
  43.                         mRenderTextureSprite = new UncoloredSprite(0f, 0f, TextureRegionFactory.extractFromTexture(mRenderTexture), getVertexBufferObjectManager()) {
  44.                                 @Override
  45.                                 protected void preDraw(GLState pGLState, Camera pCamera) {
  46.                                         super.preDraw(pGLState, pCamera);
  47.                                         if (mShockwaveTime > 0f && mShockwaveTime < 10f) GLES20.glUniform1f(ShockwaveShaderProgram.sUniformTimeLocation, mShockwaveTime);
  48.                                 }
  49.                         };
  50.                         mRenderTextureSprite.setShaderProgram(ShockwaveShaderProgram.getInstance());                           
  51.                 }
  52.         };
  53. }
Parsed in 0.037 seconds, using GeSHi 1.0.8.4


This line goes inside onLoadResources:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. this.getShaderProgramManager().loadShaderProgram(ShockwaveShaderProgram.getInstance());
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


I put shader class code to the end of my main class:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public static class ShockwaveShaderProgram extends ShaderProgram {
  2.        
  3.         private static ShockwaveShaderProgram instance;
  4.        
  5.         public static ShockwaveShaderProgram getInstance() {
  6.                 if (instance == null) instance = new ShockwaveShaderProgram();
  7.                 return instance;
  8.         }
  9.                        
  10.         public static final String FRAGMENTSHADER =
  11.         "precision lowp float;\n" +
  12.  
  13.         "uniform lowp sampler2D " + ShaderProgramConstants.UNIFORM_TEXTURE_0 + ";\n" +
  14.         "varying mediump vec2 " + ShaderProgramConstants.VARYING_TEXTURECOORDINATES + ";\n" +
  15.        
  16.         "uniform vec2 center;\n" +
  17.         "uniform float time;\n" +
  18.         "const vec3 params = vec3(10.0, 0.8, 0.02);\n" +
  19.  
  20.         "void main()    \n" +
  21.         "{                              \n" +
  22.         "       mediump vec2 texCoord = " + ShaderProgramConstants.VARYING_TEXTURECOORDINATES + ";\n" +
  23.         "       float distance = distance(texCoord, center);\n" +
  24.         "       if ( (distance <= (time + params.z)) && (distance >= (time - params.z)) )\n" +
  25.         "       {\n" +         
  26.         "               float diff = (distance - time);\n" +
  27.         "               float powDiff = 1.0 - pow(abs(diff*params.x), params.y);\n" +
  28.         "               float diffTime = diff  * powDiff;\n" +
  29.         "               vec2 diffUV = normalize(texCoord - center);\n" +
  30.         "               texCoord = texCoord + (diffUV * diffTime);\n" +
  31.         "       }\n" +
  32.         "       gl_FragColor = texture2D(" + ShaderProgramConstants.UNIFORM_TEXTURE_0 + ", texCoord);\n" +
  33.         "}              \n";
  34.  
  35.          
  36.         private ShockwaveShaderProgram() {
  37.                 super(PositionTextureCoordinatesShaderProgram.VERTEXSHADER, FRAGMENTSHADER);
  38.         }
  39.        
  40.         public static int sUniformModelViewPositionMatrixLocation = ShaderProgramConstants.LOCATION_INVALID;
  41.         public static int sUniformTexture0Location = ShaderProgramConstants.LOCATION_INVALID;
  42.         public static int sUniformCenterLocation = ShaderProgramConstants.LOCATION_INVALID;
  43.         public static int sUniformTimeLocation = ShaderProgramConstants.LOCATION_INVALID;
  44.        
  45.         @Override
  46.         protected void link(final GLState pGLState) throws ShaderProgramLinkException {
  47.                 GLES20.glBindAttribLocation(this.mProgramID, ShaderProgramConstants.ATTRIBUTE_POSITION_LOCATION, ShaderProgramConstants.ATTRIBUTE_POSITION);
  48.                 GLES20.glBindAttribLocation(this.mProgramID, ShaderProgramConstants.ATTRIBUTE_TEXTURECOORDINATES_LOCATION, ShaderProgramConstants.ATTRIBUTE_TEXTURECOORDINATES);
  49.  
  50.                 super.link(pGLState);
  51.  
  52.                 ShockwaveShaderProgram.sUniformModelViewPositionMatrixLocation = this.getUniformLocation(ShaderProgramConstants.UNIFORM_MODELVIEWPROJECTIONMATRIX);
  53.                 ShockwaveShaderProgram.sUniformTexture0Location = this.getUniformLocation(ShaderProgramConstants.UNIFORM_TEXTURE_0);
  54.                 ShockwaveShaderProgram.sUniformCenterLocation = this.getUniformLocation("center");
  55.                 ShockwaveShaderProgram.sUniformTimeLocation = this.getUniformLocation("time");
  56.         }
  57.        
  58.         @Override
  59.         public void bind(final GLState pGLState, final VertexBufferObjectAttributes pVertexBufferObjectAttributes) {
  60.                 GLES20.glDisableVertexAttribArray(ShaderProgramConstants.ATTRIBUTE_COLOR_LOCATION);
  61.                 super.bind(pGLState, pVertexBufferObjectAttributes);
  62.                 GLES20.glUniformMatrix4fv(ShockwaveShaderProgram.sUniformModelViewPositionMatrixLocation, 1, false, pGLState.getModelViewProjectionGLMatrix(), 0);
  63.                 GLES20.glUniform1i(ShockwaveShaderProgram.sUniformTexture0Location, 0);
  64.                 GLES20.glUniform2f(ShockwaveShaderProgram.sUniformCenterLocation, 0.5f, 0.5f);
  65.         }
  66.  
  67.  
  68.         @Override
  69.         public void unbind(final GLState pGLState) throws ShaderProgramException {
  70.                 GLES20.glEnableVertexAttribArray(ShaderProgramConstants.ATTRIBUTE_COLOR_LOCATION);
  71.                 super.unbind(pGLState);
  72.         }
  73. }
Parsed in 0.047 seconds, using GeSHi 1.0.8.4


Put this code where you want to trigger it:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. mScene.registerUpdateHandler(new TimerHandler(0.08f, true, new ITimerCallback() {
  2.         @Override
  3.         public void onTimePassed(TimerHandler pTimerHandler) {
  4.                 mShockwaveTime += 0.02f;
  5.                 if (mShockwaveTime > 1.2f) {
  6.                         mScene.unregisterUpdateHandler(pTimerHandler);
  7.                         mShockwaveTime = 0.0f;
  8.                 }
  9.         }
  10. }));
Parsed in 0.036 seconds, using GeSHi 1.0.8.4
Go and trap them... Trap Balls on Google Play
Play & reminisce... Treasure Island LCD Retro
thepi
 
Posts: 456
Joined: Sun Oct 09, 2011 9:30 pm

Next

Return to GLES1

Who is online

Users browsing this forum: No registered users and 9 guests