Project

General

Profile

« Previous | Next » 

Revision da57b7da

Added by Leszek Koltunski about 6 years ago

Fix the 'OIT' artefacts.

View differences:

src/main/java/org/distorted/examples/blur/BlurRenderer.java
24 24
import android.opengl.GLSurfaceView;
25 25

  
26 26
import org.distorted.examples.R;
27
import org.distorted.library.effect.EffectName;
28 27
import org.distorted.library.effect.MatrixEffectMove;
29 28
import org.distorted.library.effect.MatrixEffectScale;
30 29
import org.distorted.library.effect.PostprocessEffectBlur;
31 30
import org.distorted.library.main.Distorted;
32 31
import org.distorted.library.main.DistortedEffects;
32
import org.distorted.library.main.DistortedFramebuffer;
33 33
import org.distorted.library.main.DistortedNode;
34 34
import org.distorted.library.main.DistortedScreen;
35 35
import org.distorted.library.main.DistortedTexture;
......
48 48

  
49 49
class BlurRenderer implements GLSurfaceView.Renderer
50 50
{
51
    private final static int SIZE = 500;
52

  
51 53
    private GLSurfaceView mView;
52 54
    private DistortedTexture mTexture;
53
    private DistortedEffects mEffects;
55
    private DistortedEffects mEffects, mBufferEffects;
54 56
    private DistortedScreen mScreen;
57
    private DistortedFramebuffer mBuffer;
55 58
    private MeshFlat mMesh;
56 59
    private Static1D mRadiusSta;
57 60
    private int mObjHeight, mObjWidth;
58
    private Static3D mMove, mScale;
61
    private Static3D mMove, mScale, mBufferMove, mBufferScale;
59 62

  
60 63
///////////////////////////////////////////////////////////////////////////////////////////////////
61 64

  
......
64 67
      mView   = v;
65 68
      mMesh   = new MeshFlat(1,1);
66 69
      mScreen = new DistortedScreen();
70
      mBuffer = new DistortedFramebuffer(SIZE,SIZE);
67 71

  
68 72
      mRadiusSta = new Static1D(5);
69 73
      Dynamic1D radiusDyn = new Dynamic1D();
......
71 75

  
72 76
      mMove = new Static3D(0,0,0);
73 77
      mScale= new Static3D(1,1,1);
78
      mBufferMove = new Static3D(0,0,0);
79
      mBufferScale= new Static3D(1,1,1);
80

  
81
      mBufferEffects = new DistortedEffects();
82
      mBufferEffects.apply(new MatrixEffectMove(mBufferMove));
83
      mBufferEffects.apply(new MatrixEffectScale(mBufferScale));
74 84

  
75 85
      mEffects = new DistortedEffects();
76 86
      mEffects.apply( new PostprocessEffectBlur(radiusDyn) );
......
91 101
   
92 102
   public void onDrawFrame(GL10 glUnused) 
93 103
      {
94
      mScreen.render( System.currentTimeMillis() );
104
      long time = System.currentTimeMillis();
105

  
106
      mBuffer.render(time);
107
      mScreen.render(time);
95 108
      }
96 109

  
97 110
///////////////////////////////////////////////////////////////////////////////////////////////////
98 111
    
99 112
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
100 113
     {
101
     float qw = (float)width /mObjWidth;
102
     float qh = (float)height/mObjHeight;
103
     float factor = 0.8f* (qw<qh ? qw:qh);
104
     int w = (int)(factor*mObjWidth);
105
     int h = (int)(factor*mObjHeight);
106

  
107
     mMove.set((width-w)/2 ,(height-h)/2, 0);
108
     mScale.set( factor,factor,factor );
114
     float qw1 = (float)width /SIZE;
115
     float qh1 = (float)height/SIZE;
116
     float factor1 = 0.8f* (qw1<qh1 ? qw1:qh1);
117
     int w1 = (int)(factor1*SIZE);
118
     int h1 = (int)(factor1*SIZE);
119

  
120
     mBufferMove.set((width-w1)/2 ,(height-h1)/2, 0);
121
     mBufferScale.set( factor1,factor1,factor1 );
122

  
123
     float qw2 = (float)SIZE/mObjWidth;
124
     float qh2 = (float)SIZE/mObjHeight;
125
     float factor2 = 0.9f* (qw2<qh2 ? qw2:qh2);
126
     int w2 = (int)(factor2*mObjWidth);
127
     int h2 = (int)(factor2*mObjHeight);
128

  
129
     mMove.set((SIZE-w2)/2 ,(SIZE-h2)/2, 0);
130
     mScale.set( factor2,factor2,factor2 );
131

  
109 132
     mScreen.resize(width, height);
110 133
     }
111 134

  
......
136 159
     mTexture.setTexture(bitmap);
137 160

  
138 161
     mScreen.detachAll();
139
     mScreen.attach(new DistortedNode(mTexture,mEffects,mMesh));
162
     mScreen.attach(mBuffer, mBufferEffects, mMesh);
163
     mBuffer.attach(new DistortedNode(mTexture,mEffects,mMesh));
140 164

  
141 165
     PostprocessEffectBlur.enable();
142 166

  

Also available in: Unified diff