use of net.drewke.tdme.engine.subsystems.shadowmapping.ShadowMapping in project tdme by andreasdr.
the class Engine method createOffScreenInstance.
/**
* Creates an offscreen rendering instance
* Note:
* - the root engine must have been initialized before
* - the created offscreen engine must not be initialized
*
* @return off screen engine
*/
public static Engine createOffScreenInstance(GLAutoDrawable drawable, int width, int height) {
if (instance == null || instance.initialized == false) {
System.out.println("Engine::createOffScreenInstance(): Engine not created or not initialized.");
return null;
}
// create off screen engine
Engine offScreenEngine = new Engine();
offScreenEngine.initialized = true;
// create GUI
offScreenEngine.gui = new GUI(offScreenEngine, guiRenderer);
// create object 3d vbo renderer
offScreenEngine.object3DVBORenderer = new Object3DVBORenderer(offScreenEngine, renderer);
offScreenEngine.object3DVBORenderer.init();
offScreenEngine.frameBuffer = new FrameBuffer(offScreenEngine, width, height, FrameBuffer.FRAMEBUFFER_DEPTHBUFFER | FrameBuffer.FRAMEBUFFER_COLORBUFFER);
offScreenEngine.frameBuffer.init();
// create camera, frustum partition
offScreenEngine.camera = new Camera(renderer);
offScreenEngine.partition = new PartitionQuadTree();
// create lights
for (int i = 0; i < offScreenEngine.lights.length; i++) offScreenEngine.lights[i] = new Light(renderer, i);
// create shadow mapping
if (instance.shadowMappingEnabled == true) {
offScreenEngine.shadowMapping = new ShadowMapping(offScreenEngine, renderer, offScreenEngine.object3DVBORenderer);
}
offScreenEngine.reshape(drawable, 0, 0, width, height);
return offScreenEngine;
}
use of net.drewke.tdme.engine.subsystems.shadowmapping.ShadowMapping in project tdme by andreasdr.
the class Object3DVBORenderer method renderObjectsOfSameType.
/**
* Renders multiple objects of same type(with same model)
* @param engine
* @param objects of same type/ with same models
* @param collect render faces
* @param skinning shader
*/
protected void renderObjectsOfSameType(ArrayList<Object3D> objects, boolean collectTransparentFaces, SkinningShader skinningShader) {
// do pre render steps
for (int i = 0; i < objects.size(); i++) {
Object3D object = objects.get(i);
for (int j = 0; j < object.object3dGroups.length; j++) {
Object3DGroup object3DGroup = object.object3dGroups[j];
((Object3DGroupVBORenderer) object3DGroup.renderer).preRender(this);
}
}
//
ShadowMapping shadowMapping = engine.getShadowMapping();
modelViewMatrixBackup.set(renderer.getModelViewMatrix());
// render faces entities
int currentFrontFace = -1;
Object3D firstObject = objects.get(0);
// all objects share the same object 3d group structure, so we just take the first one
int[] boundVBOBaseIds = null;
int[] boundVBOTangentBitangentIds = null;
int[] boundSkinningIds = null;
for (int object3DGroupIdx = 0; object3DGroupIdx < firstObject.object3dGroups.length; object3DGroupIdx++) {
Object3DGroup object3DGroup = firstObject.object3dGroups[object3DGroupIdx];
// render each faces entity
FacesEntity[] facesEntities = object3DGroup.group.getFacesEntities();
int faceIdx = 0;
int facesEntityIdxCount = facesEntities.length;
for (int faceEntityIdx = 0; faceEntityIdx < facesEntityIdxCount; faceEntityIdx++) {
FacesEntity facesEntity = facesEntities[faceEntityIdx];
boolean isTextureCoordinatesAvailable = facesEntity.isTextureCoordinatesAvailable();
int faces = facesEntity.getFaces().length;
// material
Material material = facesEntity.getMaterial();
// determine if transparent
boolean transparentFacesEntity = false;
// via material
if (material != null) {
if (material.hasTransparency() == true)
transparentFacesEntity = true;
}
// skip, if requested
if (transparentFacesEntity == true) {
// add to transparent render faces, if requested
int objectCount = objects.size();
for (int objectIdx = 0; objectIdx < objectCount; objectIdx++) {
Object3D object = objects.get(objectIdx);
Object3DGroup _object3DGroup = object.object3dGroups[object3DGroupIdx];
// set up textures
Object3DGroup.setupTextures(renderer, object3DGroup, faceEntityIdx);
// set up transparent render faces
if (collectTransparentFaces == true) {
transparentRenderFacesPool.createTransparentRenderFaces((_object3DGroup.mesh.skinning == true ? modelViewMatrix.identity() : modelViewMatrix.set(_object3DGroup.groupTransformationsMatrix)).multiply(object.transformationsMatrix).multiply(modelViewMatrixBackup), object.object3dGroups[object3DGroupIdx], faceEntityIdx, faceIdx);
}
}
// keep track of rendered faces
faceIdx += faces;
// skip to next entity
continue;
}
// optional texture coordinates
if (isTextureCoordinatesAvailable == true) {
// enable texturing client state if not yet done
if (renderer.renderingTexturingClientState == false) {
renderer.enableClientState(renderer.CLIENTSTATE_TEXTURECOORD_ARRAY);
renderer.renderingTexturingClientState = true;
}
} else {
// disable texturing client state if not yet done
if (renderer.renderingTexturingClientState == true) {
renderer.disableClientState(renderer.CLIENTSTATE_TEXTURECOORD_ARRAY);
renderer.renderingTexturingClientState = false;
}
}
// draw this faces entity for each object
int objectCount = objects.size();
for (int objectIdx = 0; objectIdx < objectCount; objectIdx++) {
Object3D object = objects.get(objectIdx);
Object3DGroup _object3DGroup = object.object3dGroups[object3DGroupIdx];
// set up material on first object
if (objectIdx == 0) {
// set up material
setupMaterial(_object3DGroup, faceEntityIdx);
} else {
// only set up textures
Object3DGroup.setupTextures(renderer, _object3DGroup, faceEntityIdx);
}
// check transparency via effect
if (object.effectColorMul.getAlpha() < 1.0f - MathTools.EPSILON || object.effectColorAdd.getAlpha() < -MathTools.EPSILON) {
// add to transparent render faces, if requested
if (collectTransparentFaces == true) {
transparentRenderFacesPool.createTransparentRenderFaces((_object3DGroup.mesh.skinning == true ? modelViewMatrix.identity() : modelViewMatrix.set(_object3DGroup.groupTransformationsMatrix)).multiply(object.transformationsMatrix).multiply(modelViewMatrixBackup), _object3DGroup, faceEntityIdx, faceIdx);
}
// skip to next object
continue;
}
// bind buffer base objects if not bound yet
int[] currentVBOGlIds = ((Object3DGroupVBORenderer) _object3DGroup.renderer).vboBaseIds;
if (boundVBOBaseIds != currentVBOGlIds) {
boundVBOBaseIds = currentVBOGlIds;
// texture coordinates
if (isTextureCoordinatesAvailable == true) {
renderer.bindTextureCoordinatesBufferObject(currentVBOGlIds[3]);
}
// vertices
renderer.bindVerticesBufferObject(currentVBOGlIds[1]);
// normals
renderer.bindNormalsBufferObject(currentVBOGlIds[2]);
// indices
renderer.bindIndicesBufferObject(currentVBOGlIds[0]);
}
// bind tangent, bitangend buffers if not yet bound
int[] currentVBOTangentBitangentIds = ((Object3DGroupVBORenderer) _object3DGroup.renderer).vboTangentBitangentIds;
if (renderer.isNormalMappingAvailable() && currentVBOTangentBitangentIds != null && currentVBOTangentBitangentIds != boundVBOTangentBitangentIds) {
// tangent
renderer.bindTangentsBufferObject(currentVBOTangentBitangentIds[0]);
// bitangent
renderer.bindBitangentsBufferObject(currentVBOTangentBitangentIds[1]);
}
// set up GPU skinning, if required
if (Engine.animationProcessingTarget == Engine.AnimationProcessingTarget.GPU && _object3DGroup.mesh.skinning == true && skinningShader != null) {
_object3DGroup.mesh.setupSkinningTransformationsMatrices(_object3DGroup.groupTransformationsMatricesVector);
skinningShader.initSkinning(renderer, _object3DGroup.mesh);
int[] currentSkinningIds = ((Object3DGroupVBORenderer) _object3DGroup.renderer).vboSkinningIds;
if (boundSkinningIds != currentSkinningIds) {
boundSkinningIds = currentSkinningIds;
renderer.bindSkinningVerticesJointsBufferObject(currentSkinningIds[0]);
renderer.bindSkinningVerticesVertexJointsIdxBufferObject(currentSkinningIds[1]);
renderer.bindSkinningVerticesVertexJointsWeightBufferObject(currentSkinningIds[2]);
}
}
// set up local -> world transformations matrix
renderer.getModelViewMatrix().set((_object3DGroup.mesh.skinning == true ? modelViewMatrix.identity() : modelViewMatrix.set(_object3DGroup.groupTransformationsMatrix)).multiply(object.transformationsMatrix).multiply(modelViewMatrixBackup));
renderer.onUpdateModelViewMatrix();
// set up front face
int objectFrontFace = matrix4x4Negative.isNegative(renderer.getModelViewMatrix()) == false ? renderer.FRONTFACE_CCW : renderer.FRONTFACE_CW;
if (objectFrontFace != currentFrontFace) {
renderer.setFrontFace(objectFrontFace);
currentFrontFace = objectFrontFace;
}
// set up effect color
renderer.setEffectColorMul(object.effectColorMul.getArray());
renderer.setEffectColorAdd(object.effectColorAdd.getArray());
renderer.onUpdateEffect();
// do transformation start to shadow mapping
if (shadowMapping != null) {
shadowMapping.startObjectTransformations((_object3DGroup.mesh.skinning == true ? modelViewMatrix.identity() : modelViewMatrix.set(_object3DGroup.groupTransformationsMatrix)).multiply(object.transformationsMatrix));
}
// draw
renderer.drawIndexedTrianglesFromBufferObjects(faces, faceIdx);
// do transformations end to shadow mapping
if (shadowMapping != null) {
shadowMapping.endObjectTransformations();
}
}
// done skinning
if (skinningShader != null) {
skinningShader.doneSkinning(renderer);
}
// keep track of rendered faces
faceIdx += faces;
}
}
// unbind buffers
renderer.unbindBufferObjects();
// restore model view matrix / view matrix
renderer.getModelViewMatrix().set(modelViewMatrixBackup);
}
use of net.drewke.tdme.engine.subsystems.shadowmapping.ShadowMapping in project tdme by andreasdr.
the class Engine method init.
/**
* Initialize render engine
* @param drawable
* @param debug
*/
public void init(GLAutoDrawable drawable, boolean debug) {
// exit if already initialized like a offscreen engine instance
if (initialized == true)
return;
//
GLContext glContext = drawable.getGL().getContext();
if (drawable.getGL().isGL3()) {
GL3 gl = (GL3) drawable.getGL().getGL3();
if (debug == true) {
drawable.setGL(new DebugGL3(gl));
}
// use gl3 renderer
renderer = new GL3Renderer() {
public final void onUpdateProjectionMatrix() {
if (lightingShader != null)
lightingShader.updateMatrices(this);
if (particlesShader != null)
particlesShader.updateMatrices(this);
if (shadowMapping != null)
shadowMapping.updateMVPMatrices(this);
}
public final void onUpdateCameraMatrix() {
if (lightingShader != null)
lightingShader.updateMatrices(this);
if (particlesShader != null)
particlesShader.updateMatrices(this);
if (shadowMapping != null)
shadowMapping.updateMVPMatrices(this);
}
public final void onUpdateModelViewMatrix() {
if (lightingShader != null)
lightingShader.updateMatrices(this);
if (particlesShader != null)
particlesShader.updateMatrices(this);
if (shadowMapping != null)
shadowMapping.updateMVPMatrices(this);
}
public final void onBindTexture(int textureId) {
if (lightingShader != null)
lightingShader.bindTexture(this, textureId);
if (guiShader != null)
guiShader.bindTexture(this, textureId);
}
public final void onUpdateTextureMatrix() {
// no op
}
public final void onUpdateEffect() {
if (lightingShader != null)
lightingShader.updateEffect(this);
if (particlesShader != null)
particlesShader.updateEffect(this);
if (guiShader != null)
guiShader.updateEffect(this);
}
public final void onUpdateLight(int lightId) {
if (lightingShader != null)
lightingShader.updateLight(this, lightId);
}
public final void onUpdateMaterial() {
if (lightingShader != null)
lightingShader.updateMaterial(this);
}
};
// notify gl context to renderer
renderer.setGL(gl);
// print gl version, extensions
System.out.println("TDME::Using GL3");
System.out.println("TDME::Extensions: " + gl.glGetString(GL.GL_EXTENSIONS));
// engine defaults
shadowMappingEnabled = true;
animationProcessingTarget = AnimationProcessingTarget.CPU;
ShadowMapping.setShadowMapSize(2048, 2048);
} else if (drawable.getGL().isGL2()) {
GL2 gl = (GL2) drawable.getGL().getGL2();
if (debug == true) {
drawable.setGL(new DebugGL2(gl));
}
// use gl2 renderer
renderer = new GL2Renderer() {
public final void onUpdateProjectionMatrix() {
if (lightingShader != null)
lightingShader.updateMatrices(this);
if (particlesShader != null)
particlesShader.updateMatrices(this);
if (shadowMapping != null)
shadowMapping.updateMVPMatrices(this);
}
public final void onUpdateCameraMatrix() {
if (lightingShader != null)
lightingShader.updateMatrices(this);
if (particlesShader != null)
particlesShader.updateMatrices(this);
if (shadowMapping != null)
shadowMapping.updateMVPMatrices(this);
}
public final void onUpdateModelViewMatrix() {
if (lightingShader != null)
lightingShader.updateMatrices(this);
if (particlesShader != null)
particlesShader.updateMatrices(this);
if (shadowMapping != null)
shadowMapping.updateMVPMatrices(this);
}
public final void onBindTexture(int textureId) {
if (lightingShader != null)
lightingShader.bindTexture(this, textureId);
if (guiShader != null)
guiShader.bindTexture(this, textureId);
}
public final void onUpdateTextureMatrix() {
// no op
}
public final void onUpdateEffect() {
if (lightingShader != null)
lightingShader.updateEffect(this);
if (particlesShader != null)
particlesShader.updateEffect(this);
if (guiShader != null)
guiShader.updateEffect(this);
}
public final void onUpdateLight(int lightId) {
if (lightingShader != null)
lightingShader.updateLight(this, lightId);
}
public final void onUpdateMaterial() {
if (lightingShader != null)
lightingShader.updateMaterial(this);
}
};
// notify gl context to renderer
renderer.setGL(gl);
// print gl version, extensions
System.out.println("TDME::Using GL2");
System.out.println("TDME::Extensions: " + gl.glGetString(GL.GL_EXTENSIONS));
// engine defaults
shadowMappingEnabled = true;
animationProcessingTarget = AnimationProcessingTarget.CPU;
ShadowMapping.setShadowMapSize(2048, 2048);
} else if (drawable.getGL().isGLES2()) {
GLES2 gl = (GLES2) drawable.getGL().getGLES2();
if (debug == true) {
drawable.setGL(new DebugGLES2(gl));
}
// use gl es 2 renderer
renderer = new GLES2Renderer() {
public final void onUpdateProjectionMatrix() {
if (lightingShader != null)
lightingShader.updateMatrices(this);
if (particlesShader != null)
particlesShader.updateMatrices(this);
if (shadowMapping != null)
shadowMapping.updateMVPMatrices(this);
}
public final void onUpdateCameraMatrix() {
if (lightingShader != null)
lightingShader.updateMatrices(this);
if (particlesShader != null)
particlesShader.updateMatrices(this);
if (shadowMapping != null)
shadowMapping.updateMVPMatrices(this);
}
public final void onUpdateModelViewMatrix() {
if (lightingShader != null)
lightingShader.updateMatrices(this);
if (particlesShader != null)
particlesShader.updateMatrices(this);
if (shadowMapping != null)
shadowMapping.updateMVPMatrices(this);
}
public final void onBindTexture(int textureId) {
if (lightingShader != null)
lightingShader.bindTexture(this, textureId);
if (guiShader != null)
guiShader.bindTexture(this, textureId);
}
public final void onUpdateTextureMatrix() {
// no op
}
public final void onUpdateEffect() {
if (lightingShader != null)
lightingShader.updateEffect(this);
if (particlesShader != null)
particlesShader.updateEffect(this);
if (guiShader != null)
guiShader.updateEffect(this);
}
public final void onUpdateLight(int lightId) {
if (lightingShader != null)
lightingShader.updateLight(this, lightId);
}
public final void onUpdateMaterial() {
if (lightingShader != null)
lightingShader.updateMaterial(this);
}
};
// notify gl context to renderer
renderer.setGL(gl);
// print gl version, extensions
System.out.println("TDME::Using GLES2");
System.out.println("TDME::Extensions: " + gl.glGetString(GL.GL_EXTENSIONS));
// is shadow mapping available?
if (renderer.isBufferObjectsAvailable() == true && renderer.isDepthTextureAvailable() == true) {
// yep, nice
shadowMappingEnabled = true;
animationProcessingTarget = AnimationProcessingTarget.CPU;
ShadowMapping.setShadowMapSize(512, 512);
} else {
// nope, renderer skinning on GPU to speed up things and do not shadow mapping
shadowMappingEnabled = false;
animationProcessingTarget = AnimationProcessingTarget.GPU;
}
} else {
System.out.println("Engine::init(): unsupported GL!");
return;
}
// init
initialized = true;
renderer.init();
renderer.renderingTexturingClientState = false;
// create manager
textureManager = new TextureManager(renderer);
vboManager = new VBOManager(renderer);
meshManager = new MeshManager();
// create object 3d vbo renderer
object3DVBORenderer = new Object3DVBORenderer(this, renderer);
object3DVBORenderer.init();
// create GUI
guiRenderer = new GUIRenderer(renderer);
guiRenderer.init();
gui = new GUI(this, guiRenderer);
gui.init();
// create camera
camera = new Camera(renderer);
partition = new PartitionQuadTree();
// create lights
for (int i = 0; i < lights.length; i++) lights[i] = new Light(renderer, i);
// create lighting shader
lightingShader = new LightingShader(renderer);
lightingShader.init();
// create particles shader
particlesShader = new ParticlesShader(this, renderer);
particlesShader.init();
// create GUI shader
guiShader = new GUIShader(renderer);
guiShader.init();
// check if VBOs are available
if (renderer.isBufferObjectsAvailable()) {
System.out.println("TDME::VBOs are available.");
} else {
System.out.println("TDME::VBOs are not available! Engine will not work!");
initialized = false;
}
// check FBO support
if (glContext.hasBasicFBOSupport() == false) {
System.out.println("TDME::Basic FBOs are not available!");
shadowMappingEnabled = false;
} else {
System.out.println("TDME::Basic FBOs are available.");
}
// initialize shadow mapping
if (shadowMappingEnabled == true) {
System.out.println("TDME::Using shadow mapping");
shadowMappingShaderPre = new ShadowMappingShaderPre(renderer);
shadowMappingShaderPre.init();
shadowMappingShaderRender = new ShadowMappingShaderRender(renderer);
shadowMappingShaderRender.init();
shadowMapping = new ShadowMapping(this, renderer, object3DVBORenderer);
} else {
System.out.println("TDME::Not using shadow mapping");
}
// print out animation processing target
System.out.println("TDME: animation processing target: " + animationProcessingTarget);
// determine initialized from sub systems
initialized &= shadowMappingShaderPre == null ? true : shadowMappingShaderPre.isInitialized();
initialized &= shadowMappingShaderRender == null ? true : shadowMappingShaderRender.isInitialized();
initialized &= lightingShader.isInitialized();
initialized &= particlesShader.isInitialized();
initialized &= guiShader.isInitialized();
//
System.out.println("TDME::initialized & ready: " + initialized);
}
Aggregations