<node name="scene"> <node flags="camera"> <method id="draw" value="cameraMethod"/> </node> <node name="terrainNode" flags="object,dynamic"> <bounds xmin="-50000" xmax="50000" ymin="-50000" ymax="50000" zmin="0" zmax="5000"/> <field id="terrain" value="terrain"/> <tileSamplerZ id="elevation" sampler="elevationSampler" producer="groundElevations1" storeInvisible="false"/> <tileSampler id="fnormal" sampler="fragmentNormalSampler" producer="groundNormals1" storeParent="false" storeInvisible="false"/> <mesh id="grid" value="quad.mesh"/> <method id="update" value="updateTerrainMethod"/> <method id="draw" value="drawTerrainMethod"/> <module id="material" value="terrainShader"/> </node> </node>
TileSampleZ
class is a derived class from TileSampler
. FrameBuffer::setTextureBuffer()
: Arrf, no, in fact we already have that as setTexture2DBuffer() 😁bool ReadbackManager::readback(ptr<FrameBuffer> fb, int x, int y, int w, int h, TextureFormat f, PixelType t, ptr<Callback> cb) { if (readCount[0] < maxReadbackPerFrame) { int index = readCount[0]; fb->readPixels(x, y, w, h, f, t, Buffer::Parameters(), *(toRead[0][index])); toReadCallbacks[0][index] = cb; ++readCount[0]; return true; } else { assert(false); // should not happen, call canReadback before return false; } }
void FrameBuffer::readPixels(int x, int y, int w, int h, TextureFormat f, PixelType t, const Buffer::Parameters &s, const Buffer &dstBuf, bool clamp) { if (Logger::DEBUG_LOGGER != NULL) { Logger::DEBUG_LOGGER->logf("RENDER", "read %d pixels", w * h); } set(); dstBuf.bind(GL_PIXEL_PACK_BUFFER); s.set(); glClampColor(GL_CLAMP_READ_COLOR, clamp ? GL_TRUE : GL_FALSE); glReadPixels(x, y, w, h, getTextureFormat(f), getPixelType(t), dstBuf.data(0)); s.unset(); dstBuf.unbind(GL_PIXEL_PACK_BUFFER); dstBuf.dirty(); assert(getError() == 0); }
async init() { // Get or create the state factory: let factory = RenderContext.getCurrent().getOrCreateFactory('TileSamplerZState', TileSamplerZStateFactory); // Create our state object: let storage = this.producer.getCache().getStorage().asGPUTileStorage(); this.state = await factory.get(storage); }
export async function createTileSamplerZ(producer: TileProducer, name: string = null): Promise<TileSamplerZ> { let ts = new TileSamplerZ(producer, name); await ts.init(); return ts; }
let pass = 0; while (h != 1) { h = h / 4 + (h % 4 == 0 ? 0 : 1); pass += 1; }
tsZ.setStoreInvisible(false)
and now we are good!⇒ Next time, we will create the TileSampler class… or maybe not 🤔: we probably need to start with the NormalProducer first.