Liquid Fun - Box2D became even better - SUCCEED !!!

  ... the case you feel the need for a new feature or want to submit one.

Re: Liquid Fun - Box2D became even better - SUCCEED !!!

Postby GForce » Tue Apr 22, 2014 12:53 pm

How do you draw the particles directly from position buffer? I tried running gl code from native and not from java, but that coused everything to crash what is actually kind of strange...
To handle this PIXEL TO METER RATIO you need to scale your projection matrix by this value even before passing it to the shader. And of cause you need to scale the point size by this value.
GForce
 
Posts: 10
Joined: Mon Mar 19, 2012 2:39 pm

Re: Liquid Fun - Box2D became even better - SUCCEED !!!

Postby valka » Wed Apr 23, 2014 1:44 am

so after a couple of white nights and a lot of help from GForce, that's what we've got:
on the top - SpriteBatch
on the bottom - Mesh with shader (1st step from GForce's render method)
Image
I consider the lg optimus 3d to be pretty low end device, its something between galaxy s1 and s2.
on nexus 5 both works great and on bluestacks i have 60-59.9fps.

next task should be applying threshold on that water :) .. we'll leave that for another day..

here is the code:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package Object;
  2.  
  3. import java.nio.FloatBuffer;
  4. import java.util.Random;
  5.  
  6. import org.andengine.engine.camera.Camera;
  7. import org.andengine.engine.camera.ZoomCamera;
  8. import org.andengine.entity.Entity;
  9. import org.andengine.entity.primitive.Mesh;
  10. import org.andengine.entity.primitive.Rectangle;
  11. import org.andengine.entity.primitive.TexturedMesh;
  12. import org.andengine.entity.primitive.TexturedMesh.DrawMode;
  13. import org.andengine.entity.primitive.TexturedMesh.HighPerformanceTexturedMeshVertexBufferObject;
  14. import org.andengine.entity.primitive.TexturedMesh.ITexturedMeshVertexBufferObject;
  15. import org.andengine.entity.shape.Shape;
  16. import org.andengine.extension.physics.box2d.util.constants.PhysicsConstants;
  17. import org.andengine.opengl.shader.PositionColorShaderProgram;
  18. import org.andengine.opengl.shader.PositionColorTextureCoordinatesShaderProgram;
  19. import org.andengine.opengl.shader.PositionTextureCoordinatesShaderProgram;
  20. import org.andengine.opengl.shader.ShaderProgram;
  21. import org.andengine.opengl.shader.constants.ShaderProgramConstants;
  22. import org.andengine.opengl.shader.exception.ShaderProgramException;
  23. import org.andengine.opengl.shader.exception.ShaderProgramLinkException;
  24. import org.andengine.opengl.shader.source.IShaderSource;
  25. import org.andengine.opengl.shader.source.StringShaderSource;
  26. import org.andengine.opengl.texture.ITexture;
  27. import org.andengine.opengl.texture.region.ITextureRegion;
  28. import org.andengine.opengl.util.GLState;
  29. import org.andengine.opengl.vbo.DrawType;
  30. import org.andengine.opengl.vbo.HighPerformanceVertexBufferObject;
  31. import org.andengine.opengl.vbo.IVertexBufferObject;
  32. import org.andengine.opengl.vbo.VertexBufferObjectManager;
  33. import org.andengine.opengl.vbo.attribute.VertexBufferObjectAttribute;
  34. import org.andengine.opengl.vbo.attribute.VertexBufferObjectAttributes;
  35. import org.andengine.opengl.vbo.attribute.VertexBufferObjectAttributesBuilder;
  36. import org.andengine.util.adt.color.Color;
  37. import org.andengine.util.debug.Debug;
  38. import org.andengine.util.system.SystemUtils;
  39.  
  40. import com.badlogic.gdx.physics.box2d.liquidfun.ParticleSystem;
  41.  
  42. import android.opengl.GLES20;
  43.  
  44.  
  45. public class WaterMesh extends Shape{
  46.        
  47.         // ===========================================================
  48.         // Constants
  49.         // ===========================================================
  50.  
  51.         public static final int VERTEX_INDEX_X = 0;
  52.         public static final int VERTEX_INDEX_Y = TexturedMesh.VERTEX_INDEX_X + 1;
  53.  
  54.         public static final int VERTEX_SIZE = 2;
  55.  
  56.         public static final VertexBufferObjectAttributes VERTEXBUFFEROBJECTATTRIBUTES_DEFAULT = new VertexBufferObjectAttributesBuilder(1)
  57.                 .add(ShaderProgramConstants.ATTRIBUTE_POSITION_LOCATION, ShaderProgramConstants.ATTRIBUTE_POSITION, 2, GLES20.GL_FLOAT, false)
  58.                 .build();
  59.  
  60.         // ===========================================================
  61.         // Fields
  62.         // ===========================================================
  63.  
  64.         protected final IWaterMeshVertexBufferObject mWaterMeshBufferObject;
  65.         private int mDrawMode;
  66.         private ParticleSystem mLiquidFunParticleSystem;
  67.         protected ITextureRegion mTextureRegion;
  68.         // ===========================================================
  69.         // Constructors
  70.         // ===========================================================
  71.  
  72.         /**
  73.          * Uses a default {@link HighPerformanceTexturedMeshVertexBufferObject} in {@link DrawType#STATIC} with the {@link VertexBufferObjectAttribute}s: {@link Mesh#VERTEXBUFFEROBJECTATTRIBUTES_DEFAULT}.
  74.          */
  75.         public WaterMesh(final ParticleSystem pLiquidFunParticleSystem, final VertexBufferObjectManager pVertexBufferObjectManager) {
  76.                 this(pLiquidFunParticleSystem, null, pVertexBufferObjectManager, DrawType.STATIC);
  77.         }
  78.  
  79.         /**
  80.          * Uses a default {@link HighPerformanceTexturedMeshVertexBufferObject} in {@link DrawType#STATIC} with the {@link VertexBufferObjectAttribute}s: {@link Mesh#VERTEXBUFFEROBJECTATTRIBUTES_DEFAULT}.
  81.          */
  82.         public WaterMesh(final ParticleSystem pLiquidFunParticleSystem, final ITextureRegion pTextureRegion, final VertexBufferObjectManager pVertexBufferObjectManager) {
  83.                 this(pLiquidFunParticleSystem, pTextureRegion, pVertexBufferObjectManager, DrawType.STATIC);
  84.         }
  85.  
  86.         /**
  87.          * Uses a default {@link HighPerformanceTexturedMeshVertexBufferObject} with the {@link VertexBufferObjectAttribute}s: {@link Mesh#VERTEXBUFFEROBJECTATTRIBUTES_DEFAULT}.
  88.          */
  89.         public WaterMesh(final ParticleSystem pLiquidFunParticleSystem, final VertexBufferObjectManager pVertexBufferObjectManager, final DrawType pDrawType) {
  90.                 this(pLiquidFunParticleSystem, null, pVertexBufferObjectManager, pDrawType);
  91.         }
  92.  
  93.         /**
  94.          * Uses a default {@link HighPerformanceTexturedMeshVertexBufferObject} with the {@link VertexBufferObjectAttribute}s: {@link Mesh#VERTEXBUFFEROBJECTATTRIBUTES_DEFAULT}.
  95.          */
  96.         public WaterMesh(final ParticleSystem pLiquidFunParticleSystem, final ITextureRegion pTextureRegion, final VertexBufferObjectManager pVertexBufferObjectManager, final DrawType pDrawType) {
  97.                 this(pLiquidFunParticleSystem, pTextureRegion, new HighPerformanceWaterMeshVertexBufferObject(pVertexBufferObjectManager, pLiquidFunParticleSystem.getParticlePositionBufferArray(true), (int)pLiquidFunParticleSystem.getMaxParticleCount(), pDrawType, true, WaterMesh.VERTEXBUFFEROBJECTATTRIBUTES_DEFAULT));
  98.         }
  99.  
  100.         public WaterMesh(final ParticleSystem pLiquidFunParticleSystem, final ITextureRegion pTextureRegion, final IWaterMeshVertexBufferObject pMeshVertexBufferObject) {
  101.                 super(0, 0,PositionColorTextureCoordinatesShaderProgram.getInstance());
  102.  
  103.                 this.mDrawMode = GLES20.GL_POINTS;
  104.                 this.mTextureRegion = pTextureRegion;
  105.                 this.mWaterMeshBufferObject = pMeshVertexBufferObject;
  106.                 this.mLiquidFunParticleSystem = pLiquidFunParticleSystem;
  107.                
  108.                 if( pTextureRegion != null)
  109.                 {
  110.                         this.setBlendingEnabled(true);
  111.                         this.initBlendFunction(pTextureRegion);
  112.                         //this.onUpdateTextureCoordinates();
  113.                 }
  114.  
  115.                 this.onUpdateVertices();
  116.                 this.onUpdateColor();
  117.  
  118.                 this.mWaterMeshBufferObject.setDirtyOnHardware();
  119.  
  120.                 this.setBlendingEnabled(true);
  121.                
  122.                 this.setShaderProgram(WaterShaderProgram.getInstance());
  123.                 WaterShaderProgram.getInstance().setParticleSize(mLiquidFunParticleSystem.getParticleRadius() * PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT * 4f);
  124.         }
  125.  
  126.         // ===========================================================
  127.         // Getter & Setter
  128.         // ===========================================================
  129.  
  130.         public float[] getBufferData() {
  131.                 return this.mWaterMeshBufferObject.getBufferData();
  132.         }
  133.  
  134.         public ITextureRegion getTextureRegion() {
  135.                 return this.mTextureRegion;
  136.         }
  137.        
  138.         public void setZoomCamera(final ZoomCamera pZoomCamera) {
  139.                 WaterShaderProgram.getInstance().setZoomCamera(pZoomCamera);
  140.         }
  141.  
  142.         // ===========================================================
  143.         // Methods for/from SuperClass/Interfaces
  144.         // ===========================================================
  145.  
  146.         @Override
  147.         public IWaterMeshVertexBufferObject getVertexBufferObject() {
  148.                 return this.mWaterMeshBufferObject;
  149.         }
  150.  
  151.         @Override
  152.         public void reset() {
  153.                 super.reset();
  154.                 this.initBlendFunction(this.getTextureRegion().getTexture());
  155.         }
  156.  
  157.         @Override
  158.         protected void preDraw(final GLState pGLState, final Camera pCamera) {
  159.                 super.preDraw(pGLState, pCamera);
  160.                 //pGLState.lineWidth(10f);
  161.                 GLES20.glEnable(0x8642);
  162.                 GLES20.glEnable(0x8861);
  163.                 //GLES20.glHint(GLES20.GL_SM, mode);
  164.                 this.mWaterMeshBufferObject.onUpdateVertices(mLiquidFunParticleSystem.getParticlePositionBufferArray(true));
  165.                 //this.mTextureRegion.getTexture().bind(pGLState);
  166.                 this.mWaterMeshBufferObject.bind(pGLState, this.mShaderProgram);
  167.         }
  168.  
  169.         @Override
  170.         protected void draw(final GLState pGLState, final Camera pCamera) {
  171.                 this.mWaterMeshBufferObject.draw(this.mDrawMode, this.mLiquidFunParticleSystem.getParticleCount());
  172.         }
  173.  
  174.         @Override
  175.         protected void postDraw(final GLState pGLState, final Camera pCamera) {
  176.                 this.mWaterMeshBufferObject.unbind(pGLState, this.mShaderProgram);
  177.                 super.postDraw(pGLState, pCamera);
  178.         }
  179.  
  180.         @Override
  181.         protected void onUpdateColor() {
  182.                 //this.mWaterMeshBufferObject.onUpdateColor(this);
  183.         }
  184.  
  185.         @Override
  186.         protected void onUpdateVertices() {
  187.                
  188.         }
  189.         /*protected void onUpdateTextureCoordinates() {
  190.                 this.mWaterMeshBufferObject.onUpdateTextureCoordinates(this);
  191.         }*/
  192.  
  193.         // ===========================================================
  194.         // Methods
  195.         // ===========================================================
  196.        
  197.         // ===========================================================
  198.         // Inner and Anonymous Classes
  199.         // ===========================================================
  200.  
  201.         public static interface IWaterMeshVertexBufferObject extends IVertexBufferObject {
  202.                 public float[] getBufferData();
  203.                 //public void onUpdateColor(final WaterMesh pMesh);
  204.                 public void onUpdateVertices(final float[] pNewBuffer);
  205.                 //public void onUpdateTextureCoordinates(final WaterMesh pMesh);
  206.         }
  207.  
  208.         public static class HighPerformanceWaterMeshVertexBufferObject extends HighPerformanceVertexBufferObject implements IWaterMeshVertexBufferObject {
  209.  
  210.                 protected float[] mBufferData;
  211.                 protected FloatBuffer mFloatBuffer;
  212.                 private int mVertexCount;
  213.                
  214.                 public HighPerformanceWaterMeshVertexBufferObject(final VertexBufferObjectManager pVertexBufferObjectManager, final float[] pBufferData, final int pVertexCount, final DrawType pDrawType, final boolean pAutoDispose, final VertexBufferObjectAttributes pVertexBufferObjectAttributes) {
  215.                         super(pVertexBufferObjectManager, pBufferData, pDrawType, pAutoDispose, pVertexBufferObjectAttributes);
  216.                         this.mVertexCount = pVertexCount;
  217.                 }
  218.  
  219.                 @Override
  220.                 public void onUpdateVertices(final float[] pNewBuffer) {
  221.                         if(this.mBufferData!=pNewBuffer) this.mBufferData = pNewBuffer;
  222.                         this.setDirtyOnHardware();
  223.                 }
  224.         }
  225.        
  226.         public static class WaterShaderProgram extends ShaderProgram {
  227.                 // ===========================================================
  228.                 // Constants
  229.                 // ===========================================================
  230.  
  231.                 private static WaterShaderProgram INSTANCE;
  232.  
  233.                 public static final String VERTEXSHADER =
  234.                                 "uniform mat4 " + ShaderProgramConstants.UNIFORM_MODELVIEWPROJECTIONMATRIX + ";\n" +
  235.                                 "attribute vec4 " + ShaderProgramConstants.ATTRIBUTE_POSITION + ";\n" +
  236.                                 "uniform float particlesize;\n" +
  237.                                 "uniform float scale;\n" +
  238.                                 "void main() {\n" +
  239.                                 "       gl_Position = " + ShaderProgramConstants.UNIFORM_MODELVIEWPROJECTIONMATRIX + " * " + ShaderProgramConstants.ATTRIBUTE_POSITION + ";\n" +
  240.                                 "   gl_PointSize = scale * particlesize;\n" +
  241.                                 "}";
  242.  
  243.                 public static final String FRAGMENTSHADER = "#ifdef GL_ES\n" //
  244.                               + "#define LOWP lowp\n" //
  245.                               + "precision mediump float;\n" //
  246.                               + "#else\n" //
  247.                               + "#define LOWP \n" //
  248.                               + "#endif\n" //
  249.                                         + "void main()\n"//
  250.                                         + "{\n" //
  251.                                         + " float len = length(vec2(gl_PointCoord.x - 0.5, gl_PointCoord.y - 0.5));\n" //
  252.                                         + " if(len <= 0.5) {\n" //
  253.                                         + "     gl_FragColor = vec4(" + 0 + "," + 0.635f + "," + 1 + ", 1.0 * (1.0 - len * 1.8));\n"//
  254.                                         + " } else {\n" //
  255.                                         + "     gl_FragColor = vec4(" + 0 + "," + 0.635f + "," + 1 + ", 0);\n" //
  256.                                         + " }\n" //
  257.                                         + "}";
  258.  
  259.                 // ===========================================================
  260.                 // Fields
  261.                 // ===========================================================
  262.  
  263.                 public static int sUniformModelViewPositionMatrixLocation = ShaderProgramConstants.LOCATION_INVALID;
  264.                 private int scaleLocation, particleSizeLocation;
  265.  
  266.                 private float mParticleSize = 1.0f;
  267.                 private float mParticleScale = 1.0f;
  268.                 private ZoomCamera mZoomCamera; //TODO: something smarter
  269.  
  270.                 // ===========================================================
  271.                 // Constructors
  272.                 // ===========================================================
  273.  
  274.                 private WaterShaderProgram() {
  275.                         super(WaterShaderProgram.VERTEXSHADER, WaterShaderProgram.FRAGMENTSHADER);
  276.                 }
  277.  
  278.                 public static WaterShaderProgram getInstance() {
  279.                         if (WaterShaderProgram.INSTANCE == null) {
  280.                                 WaterShaderProgram.INSTANCE = new WaterShaderProgram();
  281.                         }
  282.                         return WaterShaderProgram.INSTANCE;
  283.                 }
  284.  
  285.                 // ===========================================================
  286.                 // Getter & Setter
  287.                 // ===========================================================
  288.  
  289.                
  290.                
  291.                 public void setParticleSize(final float pParticleSize) {
  292.                         mParticleSize = pParticleSize;
  293.                 }
  294.                
  295.                 public void setZoomCamera(final ZoomCamera pZoomCamera) {//TODO: something smarter
  296.                         mZoomCamera = pZoomCamera;
  297.                 }
  298.                
  299.                 // ===========================================================
  300.                 // Methods for/from SuperClass/Interfaces
  301.                 // ===========================================================
  302.  
  303.                 @Override
  304.                 protected void link(final GLState pGLState) throws ShaderProgramLinkException {
  305.                         GLES20.glBindAttribLocation(this.mProgramID, ShaderProgramConstants.ATTRIBUTE_POSITION_LOCATION,
  306.  
  307.                         ShaderProgramConstants.ATTRIBUTE_POSITION);
  308.                                                                
  309.                         super.link(pGLState);
  310.  
  311.                         sUniformModelViewPositionMatrixLocation = getUniformLocation(ShaderProgramConstants.UNIFORM_MODELVIEWPROJECTIONMATRIX);
  312.                         scaleLocation = getUniformLocation("scale");
  313.                         particleSizeLocation = getUniformLocation("particlesize");
  314.                 }
  315.                
  316.                 @Override
  317.                 public void bind(final GLState pGLState, final VertexBufferObjectAttributes pVertexBufferObjectAttributes) {
  318.                         //GLES20.glDisableVertexAttribArray(ShaderProgramConstants.ATTRIBUTE_TEXTURECOORDINATES_LOCATION);
  319.  
  320.                         super.bind(pGLState, pVertexBufferObjectAttributes);
  321.                        
  322.                         float[] cameraMatrix = pGLState.getModelViewProjectionGLMatrix();
  323.                         cameraMatrix[0] = cameraMatrix[0] * PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT;
  324.                         cameraMatrix[5] = cameraMatrix[5] * PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT;
  325.                         cameraMatrix[10] = cameraMatrix[10] * PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT;
  326.                        
  327.                         GLES20.glUniformMatrix4fv(sUniformModelViewPositionMatrixLocation, 1, false, cameraMatrix, 0);
  328.                         GLES20.glUniform1f(particleSizeLocation, mParticleSize);
  329.                         if(mZoomCamera!=null) GLES20.glUniform1f(scaleLocation, mZoomCamera.getZoomFactor());//TODO: something smarter
  330.                         else GLES20.glUniform1f(scaleLocation, 1f);
  331.                 }
  332.  
  333.                 @Override
  334.                 public void unbind(final GLState pGLState) {
  335.                         //GLES20.glEnableVertexAttribArray(ShaderProgramConstants.ATTRIBUTE_TEXTURECOORDINATES_LOCATION);
  336.  
  337.                         super.unbind(pGLState);
  338.                 }
  339.         }
  340. }
  341.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


to attach it you call
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.             //WaterMesh test
  2.             final WaterMesh waterMesh = new WaterMesh(liquidFunParticleSystem, ResourcesManager.getInstance().vbom);
  3.             waterMesh.setZoomCamera(ResourcesManager.getInstance().camera); // this is not a must, only you you use zoom camera...
  4.             waterLayer.attachChild(waterMesh);
  5.  
Parsed in 0.011 seconds, using GeSHi 1.0.8.4


after applying threshold it should get this effect:
http://www.emanueleferonato.com/2012/05 ... d-filters/

and after that a bevel filter will make it look almost real :) :)
http://caffeinatednightmare.com/blog/wa ... verywhere/
User avatar
valka
 
Posts: 97
Joined: Tue Aug 13, 2013 3:17 pm

Re: Liquid Fun - Box2D became even better - SUCCEED !!!

Postby GForce » Wed Apr 23, 2014 7:57 pm

Nice to see that it works now :)
Next we have to implement the step shader (or smoothstep, depending on what kind of result you want to get).
I'm sorry I have no time to do this at the moment but I can explain you in general what you have to do:
Andengine got this RenderTexture class and it seems to be a FrameBuffer just with an other name.
So you need one object of these and you have to call begin() somewhere inside the preDraw() method of the FIRST shader (so the shader you already implemented) and end() inside the postDraw(). You should use the begin() call with a (0, 0, 0, 0) clear color.
After doing this the particles are rendered to the texture instead of the screen. Now you have to bind this texture and use the stepshader. Here it's important to use the right blending methods! Just look into my previously posted render method. I'm not 100% sure with the projection matrix for the step shader but I think in this case you don't even have to use one. (Because the viewport of the offscreen buffer, or in andengine term the RenderTexture, is the same as the viewport of the main opengl framebuffer). If everything works you could think about using a RenderTexture with a lower resolution than the screen to make everything faster. It won't look very different but will give it a nice little performance boost. But in this case you have to think about a different projection matrix.

Good luck ;)

PS: I found a very easy way to get this effect on the water surface you wanted to get. I don't know if this effect is enough for you but if you want I can give you the source. It's just a few lines inside the stepshader.
Image
GForce
 
Posts: 10
Joined: Mon Mar 19, 2012 2:39 pm

Re: Liquid Fun - Box2D became even better - SUCCEED !!!

Postby valka » Wed Apr 23, 2014 8:37 pm

thanks :)
I've got to do some work for a client tonight, but i'll try to give an hour on this direction..

when i'll understand the FrameBuffer thing i should get along with the blending modes.
it will be more like photoshop and less like AndEngine coding :)

ltmon explains here how to use 2 pass gaussian blur with this technique, it should be the basis of what you are saying :)
tutorials/ongoing-guide-getting-started-with-shaders-in-andengine-t6659.html?hilit=rendertexture
User avatar
valka
 
Posts: 97
Joined: Tue Aug 13, 2013 3:17 pm

Re: Liquid Fun - Box2D became even better - SUCCEED !!!

Postby valka » Thu Apr 24, 2014 4:00 am

im almost there !
iv'e managed to draw into the framebuffer, then to draw the framebuffer into the HUD (for testing)

but that works with the default shader. I tried the step shader and it says:

04-24 04:55:03.140: E/AndroidRuntime(9963): org.andengine.opengl.shader.exception.ShaderProgramException: Unexpected uniform: 'u_texture_0'. Existing uniforms: {u_modelViewProjectionMatrix=0}

same with uniforms u_stepColor1 and u_stepColor2.. can you throw a bone ?
im playing with the binding and linking method for 2-3 hours.. i think ive tried almost everything..

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.                 @Override
  2.                 protected void link(final GLState pGLState) throws ShaderProgramLinkException {
  3.                         GLES20.glBindAttribLocation(this.mProgramID, ShaderProgramConstants.ATTRIBUTE_POSITION_LOCATION, ShaderProgramConstants.ATTRIBUTE_POSITION);
  4.                         GLES20.glBindAttribLocation(this.mProgramID, ShaderProgramConstants.ATTRIBUTE_COLOR_LOCATION, ShaderProgramConstants.ATTRIBUTE_COLOR);
  5.                         GLES20.glBindAttribLocation(this.mProgramID, ShaderProgramConstants.ATTRIBUTE_TEXTURECOORDINATES_LOCATION, ShaderProgramConstants.ATTRIBUTE_TEXTURECOORDINATES);
  6.                         /*GLES20.glBindAttribLocation(this.mProgramID, 10, "u_stepColor1");
  7.                         GLES20.glBindAttribLocation(this.mProgramID, 11, "u_stepColor2");*/
  8.        
  9.                         super.link(pGLState);
  10.  
  11.                         sUniformModelViewPositionMatrixLocation = this.getUniformLocation(ShaderProgramConstants.UNIFORM_MODELVIEWPROJECTIONMATRIX);
  12.                         sUniformTexture0Location = this.getUniformLocation(ShaderProgramConstants.UNIFORM_TEXTURE_0);
  13.                         sWaterColorLocation = this.getUniformLocation("u_stepColor1");
  14.                         sBgColorLocation = this.getUniformLocation("u_stepColor2");
  15.                 }
  16.                
  17.                 @Override
  18.                 public void bind(final GLState pGLState, final VertexBufferObjectAttributes pVertexBufferObjectAttributes) {
  19.                         GLES20.glDisableVertexAttribArray(ShaderProgramConstants.ATTRIBUTE_TEXTURECOORDINATES_LOCATION);
  20.  
  21.                         super.bind(pGLState, pVertexBufferObjectAttributes);
  22.                        
  23.                         GLES20.glUniformMatrix4fv(sUniformModelViewPositionMatrixLocation, 1, false, pGLState.getModelViewProjectionGLMatrix(), 0);
  24.                         GLES20.glUniform1i(sUniformTexture0Location, 0);
  25.                         GLES20.glUniform4fv(sBgColorLocation, 4, sWaterColor, 0);
  26.                         GLES20.glUniform4fv(sWaterColorLocation, 4, sBgColor, 0);
  27.                 }
  28.  
Parsed in 0.014 seconds, using GeSHi 1.0.8.4


thanks :)
User avatar
valka
 
Posts: 97
Joined: Tue Aug 13, 2013 3:17 pm

Re: Liquid Fun - Box2D became even better - SUCCEED !!!

Postby GForce » Thu Apr 24, 2014 4:45 pm

Maybe you can agin send me all your code?
I don't know what you modified inside the shader but if you use my original one you first have to rename the sampler2D variable to u_texture_0 instead of u_texture. In addition you don't need
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.                         GLES20.glBindAttribLocation(this.mProgramID, ShaderProgramConstants.ATTRIBUTE_COLOR_LOCATION, ShaderProgramConstants.ATTRIBUTE_COLOR);
Parsed in 0.011 seconds, using GeSHi 1.0.8.4
since you use uniform colors. (and you can delete the following)
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.                         /*GLES20.glBindAttribLocation(this.mProgramID, 10, "u_stepColor1");
  2.                         GLES20.glBindAttribLocation(this.mProgramID, 11, "u_stepColor2");*/
Parsed in 0.010 seconds, using GeSHi 1.0.8.4


At the moment you also dont need the matrix so remove everything with u_projTrans from the shader and
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.                         sUniformModelViewPositionMatrixLocation = this.getUniformLocation(ShaderProgramConstants.UNIFORM_MODELVIEWPROJECTIONMATRIX);
Parsed in 0.011 seconds, using GeSHi 1.0.8.4

and
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. GLES20.glUniformMatrix4fv(sUniformModelViewPositionMatrixLocation, 1, false, pGLState.getModelViewProjectionGLMatrix(), 0);
Parsed in 0.012 seconds, using GeSHi 1.0.8.4


Inside the bind method you also have to call renderTexture.bind(pGLState, 0);

If you send me all the source I can take another look :)
GForce
 
Posts: 10
Joined: Mon Mar 19, 2012 2:39 pm

Re: Liquid Fun - Box2D became even better - SUCCEED !!!

Postby valka » Mon Apr 28, 2014 12:01 am

GLSL + LiquidFun + Andengine = F awesome !!
Image
The poential is huge !!!
User avatar
valka
 
Posts: 97
Joined: Tue Aug 13, 2013 3:17 pm

Re: Liquid Fun - Box2D became even better - SUCCEED !!!

Postby nazgee » Mon Apr 28, 2014 1:46 pm

:o
OMFG! Well done guys :)
I plan to play with LF in about two weeks (after I finish playing with raycasting), but this really looks promising :)
Dirt Rider Mayhem is PUBLISHED now!
Image
User avatar
nazgee
 
Posts: 527
Joined: Fri Oct 21, 2011 10:31 pm
Location: Poland, Wrocław

Re: Liquid Fun - Box2D became even better - SUCCEED !!!

Postby MeeNoo » Tue Apr 29, 2014 8:47 am

Great job !!! Thank you for sharing ;)
MeeNoo
 
Posts: 102
Joined: Tue Nov 22, 2011 7:33 pm
Location: Paris ( France )

Re: Liquid Fun - Box2D became even better - SUCCEED !!!

Postby sjkm » Wed Apr 30, 2014 4:31 pm

Wow, that's really awesome! Your final results look brilliant!
sjkm
 
Posts: 25
Joined: Sun May 20, 2012 12:43 pm
Location: Zurich, Switzerland

PreviousNext

Return to Features

Who is online

Users browsing this forum: No registered users and 6 guests