mkrebser / gpuinstance Goto Github PK
View Code? Open in Web Editor NEWInstancing & Animation library for Unity3D
License: Other
Instancing & Animation library for Unity3D
License: Other
I know for a fact that the instance was initialized because I literally see it, and when trying to initialize it again, I get the "already initialized" error. I also know the parentID is 1 on every instance parented at startup, and that I'm inputting 1 to the new instances, so it's not that. Is there something I'm doing wrong? How do I parent new instances to an old instance? Sorry if this is another case of me missing it in the code guide or something, but I'm pretty lost.
Thank you once again,
Max
This isn't really an issue, but I wanted to leave you a positive review/comment. Not sure where else to leave this.
Compliment!: Comparing to the other competing solutions (where they bake vertex positions from each animation into a texture), this one appears to be superior, in that you bake the Bone Keyframes to the GPU and do animation normally using the bones. That's a LOT less data to be processed and sent to the GPU, and seems to me as a superior solution.
Question: How does your solution stack up against the "GPU Instancer" on the Asset Store (and it's add-on "Crowd Animations"?
BUG: I did find one bug -- the "Camera Culling" was only showing a "sliver" of content, instead of true "near to far distance of frustum" (was instead like distance 10 to 12, not 0.1 to 100 as I'd expect). So I nulled this out so that I could see more content.... and with 10,000 non-culled walking animated characters, I'm still running at 30 FPS.
Hi, its support URP?
Hey,
Thank you for the awesome package.
In my WebGL build in the initialization I get the error Kernel 'UpdateBuffers' not found
.
Also in the updates I get Error, must invoke function from main thread!
. Since there is only one thread in WebGL, I commented this exception out but got other exceptions instead.
Is there something I am not doing write or there should be modifications applied for the package to work with WebGL?
Tested With
Due to some API changes on the Unity side, I changed all errors after that windows build, and (editor play mode) worked as expected I don't have any experience on shader(and also types and requirements)
On Android, there is two error
Is this project suitable for mobile? If so, what are the things I need to do to solve the current bugs ?
Please help where I could look or give me an example of transform base animation. (sorry for bad English)
Hello! I've been working on a voxel engine in Unity using your instancing library for the rendering of the voxels, and after stress testing, concluded that I desperately needed LOD models for distant voxels in the case of larger-scale maps. After setting up the LOD settings I got much better performance, but because of the shape of my LOD models, had very obvious shading differences in the distant lower detail models than I did with the full-resolution voxels. This led me to try to make a shader that would either make the whole voxel model shaded or unshaded (uniform shading). I'm very new to shaders but was able to throw together an unlit one after some trial and error, only to realize it wasn't what I was looking for. I began trying to use a typical v2f shader with the instancing to have more control over the shadows and shading but quickly found that the voxels would now no longer instance correctly, instead instancing as white with their position all as 0,0,0. This happened a few times previously, during the creation of my unlit shader when I was missing any of the instancing-specific keywords or something, but in this case, I can't use the typical instancing keywords because I'm no longer using the standard surface shader. So I guess my question is;
(TLDR;) What parts are required to get the shader working right on instancing or do you have a workaround for uniform shading? Thank you so much for reading my ramblings in advance, and I hope this isn't too much to ask!
-Max
My current shader attempt:
Shader "Instanced/instancemesh_distantVoxel"
{
Properties
{
_MainTex("Albedo (RGB)", 2D) = "white" {}
//_LightingAdjustment("LightingAdjustment", Range(0, 3)) = 1.5
}
SubShader
{
Tags{ "RenderType" = "Opaque" }
LOD 200
CGPROGRAM
// Upgrade NOTE: excluded shader from OpenGL ES 2.0 because it uses non-square matrices
#pragma exclude_renderers gles
// Physically based Standard lighting model
#pragma surface surf Standard noforwardadd vertex:vert finalcolor:colorOverride
#pragma instancing_options procedural:setup
#pragma target 5.0
#pragma multi_compile_instancing
#include "AutoLight.cginc"
#include "Lighting.cginc"
sampler2D _MainTex;
half4 colorSample;
int sampledColor = 0;
float shadowAtten = 0;
//float _LightingAdjustment;
#include "gpuinstance_includes.cginc"
struct Input
{
float2 uv_MainTex;
fixed4 color;
};
void setup()
{
do_instance_setup();
}
void vert(inout appdata_full v, out Input o)
{
UNITY_INITIALIZE_OUTPUT(Input, o);
if (sampledColor < 1)
{
shadowAtten = SHADOW_ATTENUATION(v);
}
int id = get_instance_id();
o.color = get_instance_color(id);
}
void surf(Input IN, inout SurfaceOutputStandard o)
{
if (sampledColor < 1)
{
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * IN.color;
o.Albedo = c.rgb;
o.Alpha = c.a;
//o.Normal = 1;
o.Occlusion = 0;
o.Metallic = 0;
o.Smoothness = 0;
//o.Emission = c.rgb / (fixed4(1, 0.9568627f, 0.8392157f, 1) * 0.8f);
colorSample = half4(c.r, c.g, c.b, 1);
sampledColor++;
}
o.Albedo = colorSample;
o.Alpha = 1;
//o.Normal = 1;
o.Occlusion = 0;
o.Metallic = 0;
o.Smoothness = 0;
}
void colorOverride(Input IN, SurfaceOutputStandard o, inout fixed4 color)
{
color = colorSample / (1 + shadowAtten);
}
ENDCG
}
FallBack "Diffuse"
}
Hello,
this is not an issue. I just try to reach out to you this way. :)
First of all, I want to say this project is amazing! Compared to other gpu instancing solutions this one is by far the best!
I would love to have URP support. Is there any way you could help me in this regards? I tried to convert the shaders myself but without any luck. I would definitely be willing to pay for a URP version.
I created a "MainCamera" prefab, with the following adjusted settings on "CameraFreeFly" script:
Move Speed: 4
Sensitivity 4
Rotate When Down: Mouse1 (same as for Unity editor)
Sprint Multiplier: 7
The biggest need here is for "Mouse1" rotation (right mouse button) -- so that the camera isn't constantly rotating.
And the slower default speed with "7" Sprint, allows for fine-tuned motion, and fast motion (both needed for exploring the demo)
Then use this MainCamera Prefab in ALL demo scenes, and so if a user wants to adjust the Camera settings, they need only change the values on the prefab.
So this issue is just a suggestion to update to using a Camera prefab, with better settings (like those above).
Hi, the demos work very well. I had no problems with spawning to the points I wanted. At this point I want to run these codes for different shader types. For example the URP Lit shader. Is there an extra function for shader graph?
Hello again, I've been hard at work optimizing my voxel engine and it seems that the new thing causing major lag spikes is re-parenting voxels. When I disconnect a section of voxels from an object, I need them to do just that, disconnect, so I re-parent them to a new instance with the positioning of a rigibody, and they fall away. The issue is obviously that, the larger the group, the slower this re-parenting is. That's why I was wondering if it would be possible to group the voxels into large cuboids, and just change the texture of the instance based on the color of the voxels along its edge. This would mean, however, that I would need to use textures created at runtime and use a different one for each instance, as well as change them as I go. So, my question is, would these different textures differentiate the instances on the GPU and defeat the purpose of using this library, and if so, is there some way to re-texture them without doing that? Finally, if none of that's possible, how should I re-parent these instances more efficiently?
Thanks for your continued help,
-Max
Hi,
I want to use it as a method of introducing animations in dots as the official animation package is still not ready.
so i want to place the instances myself in code.
but setting position gives an error in as that is only available for billboards.
is there a way to set position of instances in code.
Hello again! I've noticed that when an instance's position is appended, it only visually applies a frame late, at least when compared with a transform. Is there a way to circumvent this? I typically wouldn't mind an issue this minor, but I'm attempting to use this instance as a player view model, making the delay quite noticeable to players when moving.
Thanks in advance,
Max
Xcode Packaging iOS to draw real-time point cloud will report an error:
ArgumentException: The t parameter is a generic type.
Parameter name: t
at UnityEngine.Rendering.CommandBuffer.SetBufferData (UnityEngine.ComputeBuffer buffer, System.Array data, System.Int32 managedBufferStartIndex, System.Int32 graphicsBufferStartIndex, System.Int32 count) [0x00000] in <00000000000000000000000000000000>:0
at GPUInstance.InstanceMeshDeltaBuffer`1+InstanceMeshIndirectIDBuffer[T].UpdateComputeBuffer (UnityEngine.ComputeBuffer buffer, UnityEngine.Rendering.CommandBuffer cmd) [0x00000] in <00000000000000000000000000000000>:0
at GPUInstance.instancemesh.computeshader_UpdateDataTask (System.Boolean& force_dispatch) [0x00000] in <00000000000000000000000000000000>:0
at GPUInstance.instancemesh.Update (System.Single dt) [0x00000] in <00000000000000000000000000000000>:0
at GPUInstance.MeshInstancer.Update (System.Single deltaTime) [0x00000] in <00000000000000000000000000000000>:0
at PointCloudSubscriber.Update () [0x00000] in <00000000000000000000000000000000>:0
I'm running the "instanceMeshAnimationDemo" with all of the block-people (225 x 225 = 50,625 instances!).
I set "Application.targetFrameRate = 60", so that it doesn't keep pegging my GPU Usage to 100% (and causing fan to turn on to cool it).... So for this demo, running at 60 FPS, it uses 41% of my GPU looking at the whole horde of them (all in frustum).
If I turn away, so that NONE are showing, the GPU is still 15%, even when Camera is still.
I'm not for sure, but this seems to indicate that maybe the "culling" logic could be optimized considerably.
One suggestion comes to mind:
So the culling would run at "{A} Hz" guaranteed (to account for animated movement coming in/out of focus), OR if the camera is turned Left/Right by "{B} Degrees". These should be user configurable.
I tried simply not calling "SelectRenderInstances" as much -- but apparently, in your pipeline, this is needed EVERY FRAME, else nothing shows up (thus my lame/easy attempt to optimize failed).
I scoured the codebase for info on this but the closest thing I could find was UniformCullingDistance and FrustumCullingType both of which seem to have no effect on the instance's render distance. Perhaps I'm assigning it incorrectly or something, but I can't figure it out so my question is, how do I change the culling distance of the instances the right way?
Hey, it's me again! I was wondering whether or not it would be possible to change the layer of each instance, as I want my camera to cull a specific instance and ignore the rest. I was messing with it and found that the instances use the default layer, so could change this on an instance basis?
Thanks as always,
-Max
Hi There
Really Powerful Tool You Have Created Here I'm Very Happy With How Stable It Is
My Question Is How Can I Enable/Disable Some Bones Per Animation To Achieve Some Sort Of Animation Blending
Kind Regards & Thanks For Taking Time To Answer Me
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.