use of com.jme3.texture.FrameBuffer in project jmonkeyengine by jMonkeyEngine.
the class AbstractShadowRendererVR method postFrame.
public void postFrame(FrameBuffer out) {
if (skipPostPass) {
return;
}
if (debug) {
displayShadowMap(renderManager.getRenderer());
}
getReceivers(lightReceivers);
if (lightReceivers.size() != 0) {
//setting params to recieving geometry list
setMatParams(lightReceivers);
Camera cam = viewPort.getCamera();
//some materials in the scene does not have a post shadow technique so we're using the fall back material
if (needsfallBackMaterial) {
renderManager.setForcedMaterial(postshadowMat);
}
//forcing the post shadow technique and render state
renderManager.setForcedTechnique(postTechniqueName);
//rendering the post shadow pass
viewPort.getQueue().renderShadowQueue(lightReceivers, renderManager, cam, false);
//resetting renderManager settings
renderManager.setForcedTechnique(null);
renderManager.setForcedMaterial(null);
renderManager.setCamera(cam, false);
//clearing the params in case there are some other shadow renderers
clearMatParams();
}
}
use of com.jme3.texture.FrameBuffer in project jmonkeyengine by jMonkeyEngine.
the class AbstractShadowRenderer method init.
private void init(AssetManager assetManager, int nbShadowMaps, int shadowMapSize) {
this.postshadowMat = new Material(assetManager, "Common/MatDefs/Shadow/PostShadow.j3md");
shadowFB = new FrameBuffer[nbShadowMaps];
shadowMaps = new Texture2D[nbShadowMaps];
dispPic = new Picture[nbShadowMaps];
lightViewProjectionsMatrices = new Matrix4f[nbShadowMaps];
shadowMapStringCache = new String[nbShadowMaps];
lightViewStringCache = new String[nbShadowMaps];
//DO NOT COMMENT THIS (it prevent the OSX incomplete read buffer crash)
dummyTex = new Texture2D(shadowMapSize, shadowMapSize, Format.RGBA8);
preshadowMat = new Material(assetManager, "Common/MatDefs/Shadow/PreShadow.j3md");
postshadowMat.setFloat("ShadowMapSize", shadowMapSize);
for (int i = 0; i < nbShadowMaps; i++) {
lightViewProjectionsMatrices[i] = new Matrix4f();
shadowFB[i] = new FrameBuffer(shadowMapSize, shadowMapSize, 1);
shadowMaps[i] = new Texture2D(shadowMapSize, shadowMapSize, Format.Depth);
shadowFB[i].setDepthTexture(shadowMaps[i]);
//DO NOT COMMENT THIS (it prevent the OSX incomplete read buffer crash)
shadowFB[i].setColorTexture(dummyTex);
shadowMapStringCache[i] = "ShadowMap" + i;
lightViewStringCache[i] = "LightViewProjectionMatrix" + i;
postshadowMat.setTexture(shadowMapStringCache[i], shadowMaps[i]);
//quads for debuging purpose
dispPic[i] = new Picture("Picture" + i);
dispPic[i].setTexture(assetManager, shadowMaps[i], false);
}
setShadowCompareMode(shadowCompareMode);
setEdgeFilteringMode(edgeFilteringMode);
setShadowIntensity(shadowIntensity);
initForcedRenderState();
}
use of com.jme3.texture.FrameBuffer in project jmonkeyengine by jMonkeyEngine.
the class RenderManager method renderViewPort.
/**
* Renders the {@link ViewPort}.
* <p>
* If the ViewPort is {@link ViewPort#isEnabled() disabled}, this method
* returns immediately. Otherwise, the ViewPort is rendered by
* the following process:<br>
* <ul>
* <li>All {@link SceneProcessor scene processors} that are attached
* to the ViewPort are {@link SceneProcessor#initialize(com.jme3.renderer.RenderManager, com.jme3.renderer.ViewPort) initialized}.
* </li>
* <li>The SceneProcessors' {@link SceneProcessor#preFrame(float) } method
* is called.</li>
* <li>The ViewPort's {@link ViewPort#getOutputFrameBuffer() output framebuffer}
* is set on the Renderer</li>
* <li>The camera is set on the renderer, including its view port parameters.
* (see {@link #setCamera(com.jme3.renderer.Camera, boolean) })</li>
* <li>Any buffers that the ViewPort requests to be cleared are cleared
* and the {@link ViewPort#getBackgroundColor() background color} is set</li>
* <li>Every scene that is attached to the ViewPort is flattened into
* the ViewPort's render queue
* (see {@link #renderViewPortQueues(com.jme3.renderer.ViewPort, boolean) })
* </li>
* <li>The SceneProcessors' {@link SceneProcessor#postQueue(com.jme3.renderer.queue.RenderQueue) }
* method is called.</li>
* <li>The render queue is sorted and then flushed, sending
* rendering commands to the underlying Renderer implementation.
* (see {@link #flushQueue(com.jme3.renderer.ViewPort) })</li>
* <li>The SceneProcessors' {@link SceneProcessor#postFrame(com.jme3.texture.FrameBuffer) }
* method is called.</li>
* <li>The translucent queue of the ViewPort is sorted and then flushed
* (see {@link #renderTranslucentQueue(com.jme3.renderer.ViewPort) })</li>
* <li>If any objects remained in the render queue, they are removed
* from the queue. This is generally objects added to the
* {@link RenderQueue#renderShadowQueue(com.jme3.renderer.queue.RenderQueue.ShadowMode, com.jme3.renderer.RenderManager, com.jme3.renderer.Camera, boolean)
* shadow queue}
* which were not rendered because of a missing shadow renderer.</li>
* </ul>
*
* @param vp View port to render
* @param tpf Time per frame value
*/
public void renderViewPort(ViewPort vp, float tpf) {
if (!vp.isEnabled()) {
return;
}
if (prof != null)
prof.vpStep(VpStep.BeginRender, vp, null);
SafeArrayList<SceneProcessor> processors = vp.getProcessors();
if (processors.isEmpty()) {
processors = null;
}
if (processors != null) {
if (prof != null)
prof.vpStep(VpStep.PreFrame, vp, null);
for (SceneProcessor proc : processors.getArray()) {
if (!proc.isInitialized()) {
proc.initialize(this, vp);
}
proc.setProfiler(this.prof);
if (prof != null)
prof.spStep(SpStep.ProcPreFrame, proc.getClass().getSimpleName());
proc.preFrame(tpf);
}
}
renderer.setFrameBuffer(vp.getOutputFrameBuffer());
setCamera(vp.getCamera(), false);
if (vp.isClearDepth() || vp.isClearColor() || vp.isClearStencil()) {
if (vp.isClearColor()) {
renderer.setBackgroundColor(vp.getBackgroundColor());
}
renderer.clearBuffers(vp.isClearColor(), vp.isClearDepth(), vp.isClearStencil());
}
if (prof != null)
prof.vpStep(VpStep.RenderScene, vp, null);
List<Spatial> scenes = vp.getScenes();
for (int i = scenes.size() - 1; i >= 0; i--) {
renderScene(scenes.get(i), vp);
}
if (processors != null) {
if (prof != null)
prof.vpStep(VpStep.PostQueue, vp, null);
for (SceneProcessor proc : processors.getArray()) {
if (prof != null)
prof.spStep(SpStep.ProcPostQueue, proc.getClass().getSimpleName());
proc.postQueue(vp.getQueue());
}
}
if (prof != null)
prof.vpStep(VpStep.FlushQueue, vp, null);
flushQueue(vp);
if (processors != null) {
if (prof != null)
prof.vpStep(VpStep.PostFrame, vp, null);
for (SceneProcessor proc : processors.getArray()) {
if (prof != null)
prof.spStep(SpStep.ProcPostFrame, proc.getClass().getSimpleName());
proc.postFrame(vp.getOutputFrameBuffer());
}
if (prof != null)
prof.vpStep(VpStep.ProcEndRender, vp, null);
}
//renders the translucent objects queue after processors have been rendered
renderTranslucentQueue(vp);
// clear any remaining spatials that were not rendered.
clearQueue(vp);
if (prof != null)
prof.vpStep(VpStep.EndRender, vp, null);
}
use of com.jme3.texture.FrameBuffer in project jmonkeyengine by jMonkeyEngine.
the class GLRenderer method setFrameBuffer.
public void setFrameBuffer(FrameBuffer fb) {
if (fb == null && mainFbOverride != null) {
fb = mainFbOverride;
}
if (context.boundFB == fb) {
if (fb == null || !fb.isUpdateNeeded()) {
return;
}
}
if (!caps.contains(Caps.FrameBuffer)) {
throw new RendererException("Framebuffer objects are not supported" + " by the video hardware");
}
// generate mipmaps for last FB if needed
if (context.boundFB != null) {
for (int i = 0; i < context.boundFB.getNumColorBuffers(); i++) {
RenderBuffer rb = context.boundFB.getColorBuffer(i);
Texture tex = rb.getTexture();
if (tex != null && tex.getMinFilter().usesMipMapLevels()) {
setTexture(0, rb.getTexture());
int textureType = convertTextureType(tex.getType(), tex.getImage().getMultiSamples(), rb.getFace());
glfbo.glGenerateMipmapEXT(textureType);
}
}
}
if (fb == null) {
bindFrameBuffer(null);
setReadDrawBuffers(null);
} else {
if (fb.isUpdateNeeded()) {
updateFrameBuffer(fb);
} else {
bindFrameBuffer(fb);
setReadDrawBuffers(fb);
}
// update viewport to reflect framebuffer's resolution
setViewPort(0, 0, fb.getWidth(), fb.getHeight());
assert fb.getId() > 0;
assert context.boundFBO == fb.getId();
context.boundFB = fb;
}
}
use of com.jme3.texture.FrameBuffer in project jmonkeyengine by jMonkeyEngine.
the class FilterPostProcessor method renderFilterChain.
/**
* iterate through the filter list and renders filters
* @param r
* @param sceneFb
*/
private void renderFilterChain(Renderer r, FrameBuffer sceneFb) {
Texture2D tex = filterTexture;
FrameBuffer buff = sceneFb;
boolean msDepth = depthTexture != null && depthTexture.getImage().getMultiSamples() > 1;
for (int i = 0; i < filters.size(); i++) {
Filter filter = filters.get(i);
if (prof != null)
prof.spStep(SpStep.ProcPostFrame, FPP, filter.getName());
if (filter.isEnabled()) {
if (filter.getPostRenderPasses() != null) {
for (Iterator<Filter.Pass> it1 = filter.getPostRenderPasses().iterator(); it1.hasNext(); ) {
Filter.Pass pass = it1.next();
if (prof != null)
prof.spStep(SpStep.ProcPostFrame, FPP, filter.getName(), pass.toString());
pass.beforeRender();
if (pass.requiresSceneAsTexture()) {
pass.getPassMaterial().setTexture("Texture", tex);
if (tex.getImage().getMultiSamples() > 1) {
pass.getPassMaterial().setInt("NumSamples", tex.getImage().getMultiSamples());
} else {
pass.getPassMaterial().clearParam("NumSamples");
}
}
if (pass.requiresDepthAsTexture()) {
pass.getPassMaterial().setTexture("DepthTexture", depthTexture);
if (msDepth) {
pass.getPassMaterial().setInt("NumSamplesDepth", depthTexture.getImage().getMultiSamples());
} else {
pass.getPassMaterial().clearParam("NumSamplesDepth");
}
}
renderProcessing(r, pass.getRenderFrameBuffer(), pass.getPassMaterial());
}
}
if (prof != null)
prof.spStep(SpStep.ProcPostFrame, FPP, filter.getName(), "postFrame");
filter.postFrame(renderManager, viewPort, buff, sceneFb);
Material mat = filter.getMaterial();
if (msDepth && filter.isRequiresDepthTexture()) {
mat.setInt("NumSamplesDepth", depthTexture.getImage().getMultiSamples());
}
if (filter.isRequiresSceneTexture()) {
mat.setTexture("Texture", tex);
if (tex.getImage().getMultiSamples() > 1) {
mat.setInt("NumSamples", tex.getImage().getMultiSamples());
} else {
mat.clearParam("NumSamples");
}
}
boolean wantsBilinear = filter.isRequiresBilinear();
if (wantsBilinear) {
tex.setMagFilter(Texture.MagFilter.Bilinear);
tex.setMinFilter(Texture.MinFilter.BilinearNoMipMaps);
}
buff = outputBuffer;
if (i != lastFilterIndex) {
buff = filter.getRenderFrameBuffer();
tex = filter.getRenderedTexture();
}
if (prof != null)
prof.spStep(SpStep.ProcPostFrame, FPP, filter.getName(), "render");
renderProcessing(r, buff, mat);
if (prof != null)
prof.spStep(SpStep.ProcPostFrame, FPP, filter.getName(), "postFilter");
filter.postFilter(r, buff);
if (wantsBilinear) {
tex.setMagFilter(Texture.MagFilter.Nearest);
tex.setMinFilter(Texture.MinFilter.NearestNoMipMaps);
}
}
}
}
Aggregations