Coder Social home page Coder Social logo

colinleung-nilocat / unityurp-mobiledrawmeshinstancedindirectexample Goto Github PK

View Code? Open in Web Editor NEW
1.4K 30.0 224.0 3.13 MB

Example project to draw 1million grass instances on mobile

Home Page: https://youtu.be/A7rav4tS88s

License: MIT License

C# 58.12% ShaderLab 41.88%
unity mobile instancing indirect grass urp

unityurp-mobiledrawmeshinstancedindirectexample's Introduction

UnityURP-MobileDrawMeshInstancedIndirectExample

youtube runtime demo video: https://youtu.be/A7rav4tS88s
download .apk, try it on your android phone: https://drive.google.com/file/d/185JWZXYPnVyDnA451cEZkS2H2wOYSce_/view

DrawMeshInstancedIndirect ON screenshot DrawMeshInstancedIndirect ON (grass bending) screenshot screenshot DrawMeshInstancedIndirect OFF screenshot

Why create this repository?

To demonstrate an API that can draw millions of instance -> DrawMeshInstancedIndirect(), running on mobile devices.

Can this demo runs on midrange mobile?

  • can handle 10 million instances on Samsung Galaxy A70 (GPU = adreno612, not a strong GPU), 50~60fps, performance mainly affected by visible grass count on screen(draw distance = 125)
  • can handle 10 million instances on Lenovo S5 (GPU = adreno506, a weak GPU), 30fps, performance mainly affected by visible grass count on screen(draw distance = 75)

Requirement

if you want to try the pre-built .apk, your android device must support Opengles3.2 / Vulkan
download .apk: https://drive.google.com/file/d/185JWZXYPnVyDnA451cEZkS2H2wOYSce_/view

Where are the important files

https://github.com/ColinLeung-NiloCat/UnityURP-MobileDrawMeshInstancedIndirectExample/tree/master/Assets/URPMobileGrassInstancedIndirectDemo/InstancedIndirectGrass/Core

Editor

2019.4.15f1

Note

This is a simplified example repository to demonstrate DrawMeshInstancedIndirect API on mobile platform.
This repository is as simple as possible, only contains a simple CPU cell frustum culling(not even a quadtree) -> minimum compute GPU frustum culling (no Acceleration Algorithms), then just 1 DrawMeshInstancedIndirect call, nothing else, code is very short.

Lighting and animation is not the main focus of this project, but ~40% of the time was spent on writing grass shader's lighting & animation, you can have a look at InstancedIndirectGrass.shader if you are interested.

This repository also contains a RendererFeature(GrassBendingRTPrePass.cs) to render an offscreen RT(R8), which renders top down view grass bending area (by trail renderer following moving objects), it is a very simple method but the result is good enough for this demo.

reference

unityurp-mobiledrawmeshinstancedindirectexample's People

Contributors

colinleung-nilocat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

unityurp-mobiledrawmeshinstancedindirectexample's Issues

Pink triangle when built in Unity 2022.3.6

In Unity 2022.3.5 and 2022.3.6 the grass renders in the editor, but in a built application only a single pink triangle is drawn. If you move the camera close to the triangle the framerate drops significantly. The triangle can only be seen from one side.

Editor:
2023-08-05

Standalone build:
2023-08-05 (1)

The same issues occurs on:

  • Windows Direct 11
  • Windows Vulkan
  • Android Vulkan
  • iOS Metal

Note: Dynamic Resolution is broken in Unity 2022 so disable it on the camera before testing.

In the documentation for Graphics.DrawMeshInstancedIndirect, it says:
This function is now obsolete. Use Graphics.RenderMeshIndirect instead. Draws the same mesh multiple times using GPU instancing.

However, I was able to get the sample code in Graphics.DrawMeshInstancedIndirect to render a mesh such as a plane or cube in both the editor and a built application. The mesh wasn't pink like the grass, but they were rendered in the same position so it appeared like a single object. The example script is supposed to assign random positions to each instance but this doesn't seem to be working.

Can you fix this bug?

Без имени-1

Hi. Thanks for the grass shader example!

I found a bug. On a large area, when we look from above, some squares are visible. It happends when we change cellSize - in my case the cellSize is 10. If I change to 20 (for example) the squares also changed.

2

Code question: how to draw grass over terrain of uneven height?

Hello,

Thanks so much for publishing this. I've tried so many different grass assets for Unity (for VR) and this is hands down the best I've found--and most of the others I've tried I had to pay for.

I'm trying to understand the code and I have two questions for you (I'm new to URP):

  1. how would you go about drawing grass over an uneven terrain, taking the y position into consideration?
  2. Could one integrate a terrain mask for this so that the grass would follow the player but only render in certain places on the terrain based on the mask (e.g. where the grass ground layer is painted)?

Thanks again!
Kai

Licence

Hello friend,
i am terribly sorry to create an issue. But I have no idea how to send you a message :/
Please can I ask, if this grass project can be used in my RPG game? I really like the performance and stylized look.
I can see the licence is MIT. But i just want to be sure.
Thank you very much for any answer, and once again I am sorry to contact you this way.

I will delete the message if needed.

Have a nice day!! :))

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.