70 |
70 |
}
|
71 |
71 |
else
|
72 |
72 |
{
|
73 |
|
if( mFBONode==null ) mFBONode = new DistortedNode(mFBOTex,mFBOEffects,mQuad);
|
74 |
|
|
75 |
73 |
mScreen.detachAll();
|
76 |
74 |
mScreen.attach(mFBONode);
|
77 |
75 |
mFBONode.attach(mCube1Node);
|
78 |
|
mFBONode.attach(mCube2Node);
|
79 |
76 |
mFBONode.attach(mFloorNode);
|
80 |
|
|
81 |
|
DistortedFramebuffer fbo = mFBONode.getFramebuffer();
|
82 |
|
if( fbo!=null ) fbo.enableDepthStencil(DistortedFramebuffer.BOTH_DEPTH_STENCIL);
|
83 |
|
else
|
84 |
|
{
|
85 |
|
android.util.Log.e("stencil", "failed to enable STENCIL!");
|
86 |
|
}
|
|
77 |
mFBONode.attach(mCube2Node);
|
|
78 |
mFBONode.enableDepthStencil(DistortedFramebuffer.BOTH_DEPTH_STENCIL);
|
87 |
79 |
}
|
88 |
80 |
}
|
89 |
81 |
|
... | ... | |
110 |
102 |
mCube1Node = new DistortedNode(mCubeTex ,mCube1Effects,mCubeMesh );
|
111 |
103 |
mCube2Node = new DistortedNode(mCubeTex ,mCube2Effects,mCubeMesh );
|
112 |
104 |
mFloorNode = new DistortedNode(mFloorTex,mFloorEffects,mQuad );
|
113 |
|
|
|
105 |
mFBONode = new DistortedNode(mFBOTex ,mFBOEffects ,mQuad );
|
|
106 |
|
|
107 |
///////////////// The Meat of this App - shamelessly ripped off https://open.gl/depthstencils ///////////////////////
|
|
108 |
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
109 |
// Stuff to do just before we render the upper Cube
|
|
110 |
// (nothing - i.e. use default OpenGL settings with one difference - in Distorted, Depth test is on by default)
|
|
111 |
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
112 |
// Stuff to do just before we render the Floor
|
114 |
113 |
mFloorNode.glEnable(GLES30.GL_STENCIL_TEST); // Enable Stencil when rendering this Node
|
115 |
114 |
mFloorNode.glStencilFunc(GLES30.GL_ALWAYS, 1, 0xFF); // Set any stencil to 1
|
116 |
115 |
mFloorNode.glStencilOp(GLES30.GL_KEEP, GLES30.GL_KEEP, GLES30.GL_REPLACE); // replace with 1 when we fail Depth test
|
117 |
116 |
mFloorNode.glStencilMask(0xFF); // Write to stencil buffer
|
118 |
117 |
mFloorNode.glDepthMask(false); // Don't write to depth buffer
|
119 |
|
mFloorNode.glClear(GLES30.GL_STENCIL_BUFFER_BIT); // Clear stencil buffer (0 by default)
|
|
118 |
mFloorNode.glClear(GLES30.GL_STENCIL_BUFFER_BIT); // Clear stencil buffer (by default, with a 0)
|
120 |
119 |
|
|
120 |
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
121 |
// Stuff to do just before we render the lower Cube
|
121 |
122 |
mCube2Node.glEnable(GLES30.GL_STENCIL_TEST); // Enable Stencil when rendering this Node
|
122 |
123 |
mCube2Node.glStencilFunc(GLES30.GL_EQUAL, 1, 0xFF); // Pass test if stencil value is 1
|
123 |
124 |
mCube2Node.glStencilMask(0x00); // Don't write anything to stencil buffer
|
124 |
125 |
mCube2Node.glDepthMask(true); // Write to depth buffer
|
|
126 |
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
125 |
127 |
|
126 |
128 |
mScreen = new DistortedScreen(mView);
|
127 |
129 |
mScreen.glClearColor(1.0f,1.0f,1.0f,1.0f);
|
... | ... | |
149 |
151 |
float fh = mFloorTex.getHeight();
|
150 |
152 |
float fd = mFloorTex.getDepth(mQuad);
|
151 |
153 |
|
|
154 |
float bw = mFBOTex.getWidth();
|
|
155 |
float bh = mFBOTex.getHeight();
|
|
156 |
|
152 |
157 |
float cubeScale = 0.4f*(width>height ? height/ch:width/cw);
|
153 |
158 |
float floorScale= 0.8f*(width>height ? height/fh:width/fw);
|
154 |
159 |
|
... | ... | |
169 |
174 |
Static1D rotSt1 = new Static1D(angle);
|
170 |
175 |
Static1D rotSt2 = new Static1D(angle-90.0f);
|
171 |
176 |
|
|
177 |
/////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
178 |
// Those Matrix effects, i.e. correct positioning of Objects on the Screen, is admittedly quite hard.
|
|
179 |
// Figured out of experimentation.
|
|
180 |
/////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
181 |
// Upper cube
|
172 |
182 |
mCube1Effects.abortEffects(EffectTypes.MATRIX);
|
173 |
183 |
mCube1Effects.move( new Static3D( (width-cubeScale*cw)/2 , height/2-cubeScale*ch , cubeScale *cd/2) );
|
174 |
184 |
mCube1Effects.scale(cubeScale);
|
175 |
185 |
mCube1Effects.rotate(rotSt1, axisX, cubeCenter);
|
176 |
186 |
mCube1Effects.rotate(rotDyn, axisY, cubeCenter);
|
177 |
187 |
|
|
188 |
/////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
189 |
// Floor
|
|
190 |
mFloorEffects.abortEffects(EffectTypes.MATRIX);
|
|
191 |
mFloorEffects.move( new Static3D( (width-floorScale*fw)/2 ,height/2-floorScale*fh/2, floorScale*fd/2) );
|
|
192 |
mFloorEffects.scale(floorScale);
|
|
193 |
mFloorEffects.rotate(rotSt2, axisX, floorCenter);
|
|
194 |
mFloorEffects.rotate(rotDyn, axisZ, floorCenter);
|
|
195 |
|
|
196 |
/////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
197 |
// Lower cube
|
178 |
198 |
mCube2Effects.abortEffects(EffectTypes.MATRIX);
|
179 |
199 |
mCube2Effects.move( new Static3D( (width-cubeScale*cw)/2 , height/2-cubeScale*ch , cubeScale *cd/2) );
|
180 |
200 |
mCube2Effects.scale(cubeScale);
|
... | ... | |
183 |
203 |
mCube2Effects.scale(new Static3D(1,-1,1) );
|
184 |
204 |
mCube2Effects.move( new Static3D( 0, -2*ch , 0) );
|
185 |
205 |
|
186 |
|
mFloorEffects.abortEffects(EffectTypes.MATRIX);
|
187 |
|
mFloorEffects.move( new Static3D( (width-floorScale*fw)/2 ,height/2-floorScale*fh/2, floorScale*fd/2) );
|
188 |
|
mFloorEffects.scale(floorScale);
|
189 |
|
mFloorEffects.rotate(rotSt2, axisX, floorCenter);
|
190 |
|
mFloorEffects.rotate(rotDyn, axisZ, floorCenter);
|
191 |
|
|
192 |
|
if( mFBONode==null ) mFBONode = new DistortedNode(mFBOTex,mFBOEffects,mQuad);
|
193 |
|
|
194 |
|
DistortedFramebuffer fbo = mFBONode.getFramebuffer();
|
195 |
|
if( fbo!=null ) fbo.resize(width,height);
|
196 |
|
else
|
197 |
|
{
|
198 |
|
android.util.Log.e("stencil", "failed to resize FBO!");
|
199 |
|
}
|
|
206 |
/////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
207 |
// Framebuffer
|
|
208 |
mFBOEffects.abortEffects(EffectTypes.MATRIX);
|
|
209 |
mFBOEffects.scale( new Static3D( (float)width/bw, (float)height/bh, 1.0f) );
|
200 |
210 |
|
201 |
|
mScreen.resize(width, height);
|
|
211 |
mFBONode.resize( (int)((float)width/bw), (int)((float)height/bh) );
|
|
212 |
mScreen.resize( width,height);
|
202 |
213 |
}
|
203 |
214 |
|
204 |
215 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
Progress with Stencil app. Rendering through an intermediate FBO still doesn't quite work.