本文整理了Java中org.lwjglb.engine.graph.Mesh.renderList()
方法的一些代码示例,展示了Mesh.renderList()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mesh.renderList()
方法的具体详情如下:
包路径:org.lwjglb.engine.graph.Mesh
类名称:Mesh
方法名:renderList
暂无
代码示例来源:origin: lwjglgamedev/lwjglbook
private void renderNonInstancedMeshes(Scene scene, Transformation transformation) {
depthShaderProgram.setUniform("isInstanced", 0);
// Render each mesh with the associated game Items
Map<Mesh, List<GameItem>> mapMeshes = scene.getGameMeshes();
for (Mesh mesh : mapMeshes.keySet()) {
mesh.renderList(mapMeshes.get(mesh), (GameItem gameItem) -> {
Matrix4f modelMatrix = transformation.buildModelMatrix(gameItem);
depthShaderProgram.setUniform("modelNonInstancedMatrix", modelMatrix);
if (gameItem instanceof AnimGameItem) {
AnimGameItem animGameItem = (AnimGameItem) gameItem;
AnimatedFrame frame = animGameItem.getCurrentFrame();
depthShaderProgram.setUniform("jointsMatrix", frame.getJointMatrices());
}
}
);
}
}
代码示例来源:origin: lwjglgamedev/lwjglbook
private void renderNonInstancedMeshes(Scene scene, Transformation transformation) {
depthShaderProgram.setUniform("isInstanced", 0);
// Render each mesh with the associated game Items
Map<Mesh, List<GameItem>> mapMeshes = scene.getGameMeshes();
for (Mesh mesh : mapMeshes.keySet()) {
mesh.renderList(mapMeshes.get(mesh), (GameItem gameItem) -> {
Matrix4f modelMatrix = transformation.buildModelMatrix(gameItem);
depthShaderProgram.setUniform("modelNonInstancedMatrix", modelMatrix);
if (gameItem instanceof AnimGameItem) {
AnimGameItem animGameItem = (AnimGameItem) gameItem;
AnimatedFrame frame = animGameItem.getCurrentFrame();
depthShaderProgram.setUniform("jointsMatrix", frame.getJointMatrices());
}
}
);
}
}
代码示例来源:origin: lwjglgamedev/lwjglbook
private void renderNonInstancedMeshes(Scene scene, Transformation transformation) {
depthShaderProgram.setUniform("isInstanced", 0);
// Render each mesh with the associated game Items
Map<Mesh, List<GameItem>> mapMeshes = scene.getGameMeshes();
for (Mesh mesh : mapMeshes.keySet()) {
mesh.renderList(mapMeshes.get(mesh), (GameItem gameItem) -> {
Matrix4f modelMatrix = transformation.buildModelMatrix(gameItem);
depthShaderProgram.setUniform("modelNonInstancedMatrix", modelMatrix);
if (gameItem instanceof AnimGameItem) {
AnimGameItem animGameItem = (AnimGameItem) gameItem;
AnimatedFrame frame = animGameItem.getCurrentAnimation().getCurrentFrame();
depthShaderProgram.setUniform("jointsMatrix", frame.getJointMatrices());
}
}
);
}
}
代码示例来源:origin: lwjglgamedev/lwjglbook
private void renderNonInstancedMeshes(Scene scene, Transformation transformation) {
depthShaderProgram.setUniform("isInstanced", 0);
// Render each mesh with the associated game Items
Map<Mesh, List<GameItem>> mapMeshes = scene.getGameMeshes();
for (Mesh mesh : mapMeshes.keySet()) {
mesh.renderList(mapMeshes.get(mesh), (GameItem gameItem) -> {
Matrix4f modelMatrix = transformation.buildModelMatrix(gameItem);
depthShaderProgram.setUniform("modelNonInstancedMatrix", modelMatrix);
if (gameItem instanceof AnimGameItem) {
AnimGameItem animGameItem = (AnimGameItem) gameItem;
AnimatedFrame frame = animGameItem.getCurrentAnimation().getCurrentFrame();
depthShaderProgram.setUniform("jointsMatrix", frame.getJointMatrices());
}
}
);
}
}
代码示例来源:origin: lwjglgamedev/lwjglbook
private void renderDepthMap(Window window, Camera camera, Scene scene) {
// Setup view port to match the texture size
glBindFramebuffer(GL_FRAMEBUFFER, shadowMap.getDepthMapFBO());
glViewport(0, 0, ShadowMap.SHADOW_MAP_WIDTH, ShadowMap.SHADOW_MAP_HEIGHT);
glClear(GL_DEPTH_BUFFER_BIT);
depthShaderProgram.bind();
DirectionalLight light = scene.getSceneLight().getDirectionalLight();
Vector3f lightDirection = light.getDirection();
float lightAngleX = (float)Math.toDegrees(Math.acos(lightDirection.z));
float lightAngleY = (float)Math.toDegrees(Math.asin(lightDirection.x));
float lightAngleZ = 0;
Matrix4f lightViewMatrix = transformation.updateLightViewMatrix(new Vector3f(lightDirection).mul(light.getShadowPosMult()), new Vector3f(lightAngleX, lightAngleY, lightAngleZ));
DirectionalLight.OrthoCoords orthCoords = light.getOrthoCoords();
Matrix4f orthoProjMatrix = transformation.updateOrthoProjectionMatrix(orthCoords.left, orthCoords.right, orthCoords.bottom, orthCoords.top, orthCoords.near, orthCoords.far);
depthShaderProgram.setUniform("orthoProjectionMatrix", orthoProjMatrix);
Map<Mesh, List<GameItem>> mapMeshes = scene.getGameMeshes();
for (Mesh mesh : mapMeshes.keySet()) {
mesh.renderList(mapMeshes.get(mesh), (GameItem gameItem) -> {
Matrix4f modelLightViewMatrix = transformation.buildModelViewMatrix(gameItem, lightViewMatrix);
depthShaderProgram.setUniform("modelLightViewMatrix", modelLightViewMatrix);
}
);
}
// Unbind
depthShaderProgram.unbind();
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
代码示例来源:origin: lwjglgamedev/lwjglbook
private void renderDepthMap(Window window, Camera camera, Scene scene) {
// Setup view port to match the texture size
glBindFramebuffer(GL_FRAMEBUFFER, shadowMap.getDepthMapFBO());
glViewport(0, 0, ShadowMap.SHADOW_MAP_WIDTH, ShadowMap.SHADOW_MAP_HEIGHT);
glClear(GL_DEPTH_BUFFER_BIT);
depthShaderProgram.bind();
DirectionalLight light = scene.getSceneLight().getDirectionalLight();
Vector3f lightDirection = light.getDirection();
float lightAngleX = (float)Math.toDegrees(Math.acos(lightDirection.z));
float lightAngleY = (float)Math.toDegrees(Math.asin(lightDirection.x));
float lightAngleZ = 0;
Matrix4f lightViewMatrix = transformation.updateLightViewMatrix(new Vector3f(lightDirection).mul(light.getShadowPosMult()), new Vector3f(lightAngleX, lightAngleY, lightAngleZ));
DirectionalLight.OrthoCoords orthCoords = light.getOrthoCoords();
Matrix4f orthoProjMatrix = transformation.updateOrthoProjectionMatrix(orthCoords.left, orthCoords.right, orthCoords.bottom, orthCoords.top, orthCoords.near, orthCoords.far);
depthShaderProgram.setUniform("orthoProjectionMatrix", orthoProjMatrix);
Map<Mesh, List<GameItem>> mapMeshes = scene.getGameMeshes();
for (Mesh mesh : mapMeshes.keySet()) {
mesh.renderList(mapMeshes.get(mesh), (GameItem gameItem) -> {
Matrix4f modelLightViewMatrix = transformation.buildModelViewMatrix(gameItem, lightViewMatrix);
depthShaderProgram.setUniform("modelLightViewMatrix", modelLightViewMatrix);
}
);
}
// Unbind
depthShaderProgram.unbind();
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
代码示例来源:origin: lwjglgamedev/lwjglbook
private void renderDepthMap(Window window, Camera camera, Scene scene) {
// Setup view port to match the texture size
glBindFramebuffer(GL_FRAMEBUFFER, shadowMap.getDepthMapFBO());
glViewport(0, 0, ShadowMap.SHADOW_MAP_WIDTH, ShadowMap.SHADOW_MAP_HEIGHT);
glClear(GL_DEPTH_BUFFER_BIT);
depthShaderProgram.bind();
DirectionalLight light = scene.getSceneLight().getDirectionalLight();
Vector3f lightDirection = light.getDirection();
float lightAngleX = (float)Math.toDegrees(Math.acos(lightDirection.z));
float lightAngleY = (float)Math.toDegrees(Math.asin(lightDirection.x));
float lightAngleZ = 0;
Matrix4f lightViewMatrix = transformation.updateLightViewMatrix(new Vector3f(lightDirection).mul(light.getShadowPosMult()), new Vector3f(lightAngleX, lightAngleY, lightAngleZ));
DirectionalLight.OrthoCoords orthCoords = light.getOrthoCoords();
Matrix4f orthoProjMatrix = transformation.updateOrthoProjectionMatrix(orthCoords.left, orthCoords.right, orthCoords.bottom, orthCoords.top, orthCoords.near, orthCoords.far);
depthShaderProgram.setUniform("orthoProjectionMatrix", orthoProjMatrix);
Map<Mesh, List<GameItem>> mapMeshes = scene.getGameMeshes();
for (Mesh mesh : mapMeshes.keySet()) {
mesh.renderList(mapMeshes.get(mesh), (GameItem gameItem) -> {
Matrix4f modelLightViewMatrix = transformation.buildModelViewMatrix(gameItem, lightViewMatrix);
depthShaderProgram.setUniform("modelLightViewMatrix", modelLightViewMatrix);
}
);
}
// Unbind
depthShaderProgram.unbind();
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
代码示例来源:origin: lwjglgamedev/lwjglbook
public void renderScene(Window window, Camera camera, Scene scene) {
sceneShaderProgram.bind();
Matrix4f projectionMatrix = transformation.getProjectionMatrix();
sceneShaderProgram.setUniform("projectionMatrix", projectionMatrix);
Matrix4f viewMatrix = transformation.getViewMatrix();
SceneLight sceneLight = scene.getSceneLight();
renderLights(viewMatrix, sceneLight);
sceneShaderProgram.setUniform("texture_sampler", 0);
// Render each mesh with the associated game Items
Map<Mesh, List<GameItem>> mapMeshes = scene.getGameMeshes();
for (Mesh mesh : mapMeshes.keySet()) {
sceneShaderProgram.setUniform("material", mesh.getMaterial());
mesh.renderList(mapMeshes.get(mesh), (GameItem gameItem) -> {
Matrix4f modelViewMatrix = transformation.buildModelViewMatrix(gameItem, viewMatrix);
sceneShaderProgram.setUniform("modelViewMatrix", modelViewMatrix);
}
);
}
sceneShaderProgram.unbind();
}
代码示例来源:origin: lwjglgamedev/lwjglbook
public void renderScene(Window window, Camera camera, Scene scene) {
sceneShaderProgram.bind();
Matrix4f projectionMatrix = transformation.getProjectionMatrix();
sceneShaderProgram.setUniform("projectionMatrix", projectionMatrix);
Matrix4f viewMatrix = transformation.getViewMatrix();
SceneLight sceneLight = scene.getSceneLight();
renderLights(viewMatrix, sceneLight);
sceneShaderProgram.setUniform("texture_sampler", 0);
// Render each mesh with the associated game Items
Map<Mesh, List<GameItem>> mapMeshes = scene.getGameMeshes();
for (Mesh mesh : mapMeshes.keySet()) {
sceneShaderProgram.setUniform("material", mesh.getMaterial());
mesh.renderList(mapMeshes.get(mesh), (GameItem gameItem) -> {
Matrix4f modelViewMatrix = transformation.buildModelViewMatrix(gameItem, viewMatrix);
sceneShaderProgram.setUniform("modelViewMatrix", modelViewMatrix);
}
);
}
sceneShaderProgram.unbind();
}
代码示例来源:origin: lwjglgamedev/lwjglbook
private void renderDepthMap(Window window, Camera camera, Scene scene) {
// Setup view port to match the texture size
glBindFramebuffer(GL_FRAMEBUFFER, shadowMap.getDepthMapFBO());
glViewport(0, 0, ShadowMap.SHADOW_MAP_WIDTH, ShadowMap.SHADOW_MAP_HEIGHT);
glClear(GL_DEPTH_BUFFER_BIT);
depthShaderProgram.bind();
DirectionalLight light = scene.getSceneLight().getDirectionalLight();
Vector3f lightDirection = light.getDirection();
float lightAngleX = (float)Math.toDegrees(Math.acos(lightDirection.z));
float lightAngleY = (float)Math.toDegrees(Math.asin(lightDirection.x));
float lightAngleZ = 0;
Matrix4f lightViewMatrix = transformation.updateLightViewMatrix(new Vector3f(lightDirection).mul(light.getShadowPosMult()), new Vector3f(lightAngleX, lightAngleY, lightAngleZ));
DirectionalLight.OrthoCoords orthCoords = light.getOrthoCoords();
Matrix4f orthoProjMatrix = transformation.updateOrthoProjectionMatrix(orthCoords.left, orthCoords.right, orthCoords.bottom, orthCoords.top, orthCoords.near, orthCoords.far);
depthShaderProgram.setUniform("orthoProjectionMatrix", orthoProjMatrix);
Map<Mesh, List<GameItem>> mapMeshes = scene.getGameMeshes();
for (Mesh mesh : mapMeshes.keySet()) {
mesh.renderList(mapMeshes.get(mesh), (GameItem gameItem) -> {
Matrix4f modelLightViewMatrix = transformation.buildModelViewMatrix(gameItem, lightViewMatrix);
depthShaderProgram.setUniform("modelLightViewMatrix", modelLightViewMatrix);
}
);
}
// Unbind
depthShaderProgram.unbind();
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
代码示例来源:origin: lwjglgamedev/lwjglbook
public void renderScene(Window window, Camera camera, Scene scene) {
sceneShaderProgram.bind();
Matrix4f projectionMatrix = transformation.getProjectionMatrix();
sceneShaderProgram.setUniform("projectionMatrix", projectionMatrix);
Matrix4f viewMatrix = transformation.getViewMatrix();
SceneLight sceneLight = scene.getSceneLight();
renderLights(viewMatrix, sceneLight);
sceneShaderProgram.setUniform("texture_sampler", 0);
// Render each mesh with the associated game Items
Map<Mesh, List<GameItem>> mapMeshes = scene.getGameMeshes();
for (Mesh mesh : mapMeshes.keySet()) {
sceneShaderProgram.setUniform("material", mesh.getMaterial());
mesh.renderList(mapMeshes.get(mesh), (GameItem gameItem) -> {
Matrix4f modelViewMatrix = transformation.buildModelViewMatrix(gameItem, viewMatrix);
sceneShaderProgram.setUniform("modelViewMatrix", modelViewMatrix);
}
);
}
sceneShaderProgram.unbind();
}
代码示例来源:origin: lwjglgamedev/lwjglbook
public void renderScene(Window window, Camera camera, Scene scene) {
sceneShaderProgram.bind();
Matrix4f projectionMatrix = transformation.getProjectionMatrix();
sceneShaderProgram.setUniform("projectionMatrix", projectionMatrix);
Matrix4f viewMatrix = transformation.getViewMatrix();
SceneLight sceneLight = scene.getSceneLight();
renderLights(viewMatrix, sceneLight);
sceneShaderProgram.setUniform("texture_sampler", 0);
sceneShaderProgram.setUniform("fog", scene.getFog());
// Render each mesh with the associated game Items
Map<Mesh, List<GameItem>> mapMeshes = scene.getGameMeshes();
for (Mesh mesh : mapMeshes.keySet()) {
sceneShaderProgram.setUniform("material", mesh.getMaterial());
mesh.renderList(mapMeshes.get(mesh), (GameItem gameItem) -> {
Matrix4f modelViewMatrix = transformation.buildModelViewMatrix(gameItem, viewMatrix);
sceneShaderProgram.setUniform("modelViewMatrix", modelViewMatrix);
}
);
}
sceneShaderProgram.unbind();
}
代码示例来源:origin: lwjglgamedev/lwjglbook
public void renderScene(Window window, Camera camera, Scene scene) {
sceneShaderProgram.bind();
Matrix4f projectionMatrix = transformation.getProjectionMatrix();
sceneShaderProgram.setUniform("projectionMatrix", projectionMatrix);
Matrix4f viewMatrix = transformation.getViewMatrix();
SceneLight sceneLight = scene.getSceneLight();
renderLights(viewMatrix, sceneLight);
sceneShaderProgram.setUniform("fog", scene.getFog());
sceneShaderProgram.setUniform("texture_sampler", 0);
sceneShaderProgram.setUniform("normalMap", 1);
// Render each mesh with the associated game Items
Map<Mesh, List<GameItem>> mapMeshes = scene.getGameMeshes();
for (Mesh mesh : mapMeshes.keySet()) {
sceneShaderProgram.setUniform("material", mesh.getMaterial());
mesh.renderList(mapMeshes.get(mesh), (GameItem gameItem) -> {
Matrix4f modelViewMatrix = transformation.buildModelViewMatrix(gameItem, viewMatrix);
sceneShaderProgram.setUniform("modelViewMatrix", modelViewMatrix);
}
);
}
sceneShaderProgram.unbind();
}
代码示例来源:origin: lwjglgamedev/lwjglbook
private void renderNonInstancedMeshes(Scene scene, boolean depthMap, ShaderProgram shader, Matrix4f viewMatrix, Matrix4f lightViewMatrix) {
sceneShaderProgram.setUniform("isInstanced", 0);
// Render each mesh with the associated game Items
Map<Mesh, List<GameItem>> mapMeshes = scene.getGameMeshes();
for (Mesh mesh : mapMeshes.keySet()) {
if (!depthMap) {
shader.setUniform("material", mesh.getMaterial());
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, shadowMap.getDepthMapTexture().getId());
}
mesh.renderList(mapMeshes.get(mesh), (GameItem gameItem) -> {
Matrix4f modelMatrix = transformation.buildModelMatrix(gameItem);
if (!depthMap) {
Matrix4f modelViewMatrix = transformation.buildModelViewMatrix(modelMatrix, viewMatrix);
sceneShaderProgram.setUniform("modelViewNonInstancedMatrix", modelViewMatrix);
}
Matrix4f modelLightViewMatrix = transformation.buildModelLightViewMatrix(modelMatrix, lightViewMatrix);
sceneShaderProgram.setUniform("modelLightViewNonInstancedMatrix", modelLightViewMatrix);
if (gameItem instanceof AnimGameItem) {
AnimGameItem animGameItem = (AnimGameItem) gameItem;
AnimatedFrame frame = animGameItem.getCurrentFrame();
shader.setUniform("jointsMatrix", frame.getJointMatrices());
}
}
);
}
}
代码示例来源:origin: lwjglgamedev/lwjglbook
private void renderNonInstancedMeshes(Scene scene) {
gBufferShaderProgram.setUniform("isInstanced", 0);
// Render each mesh with the associated game Items
Map<Mesh, List<GameItem>> mapMeshes = scene.getGameMeshes();
for (Mesh mesh : mapMeshes.keySet()) {
gBufferShaderProgram.setUniform("material", mesh.getMaterial());
Texture text = mesh.getMaterial().getTexture();
if (text != null) {
gBufferShaderProgram.setUniform("numCols", text.getNumCols());
gBufferShaderProgram.setUniform("numRows", text.getNumRows());
}
mesh.renderList(mapMeshes.get(mesh), (GameItem gameItem) -> {
gBufferShaderProgram.setUniform("selectedNonInstanced", gameItem.isSelected() ? 1.0f : 0.0f);
Matrix4f modelMatrix = transformation.buildModelMatrix(gameItem);
gBufferShaderProgram.setUniform("modelNonInstancedMatrix", modelMatrix);
if (gameItem instanceof AnimGameItem) {
AnimGameItem animGameItem = (AnimGameItem) gameItem;
AnimatedFrame frame = animGameItem.getCurrentAnimation().getCurrentFrame();
gBufferShaderProgram.setUniform("jointsMatrix", frame.getJointMatrices());
}
}
);
}
}
代码示例来源:origin: lwjglgamedev/lwjglbook
private void renderNonInstancedMeshes(Scene scene) {
sceneShaderProgram.setUniform("isInstanced", 0);
// Render each mesh with the associated game Items
Map<Mesh, List<GameItem>> mapMeshes = scene.getGameMeshes();
for (Mesh mesh : mapMeshes.keySet()) {
sceneShaderProgram.setUniform("material", mesh.getMaterial());
Texture text = mesh.getMaterial().getTexture();
if (text != null) {
sceneShaderProgram.setUniform("numCols", text.getNumCols());
sceneShaderProgram.setUniform("numRows", text.getNumRows());
}
shadowRenderer.bindTextures(GL_TEXTURE2);
mesh.renderList(mapMeshes.get(mesh), (GameItem gameItem) -> {
sceneShaderProgram.setUniform("selectedNonInstanced", gameItem.isSelected() ? 1.0f : 0.0f);
Matrix4f modelMatrix = transformation.buildModelMatrix(gameItem);
sceneShaderProgram.setUniform("modelNonInstancedMatrix", modelMatrix);
if (gameItem instanceof AnimGameItem) {
AnimGameItem animGameItem = (AnimGameItem) gameItem;
AnimatedFrame frame = animGameItem.getCurrentFrame();
sceneShaderProgram.setUniform("jointsMatrix", frame.getJointMatrices());
}
}
);
}
}
代码示例来源:origin: lwjglgamedev/lwjglbook
private void renderNonInstancedMeshes(Scene scene) {
sceneShaderProgram.setUniform("isInstanced", 0);
// Render each mesh with the associated game Items
Map<Mesh, List<GameItem>> mapMeshes = scene.getGameMeshes();
for (Mesh mesh : mapMeshes.keySet()) {
sceneShaderProgram.setUniform("material", mesh.getMaterial());
Texture text = mesh.getMaterial().getTexture();
if (text != null) {
sceneShaderProgram.setUniform("numCols", text.getNumCols());
sceneShaderProgram.setUniform("numRows", text.getNumRows());
}
shadowRenderer.bindTextures(GL_TEXTURE2);
mesh.renderList(mapMeshes.get(mesh), (GameItem gameItem) -> {
sceneShaderProgram.setUniform("selectedNonInstanced", gameItem.isSelected() ? 1.0f : 0.0f);
Matrix4f modelMatrix = transformation.buildModelMatrix(gameItem);
sceneShaderProgram.setUniform("modelNonInstancedMatrix", modelMatrix);
if (gameItem instanceof AnimGameItem) {
AnimGameItem animGameItem = (AnimGameItem) gameItem;
AnimatedFrame frame = animGameItem.getCurrentFrame();
sceneShaderProgram.setUniform("jointsMatrix", frame.getJointMatrices());
}
}
);
}
}
代码示例来源:origin: lwjglgamedev/lwjglbook
private void renderNonInstancedMeshes(Scene scene) {
sceneShaderProgram.setUniform("isInstanced", 0);
// Render each mesh with the associated game Items
Map<Mesh, List<GameItem>> mapMeshes = scene.getGameMeshes();
for (Mesh mesh : mapMeshes.keySet()) {
sceneShaderProgram.setUniform("material", mesh.getMaterial());
Texture text = mesh.getMaterial().getTexture();
if (text != null) {
sceneShaderProgram.setUniform("numCols", text.getNumCols());
sceneShaderProgram.setUniform("numRows", text.getNumRows());
}
shadowRenderer.bindTextures(GL_TEXTURE2);
mesh.renderList(mapMeshes.get(mesh), (GameItem gameItem) -> {
sceneShaderProgram.setUniform("selectedNonInstanced", gameItem.isSelected() ? 1.0f : 0.0f);
Matrix4f modelMatrix = transformation.buildModelMatrix(gameItem);
sceneShaderProgram.setUniform("modelNonInstancedMatrix", modelMatrix);
if (gameItem instanceof AnimGameItem) {
AnimGameItem animGameItem = (AnimGameItem) gameItem;
AnimatedFrame frame = animGameItem.getCurrentAnimation().getCurrentFrame();
sceneShaderProgram.setUniform("jointsMatrix", frame.getJointMatrices());
}
}
);
}
}
代码示例来源:origin: lwjglgamedev/lwjglbook
public void renderScene(Window window, Camera camera, Scene scene) {
sceneShaderProgram.bind();
Matrix4f projectionMatrix = transformation.getProjectionMatrix();
sceneShaderProgram.setUniform("projectionMatrix", projectionMatrix);
Matrix4f orthoProjMatrix = transformation.getOrthoProjectionMatrix();
sceneShaderProgram.setUniform("orthoProjectionMatrix", orthoProjMatrix);
Matrix4f lightViewMatrix = transformation.getLightViewMatrix();
Matrix4f viewMatrix = transformation.getViewMatrix();
SceneLight sceneLight = scene.getSceneLight();
renderLights(viewMatrix, sceneLight);
sceneShaderProgram.setUniform("fog", scene.getFog());
sceneShaderProgram.setUniform("texture_sampler", 0);
sceneShaderProgram.setUniform("normalMap", 1);
sceneShaderProgram.setUniform("shadowMap", 2);
// Render each mesh with the associated game Items
Map<Mesh, List<GameItem>> mapMeshes = scene.getGameMeshes();
for (Mesh mesh : mapMeshes.keySet()) {
sceneShaderProgram.setUniform("material", mesh.getMaterial());
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, shadowMap.getDepthMapTexture().getId());
mesh.renderList(mapMeshes.get(mesh), (GameItem gameItem) -> {
Matrix4f modelViewMatrix = transformation.buildModelViewMatrix(gameItem, viewMatrix);
sceneShaderProgram.setUniform("modelViewMatrix", modelViewMatrix);
Matrix4f modelLightViewMatrix = transformation.buildModelLightViewMatrix(gameItem, lightViewMatrix);
sceneShaderProgram.setUniform("modelLightViewMatrix", modelLightViewMatrix);
}
);
}
sceneShaderProgram.unbind();
}
代码示例来源:origin: lwjglgamedev/lwjglbook
private void renderParticles(Window window, Camera camera, Scene scene) {
particlesShaderProgram.bind();
particlesShaderProgram.setUniform("texture_sampler", 0);
Matrix4f projectionMatrix = transformation.getProjectionMatrix();
particlesShaderProgram.setUniform("projectionMatrix", projectionMatrix);
Matrix4f viewMatrix = transformation.getViewMatrix();
IParticleEmitter[] emitters = scene.getParticleEmitters();
int numEmitters = emitters != null ? emitters.length : 0;
glDepthMask(false);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
for (int i = 0; i < numEmitters; i++) {
IParticleEmitter emitter = emitters[i];
Mesh mesh = emitter.getBaseParticle().getMesh();
mesh.renderList((emitter.getParticles()), (GameItem gameItem) -> {
Matrix4f modelMatrix = transformation.buildModelMatrix(gameItem);
viewMatrix.transpose3x3(modelMatrix);
Matrix4f modelViewMatrix = transformation.buildModelViewMatrix(modelMatrix, viewMatrix);
modelViewMatrix.scale(gameItem.getScale());
particlesShaderProgram.setUniform("modelViewMatrix", modelViewMatrix);
}
);
}
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDepthMask(true);
particlesShaderProgram.unbind();
}
内容来源于网络,如有侵权,请联系作者删除!