Coder Social home page Coder Social logo

minimalinstancing's Introduction

MinimalInstancing

Part01

Sample project that shows how to use the Graphics.DrawInstanced() API.

InstanceColorShader.shader

This shader has the minimum amount of code needed to allow for user defined coloring and GPU intancing support

DrawInstancedScript.cs

Monobehaviour that takes in values for number of meshes in a grid (width x height) and draws the grid in batches of 1023 instances at a time Prefab and Material need to be supplied in order to draw something

InstancedMaterial.mat

Material that uses the InstanceColorShader to draw the instances of the mesh

InstancingScene.unity

Sample scene that draws 200 x 200 prisms in white color (as shown below)

Instanced Prisms

Part02

InstanceColorShader.shader

No change from Part01

DrawInstancedScript.cs

New functionality:

  1. Threshold: Specifies the min. noise value to accept. This is used for randomizing when prisms show up.
  2. ColorArray: Array of colors to show for the different prisms, used in the Material Property Block

Material Property Block

This controls the color setting on a per instance basis. Using this, we can have multiple colors on the same mesh, and keep them batched using Graphics.DrawMeshInstanced(). Calling

propertyBlock.SetVectorArray("_Color", batchedColorArray);
Graphics.DrawMeshInstanced(mMeshFilter.sharedMesh, 0, meshMaterial, batchedMatrices, batchCount, propertyBlock);

ensures that can pass the property block configured with an array down to the Shader so that it can extract the data per instance.

InstancedMaterial.mat

No chance from Part01

InstancingScene.unity

Sample scene that draws 200 x 200 prisms in white color (as shown below)

Instanced Prisms

minimalinstancing's People

Contributors

javdevgames avatar

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.