Giter Club home page Giter Club logo

modelinstancedrendering's Introduction

ModelInstancedRendering

This repo provides a libGDX v1.12 demonstration of instanced 3D rendering. The desktop version will render 1.03 million 3D cubes. GWT, teaVM and android version will render just under 25 thousand cubes.

image

Since libGDX v1.12 now has WebGL 2 support for GWT and teaVM, you can now use instancing in GWT and teaVM projects.

Tested on desktop, android, teaVM and GWT. iOS project is included but not tested.

You can run the demonstration, or download the desktop and android binaries here: https://antzgames.itch.io/modelinstancedrendering

Documentation - HowTo

The code is heavily documented so the best way to learn is to look at the code. Before this project I had zero knowledge about OpenGL instancing. Below are the two sources I started with:

Official libGDX instance test: ModelInstancedRenderingTest.java

Learn OpenGL Instancing: https://learnopengl.com/Advanced-OpenGL/Instancing

Limitations

Depending on your hardware you will not get good frame rates with 1 million cubes on desktop. Reduce INSTANCE_COUNT_SIDE value and make sure it is an odd number so that the camera is not in the middle of a cube on startup.

GWT performance is around 20k-30k cubes depending on hardware.

teaVM will have severe performance drop when cubes are rotating until gdx-teavm's FloatBuffer issues are resolved.

Voxel Terrain

I have a method to create a very simple minecraft terrain included in the code. You just need to comment out original + uncomment voxel method in ModelInstancedRenderingScreen.java as shown below:

        //createBoxField(); // regular box field
        createVoxelTerrain(); // simple minecraft terrain

Videos

Regular box field:

2023-07-10.16-35-21.mp4

Very simple voxel terrain:

2023-07-10.16-37-30.mp4

Project Structure

A libGDX project generated with gdx-liftoff.

This project was generated with a template including simple application launchers and a main class extending Game that sets the first screen.

Platforms

  • core: Main module with the application logic shared by all platforms.
  • lwjgl3: Primary desktop platform using LWJGL3.
  • android: Android mobile platform. Needs Android SDK.
  • ios: iOS mobile platform using RoboVM.
  • html: Web platform using GWT and WebGL. Supports only Java projects.

Gradle

This project uses Gradle to manage dependencies. The Gradle wrapper was included, so you can run Gradle tasks using gradlew.bat or ./gradlew commands. Useful Gradle tasks and flags:

  • --continue: when using this flag, errors will not stop the tasks from running.
  • --daemon: thanks to this flag, Gradle daemon will be used to run chosen tasks.
  • --offline: when using this flag, cached dependency archives will be used.
  • --refresh-dependencies: this flag forces validation of all dependencies. Useful for snapshot versions.
  • android:lint: performs Android project validation.
  • build: builds sources and archives of every project.
  • cleanEclipse: removes Eclipse project data.
  • cleanIdea: removes IntelliJ project data.
  • clean: removes build folders, which store compiled classes and built archives.
  • eclipse: generates Eclipse project data.
  • html:dist: compiles GWT sources. The compiled application can be found at html/build/dist: you can use any HTTP server to deploy it.
  • html:superDev: compiles GWT sources and runs the application in SuperDev mode. It will be available at localhost:8080/html. Use only during development.
  • idea: generates IntelliJ project data.
  • lwjgl3:jar: builds application's runnable jar, which can be found at lwjgl3/build/libs.
  • lwjgl3:run: starts the application.
  • test: runs unit tests (if any).

Note that most tasks that are not specific to a single project can be run with name: prefix, where the name should be replaced with the ID of a specific project. For example, core:clean removes build folder only from the core project.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.