/** * This computes the "C" value in the geomipmapping paper. * See section "2.3.1.2 Pre-calculating d" * * @param cam * @param pixelLimit * @return */ private float getCameraConstant(Camera cam, float pixelLimit){ float n = cam.getFrustumNear(); float t = FastMath.abs(cam.getFrustumTop()); float A = n / t; float v_res = cam.getHeight(); float T = (2f * pixelLimit) / v_res; return A / T; }
@Override protected void initFrustumCam() { Camera viewCam = viewPort.getCamera(); frustumCam = viewCam.clone(); frustumCam.setFrustum(viewCam.getFrustumNear(), zFarOverride, viewCam.getFrustumLeft(), viewCam.getFrustumRight(), viewCam.getFrustumTop(), viewCam.getFrustumBottom()); }
@Override protected void initFrustumCam() { Camera viewCam = viewPort.getCamera(); frustumCam = viewCam.clone(); frustumCam.setFrustum(viewCam.getFrustumNear(), zFarOverride, viewCam.getFrustumLeft(), viewCam.getFrustumRight(), viewCam.getFrustumTop(), viewCam.getFrustumBottom()); }
protected void controlRender(RenderManager rm, ViewPort vp) { BoundingVolume bv = spatial.getWorldBound(); Camera cam = vp.getCamera(); float atanNH = FastMath.atan(cam.getFrustumNear() * cam.getFrustumTop()); float ratio = (FastMath.PI / (8f * atanNH)); float newDistance = bv.distanceTo(vp.getCamera().getLocation()) / ratio; int level; if (Math.abs(newDistance - lastDistance) <= distTolerance) { level = lastLevel; // we haven't moved relative to the model, send the old measurement back. } else if (lastDistance > newDistance && lastLevel == 0) { level = lastLevel; // we're already at the lowest setting and we just got closer to the model, no need to keep trying. } else if (lastDistance < newDistance && lastLevel == numLevels - 1) { level = lastLevel; // we're already at the highest setting and we just got further from the model, no need to keep trying. } else { lastDistance = newDistance; // estimate area of polygon via bounding volume float area = AreaUtils.calcScreenArea(bv, lastDistance, cam.getWidth()); float trisToDraw = area * trisPerPixel; level = numLevels - 1; for (int i = numLevels; --i >= 0;) { if (trisToDraw - numTris[i] < 0) { break; } level = i; } lastLevel = level; } spatial.setLodLevel(level); }
/** * Zoom the camera by the specified amount. * * @param value zoom amount */ protected void zoomCamera(float value){ // derive fovY value float h = cam.getFrustumTop(); float w = cam.getFrustumRight(); float aspect = w / h; float near = cam.getFrustumNear(); float fovY = FastMath.atan(h / near) / (FastMath.DEG_TO_RAD * .5f); float newFovY = fovY + value * 0.1f * zoomSpeed; if (newFovY > 0f) { // Don't let the FOV go zero or negative. fovY = newFovY; } h = FastMath.tan( fovY * FastMath.DEG_TO_RAD * .5f) * near; w = h * aspect; cam.setFrustumTop(h); cam.setFrustumBottom(-h); cam.setFrustumLeft(-w); cam.setFrustumRight(w); }
@Override protected void initFilter(AssetManager manager, RenderManager renderManager, ViewPort vp, int w, int h) { this.renderManager = renderManager; this.viewPort = vp; int screenWidth = Math.round(w / downsample); int screenHeight = Math.round(h / downsample); normalPass = new Pass(); normalPass.init(renderManager.getRenderer(), screenWidth, screenHeight, Format.RGBA8, Format.Depth); frustumNearFar = new Vector2f(); float farY = (vp.getCamera().getFrustumTop() / vp.getCamera().getFrustumNear()) * vp.getCamera().getFrustumFar(); float farX = farY * ((float) screenWidth / (float) screenHeight); frustumCorner = new Vector3f(farX, farY, vp.getCamera().getFrustumFar()); frustumNearFar.x = vp.getCamera().getFrustumNear(); frustumNearFar.y = vp.getCamera().getFrustumFar(); //ssao Pass material = new Material(manager, "Common/MatDefs/VR/CartoonSSAO.j3md"); material.setTexture("Normals", normalPass.getRenderedTexture()); material.setVector3("FrustumCorner", frustumCorner); material.setVector2("FrustumNearFar", frustumNearFar); material.setFloat("Distance", applyDistance); if( useOutline == false ) material.setBoolean("disableOutline", true); if( instancedRendering ) material.setBoolean("useInstancing", true); }
public void postQueue(RenderQueue rq) { Camera sceneCam = rm.getCurrentCamera(); //update refraction cam refractionCam.setLocation(sceneCam.getLocation()); refractionCam.setRotation(sceneCam.getRotation()); refractionCam.setFrustum(sceneCam.getFrustumNear(), sceneCam.getFrustumFar(), sceneCam.getFrustumLeft(), sceneCam.getFrustumRight(), sceneCam.getFrustumTop(), sceneCam.getFrustumBottom()); refractionCam.setParallelProjection(sceneCam.isParallelProjection()); //update reflection cam WaterUtils.updateReflectionCam(reflectionCam, plane, sceneCam); //Rendering reflection and refraction rm.renderViewPort(reflectionView, savedTpf); rm.renderViewPort(refractionView, savedTpf); rm.getRenderer().setFrameBuffer(vp.getOutputFrameBuffer()); rm.setCamera(sceneCam, false); }
float farY = (vp.getCamera().getFrustumTop() / vp.getCamera().getFrustumNear()) * vp.getCamera().getFrustumFar(); float farX = farY * ((float) screenWidth / (float) screenHeight); frustumCorner = new Vector3f(farX, farY, vp.getCamera().getFrustumFar());
sceneCam.getFrustumLeft(), sceneCam.getFrustumRight(), sceneCam.getFrustumTop(), sceneCam.getFrustumBottom()); reflectionCam.setParallelProjection(sceneCam.isParallelProjection());
Vector3f up = viewCam.getUp(); float depthHeightRatio = viewCam.getFrustumTop() / viewCam.getFrustumNear(); float near = nearOverride; float far = farOverride; float ftop = viewCam.getFrustumTop(); float fright = viewCam.getFrustumRight(); float ratio = fright / ftop;
/** * This computes the "C" value in the geomipmapping paper. * See section "2.3.1.2 Pre-calculating d" * * @param cam * @param pixelLimit * @return */ private float getCameraConstant(Camera cam, float pixelLimit){ float n = cam.getFrustumNear(); float t = FastMath.abs(cam.getFrustumTop()); float A = n / t; float v_res = cam.getHeight(); float T = (2f * pixelLimit) / v_res; return A / T; }
public OrganizedPointCloud getPointcloud() { float xyzrgb[] = new float[width * height * 4]; int ptr = 0; float n = offCamera.getFrustumNear(); float frustrumWidthToImageWidth = (offCamera.getFrustumRight() - offCamera.getFrustumLeft()) / width; float frustrumHeightToImageHeight = (offCamera.getFrustumTop() - offCamera.getFrustumBottom()) / height; for (int h = 0; h < height; h++) for (int w = 0; w < width; w++) { float x = 0, y = 0, z = 0; if (Float.isNaN(depthImage[h][w])) { z = Float.NaN;//Float.NaN; x = (float) ((w - width / 2) * frustrumWidthToImageWidth * z / n); y = (float) ((h - height / 2) * frustrumHeightToImageHeight * z / n); } else { z = depthImage[h][w]; x = (float) ((w - width / 2) * frustrumWidthToImageWidth * z / n); y = (float) ((h - height / 2) * frustrumHeightToImageHeight * z / n); } xyzrgb[ptr++] = x; xyzrgb[ptr++] = y; xyzrgb[ptr++] = z; xyzrgb[ptr++] = Float.intBitsToFloat(image.getRGB(w, h)); } return new OrganizedPointCloud(width, height, xyzrgb); }
@Override protected void initFrustumCam() { Camera viewCam = viewPort.getCamera(); frustumCam = viewCam.clone(); frustumCam.setFrustum(viewCam.getFrustumNear(), zFarOverride, viewCam.getFrustumLeft(), viewCam.getFrustumRight(), viewCam.getFrustumTop(), viewCam.getFrustumBottom()); }
@Override protected void initFrustumCam() { Camera viewCam = viewPort.getCamera(); frustumCam = viewCam.clone(); frustumCam.setFrustum(viewCam.getFrustumNear(), zFarOverride, viewCam.getFrustumLeft(), viewCam.getFrustumRight(), viewCam.getFrustumTop(), viewCam.getFrustumBottom()); }
protected void zoomCamera(float value){ // derive fovY value float h = cam.getFrustumTop(); float w = cam.getFrustumRight(); float aspect = w / h; float near = cam.getFrustumNear(); float fovY = FastMath.atan(h / near) / (FastMath.DEG_TO_RAD * .5f); fovY += value * 0.1f; h = FastMath.tan( fovY * FastMath.DEG_TO_RAD * .5f) * near; w = h * aspect; cam.setFrustumTop(h); cam.setFrustumBottom(-h); cam.setFrustumLeft(-w); cam.setFrustumRight(w); }
public void cameraRestore() { Camera cam = app.getCamera(); //cam.setAxes(storedCamera.getLeft(), storedCamera.getUp(), storedCamera.getDirection()); //cam.setRotation(storedCamera.getRotation()); cam.setFrame(storedCamera.getLocation(), storedCamera.getRotation()); cam.setFrustum(storedCamera.getFrustumNear(), storedCamera.getFrustumFar(), storedCamera.getFrustumLeft(), storedCamera.getFrustumRight(), storedCamera.getFrustumTop(), storedCamera.getFrustumBottom()); //cam.setLocation(storedCamera.getLocation()); }
/** * Zoom the camera by the specified amount. * * @param value zoom amount */ protected void zoomCamera(float value){ // derive fovY value float h = cam.getFrustumTop(); float w = cam.getFrustumRight(); float aspect = w / h; float near = cam.getFrustumNear(); float fovY = FastMath.atan(h / near) / (FastMath.DEG_TO_RAD * .5f); float newFovY = fovY + value * 0.1f * zoomSpeed; if (newFovY > 0f) { // Don't let the FOV go zero or negative. fovY = newFovY; } h = FastMath.tan( fovY * FastMath.DEG_TO_RAD * .5f) * near; w = h * aspect; cam.setFrustumTop(h); cam.setFrustumBottom(-h); cam.setFrustumLeft(-w); cam.setFrustumRight(w); }
public void postQueue(RenderQueue rq) { Camera sceneCam = rm.getCurrentCamera(); //update refraction cam refractionCam.setLocation(sceneCam.getLocation()); refractionCam.setRotation(sceneCam.getRotation()); refractionCam.setFrustum(sceneCam.getFrustumNear(), sceneCam.getFrustumFar(), sceneCam.getFrustumLeft(), sceneCam.getFrustumRight(), sceneCam.getFrustumTop(), sceneCam.getFrustumBottom()); refractionCam.setParallelProjection(sceneCam.isParallelProjection()); //update reflection cam WaterUtils.updateReflectionCam(reflectionCam, plane, sceneCam); //Rendering reflection and refraction rm.renderViewPort(reflectionView, savedTpf); rm.renderViewPort(refractionView, savedTpf); rm.getRenderer().setFrameBuffer(vp.getOutputFrameBuffer()); rm.setCamera(sceneCam, false); }
public void postQueue(RenderQueue rq) { Camera sceneCam = rm.getCurrentCamera(); //update refraction cam refractionCam.setLocation(sceneCam.getLocation()); refractionCam.setRotation(sceneCam.getRotation()); refractionCam.setFrustum(sceneCam.getFrustumNear(), sceneCam.getFrustumFar(), sceneCam.getFrustumLeft(), sceneCam.getFrustumRight(), sceneCam.getFrustumTop(), sceneCam.getFrustumBottom()); refractionCam.setParallelProjection(sceneCam.isParallelProjection()); //update reflection cam WaterUtils.updateReflectionCam(reflectionCam, plane, sceneCam); //Rendering reflection and refraction rm.renderViewPort(reflectionView, savedTpf); rm.renderViewPort(refractionView, savedTpf); rm.getRenderer().setFrameBuffer(vp.getOutputFrameBuffer()); rm.setCamera(sceneCam, false); }
sceneCam.getFrustumLeft(), sceneCam.getFrustumRight(), sceneCam.getFrustumTop(), sceneCam.getFrustumBottom()); reflectionCam.setParallelProjection(sceneCam.isParallelProjection());