use of org.terasology.rendering.primitives.ChunkMesh in project Terasology by MovingBlocks.
the class BlockMeshPart method appendTo.
public void appendTo(ChunkMesh chunk, int offsetX, int offsetY, int offsetZ, Vector4f colorOffset, ChunkMesh.RenderType renderType, ChunkVertexFlag flags) {
ChunkMesh.VertexElements elements = chunk.getVertexElements(renderType);
for (Vector2f texCoord : texCoords) {
elements.tex.add(texCoord.x);
elements.tex.add(texCoord.y);
}
int nextIndex = elements.vertexCount;
for (int vIdx = 0; vIdx < vertices.length; ++vIdx) {
elements.color.add(colorOffset.x);
elements.color.add(colorOffset.y);
elements.color.add(colorOffset.z);
elements.color.add(colorOffset.w);
elements.vertices.add(vertices[vIdx].x + offsetX);
elements.vertices.add(vertices[vIdx].y + offsetY);
elements.vertices.add(vertices[vIdx].z + offsetZ);
elements.normals.add(normals[vIdx].x);
elements.normals.add(normals[vIdx].y);
elements.normals.add(normals[vIdx].z);
elements.flags.add(flags.getValue());
}
elements.vertexCount += vertices.length;
for (int index : indices) {
elements.indices.add(index + nextIndex);
}
}
use of org.terasology.rendering.primitives.ChunkMesh in project Terasology by MovingBlocks.
the class RenderableWorldImpl method generateVBOs.
@Override
public void generateVBOs() {
PerformanceMonitor.startActivity("Building Mesh VBOs");
ChunkMesh pendingMesh;
chunkMeshUpdateManager.setCameraPosition(playerCamera.getPosition());
for (RenderableChunk chunk : chunkMeshUpdateManager.availableChunksForUpdate()) {
if (chunk.hasPendingMesh() && chunksInProximityOfCamera.contains(chunk)) {
pendingMesh = chunk.getPendingMesh();
pendingMesh.generateVBOs();
if (chunk.hasMesh()) {
chunk.getMesh().dispose();
}
chunk.setMesh(pendingMesh);
chunk.setPendingMesh(null);
} else {
if (chunk.hasPendingMesh()) {
chunk.getPendingMesh().dispose();
chunk.setPendingMesh(null);
}
}
}
PerformanceMonitor.endActivity();
}
use of org.terasology.rendering.primitives.ChunkMesh in project Terasology by MovingBlocks.
the class OpaqueBlocksNode method process.
/**
* Renders the world's opaque blocks, effectively, the world's landscape.
* Does not render semi-transparent blocks, i.e. semi-transparent vegetation.
*
* If RenderingDebugConfig.isRenderChunkBoundingBoxes() returns true
* this method also draws wireframe boxes around chunks, displaying
* their boundaries.
*
* Finally, takes advantage of the two methods
*
* - WorldRenderer.increaseTrianglesCount(int)
* - WorldRenderer.increaseNotReadyChunkCount(int)
*
* to publish some statistics over its own activity.
*/
@Override
public void process() {
PerformanceMonitor.startActivity("rendering/" + getUri());
// Common Shader Parameters
chunkMaterial.setFloat("time", worldProvider.getTime().getDays(), true);
// Specific Shader Parameters
chunkMaterial.setFloat("clip", 0.0f, true);
if (normalMappingIsEnabled) {
if (parallaxMappingIsEnabled) {
chunkMaterial.setFloat4("parallaxProperties", parallaxBias, parallaxScale, 0.0f, 0.0f, true);
}
}
// Actual Node Processing
final Vector3f cameraPosition = activeCamera.getPosition();
int numberOfRenderedTriangles = 0;
int numberOfChunksThatAreNotReadyYet = 0;
while (renderQueues.chunksOpaque.size() > 0) {
RenderableChunk chunk = renderQueues.chunksOpaque.poll();
if (chunk.hasMesh()) {
final ChunkMesh chunkMesh = chunk.getMesh();
final Vector3f chunkPosition = chunk.getPosition().toVector3f();
chunkMesh.updateMaterial(chunkMaterial, chunkPosition, chunk.isAnimated());
numberOfRenderedTriangles += chunkMesh.render(OPAQUE, chunkPosition, cameraPosition);
if (renderingDebugConfig.isRenderChunkBoundingBoxes()) {
renderChunkBoundingBox(chunk, chunkPosition, cameraPosition);
}
} else {
numberOfChunksThatAreNotReadyYet++;
}
}
worldRenderer.increaseTrianglesCount(numberOfRenderedTriangles);
worldRenderer.increaseNotReadyChunkCount(numberOfChunksThatAreNotReadyYet);
PerformanceMonitor.endActivity();
}
use of org.terasology.rendering.primitives.ChunkMesh in project Terasology by MovingBlocks.
the class RefractiveReflectiveBlocksNode method process.
/**
* This method is where the actual rendering of refractive/reflective blocks takes place.
*
* Also takes advantage of the two methods
*
* - WorldRenderer.increaseTrianglesCount(int)
* - WorldRenderer.increaseNotReadyChunkCount(int)
*
* to publish some statistics over its own activity.
*/
@Override
public void process() {
PerformanceMonitor.startActivity("rendering/" + getUri());
chunkMaterial.activateFeature(ShaderProgramFeature.FEATURE_REFRACTIVE_PASS);
// Common Shader Parameters
sunDirection = backdropProvider.getSunDirection(false);
chunkMaterial.setFloat("daylight", backdropProvider.getDaylight(), true);
chunkMaterial.setFloat("swimming", activeCamera.isUnderWater() ? 1.0f : 0.0f, true);
chunkMaterial.setFloat("time", worldProvider.getTime().getDays(), true);
chunkMaterial.setFloat3("sunVec", sunDirection, true);
// Specific Shader Parameters
// TODO: This is necessary right now because activateFeature removes all material parameters.
// TODO: Remove this explicit binding once we get rid of activateFeature, or find a way to retain parameters through it.
chunkMaterial.setInt("textureAtlas", 0, true);
chunkMaterial.setInt("textureEffects", 1, true);
chunkMaterial.setInt("textureWater", 2, true);
chunkMaterial.setInt("textureWaterNormal", 3, true);
chunkMaterial.setInt("textureWaterNormalAlt", 4, true);
chunkMaterial.setInt("textureWaterReflection", 5, true);
chunkMaterial.setInt("texSceneOpaque", 6, true);
if (normalMappingIsEnabled) {
chunkMaterial.setInt("textureAtlasNormal", 7, true);
if (parallaxMappingIsEnabled) {
chunkMaterial.setInt("textureAtlasHeight", 8, true);
chunkMaterial.setFloat4("parallaxProperties", parallaxBias, parallaxScale, 0.0f, 0.0f, true);
}
}
chunkMaterial.setFloat4("lightingSettingsFrag", 0, 0, waterSpecExp, 0, true);
chunkMaterial.setFloat4("waterSettingsFrag", waterNormalBias, waterRefraction, waterFresnelBias, waterFresnelPow, true);
chunkMaterial.setFloat4("alternativeWaterSettingsFrag", waterTint, 0, 0, 0, true);
if (animatedWaterIsEnabled) {
chunkMaterial.setFloat("waveIntensityFalloff", waveIntensityFalloff, true);
chunkMaterial.setFloat("waveSizeFalloff", waveSizeFalloff, true);
chunkMaterial.setFloat("waveSize", waveSize, true);
chunkMaterial.setFloat("waveSpeedFalloff", waveSpeedFalloff, true);
chunkMaterial.setFloat("waveSpeed", waveSpeed, true);
chunkMaterial.setFloat("waveIntensity", waveIntensity, true);
chunkMaterial.setFloat("waterOffsetY", waterOffsetY, true);
chunkMaterial.setFloat("waveOverallScale", waveOverallScale, true);
}
// Actual Node Processing
int numberOfRenderedTriangles = 0;
int numberOfChunksThatAreNotReadyYet = 0;
final Vector3f cameraPosition = activeCamera.getPosition();
while (renderQueues.chunksAlphaBlend.size() > 0) {
RenderableChunk chunk = renderQueues.chunksAlphaBlend.poll();
if (chunk.hasMesh()) {
final ChunkMesh chunkMesh = chunk.getMesh();
final Vector3f chunkPosition = chunk.getPosition().toVector3f();
chunkMesh.updateMaterial(chunkMaterial, chunkPosition, chunk.isAnimated());
numberOfRenderedTriangles += chunkMesh.render(REFRACTIVE, chunkPosition, cameraPosition);
} else {
numberOfChunksThatAreNotReadyYet++;
}
}
worldRenderer.increaseTrianglesCount(numberOfRenderedTriangles);
worldRenderer.increaseNotReadyChunkCount(numberOfChunksThatAreNotReadyYet);
chunkMaterial.deactivateFeature(ShaderProgramFeature.FEATURE_REFRACTIVE_PASS);
PerformanceMonitor.endActivity();
}
Aggregations