unity-technologies / nativerenderingplugin Goto Github PK
View Code? Open in Web Editor NEWC++ Rendering Plugin example for Unity
Home Page: https://docs.unity3d.com/Manual/NativePluginInterface.html
License: MIT License
C++ Rendering Plugin example for Unity
Home Page: https://docs.unity3d.com/Manual/NativePluginInterface.html
License: MIT License
Is this supported for 2018.4.36f1?
for some reason it can't get the interface for Vulkan to work on Android. I've tried several variations, 32 bit or 64 bit, Unity 2018.4 or 2020.1, Mono or il2cpp, changing min android version to 19 or 26, but the demo just crashes. Works fine for OpenGL
When I step through UnityPluginLoad
s_Graphics is set to a valid interface for IUnityGraphics
s_Graphics->GetRenderer() is returning kUnityGfxRendererVulkan as expected
but unityInterfaces->Get<IUnityGraphicsVulkan>()
is returning NULL
I've checked, it's not a matter of timing, because even if I call s_UnityInterfaces->Get<IUnityGraphicsVulkan>()
at a later frame, it's still 0
The only thing I can think of, is the GUID is incorrect in IUnityGraphicsVulkan
Can you confirm at least that it is as stated in the header file
UNITY_REGISTER_INTERFACE_GUID(0x95355348d4ef4e11ULL, 0x9789313dfcffcc87ULL, IUnityGraphicsVulkan)
as I can't think of a way to confirm it myself, as I don't think you can get a list of registered interfaces.
I know it must be possible to get a working interface to Unity Vulkan from NDK, as I have seen it in other projects. We have developed a plugin for Unity, and since the default renderer for 2019 + is now Vulkan, rather than OpenGL, we can't really insist on people using OpenGL for their projects.
Any hints on how to fix this, would be appreciated.
James
It crashes in function static GLuint CreateShader(GLenum type, const char* sourceText) line 125 (GLuint ret = glCreateShader(type);
with:
Exception thrown at 0x0000000000000000 in Unity.exe: 0xC0000005: Access violation executing location 0x0000000000000000.
PC running Windows 11 (10.0.22000.556).
We are using Unity 2021.3.1f1.
Should it work or isn't it meant to work with that version of OpenGL in Windows platform?
I can't get the plugin to load on Apple Silicon Unity:
arth@mbp: Plugins % lipo -i RenderingPlugin.dylib
Architectures in the fat file: RenderingPlugin.dylib are: x86_64 arm64
I also tried with the .bundle
instead of a dylib
but no help. I had to remove the VALID_ARCHS
user define from the xcode project in order to get arm64
into it, but whatever I do it is not loaded.
Am I missing something here?
The following forum also reported this.
https://discussions.unity.com/t/why-does-intercept-vulkan-vkcreateinstance-crash/921997
Any thought?
Hello.
We are developing a plugin to play a particles created by our particle editor.
We need to support Single Pass Stereo rendering for VR.
How to realize Single Pass Stereo rendering with NativeRenderingPlugin?
Best regards.
It seems like this line in Hook_vkGetInstanceProcAddr
should return vkGetInstanceProcAddr(device, funcName);
instead of NULL
Because will NULL return editor is crashing on start, and no initialization is done.
In Vulkan when creating pipelines, the sample count must be indicated in VkPipelineMultisampleStateCreateInfo. The pipeline can't be later used with a rendertarget with a different sample count.
A native plugin doesn't receive information about the sample count of the current active render pass. I think this could be added to UnityVulkanRecordingState.
Note that the Vulkan example provided in this repository has hardcoded the sample count and doesn't work with cameras using MSAA.
Hi,
unity 2022.2 support webgl multihtread, may i ask if this nativerenderingplugin supported ?tq
I was wondering if the vertex buffer layout is always the same from Unity 2018.4 with DirectX 11 ?
You are using this structure :
struct MeshVertex
{
float pos[3];
float normal[3];
float color[4];
float uv[2];
};
But let say I just want to use pos
and color
attributes from my shaders, could I use directly the structure below to fill my ID3D11Buffer
?
struct MeshVertex
{
float pos[3];
float color[4];
};
Then before calling the native plugin I could just initialize the mesh like that
m_meshFilter = GetComponent<MeshFilter>();
m_meshFilter.mesh = new Mesh();
m_meshFilter.mesh.indexFormat = IndexFormat.UInt32;
m_meshFilter.mesh.vertices = new Vector3[100000];
m_meshFilter.mesh.colors = new Color[100000];
Also, other question : Do I really need to call MarkDynamic()
on the mesh instance if I only set the vertex buffer once during the game ?
Thank you.
The project cannot work in Unity 2018.1 because it useses VertexAttributeDescriptor which does not exist before Unity 2021.3: https://docs.unity3d.com/2021.3/Documentation/ScriptReference/Rendering.VertexAttributeDescriptor.html
It couldn't get vullan api
Since info provided here and at:
https://docs.unity3d.com/Manual/NativePluginInterface.html
is extremely scarce I started a thread at Unity forum:
https://forum.unity.com/threads/native-plugin-documentation-is-lacking.1220007/
Is IUnityInterface actually meant to be used at any professional capacity or was it meant for enthusiast to try and deduce everything from header files and very simple examples?
At one point in the Vulkan example it says:
// can't use GPU transfer here because is not marked as transfer src
No part of the documentations actually mentions what mode of access is supported by all the different resources in all the APIs (dx11, dx12, vulkan etc). Are people just supposed to experiment and see what won't crash? Is it even possible to access any kind of Debug Layers when working on the plugin to receive any meaningful feedback?
I don't expect any replies but hope this post will help other devs to get an idea of what they are getting into.
On the Windows platform, it is desired to call "UnityRegisterRenderingPlugin" in UNITYWEBGL or "UnityRegisterRenderingPlugin V5" in Native RenderingPlugin IOS
In my test, I found that the intercept of vkCmdBeginRenderPass by Hook_vkCmdBeginRenderPass in function [ ProcessDeviceEvent ] didn't work in Editor mode.
I also intercepted vkCreatInstance in function [ ProcessDeviceEvent ] and it didn't work.
However, if I intercept above APIs in function [ Hook_vkGetInstanceProcAddr ], everything works well.
I think I could say that interception in function [ Hook_vkGetInstanceProcAddr ] works definitely .
But when does interception in function [ ProcessDeviceEvent ] work?
Sorry for bothering you guys, but I really would like to understand one thing.
Can somebody explain to me why RegisterPlugin()
is called only for WEBGL
?
NativeRenderingPlugin/UnityProject/Assets/UseRenderingPlugin.cs
Lines 56 to 57 in 2b8ca29
I don't quite understand from the code how OnGraphicsDeviceEvent
(which creates an instance of the RenderAPI) gets called.
In other words, when not using UNITY_WEBGL
how does CreateRenderAPI
gets called?
I know that I am missing something, since the code seems to work just fine.
Thank you very much.
On Windows this plugin does not work with Vulkan. When changing the Player to use Vulkan no rendering happens from the plugin. Have tried rolling back the plugin to before VulkanV2 change, but no improvements. Have tried installing multiple versions of the Unity Editor, but no improvements.
UnityVulkanImage image;
if (!m_UnityVulkan->AccessRenderBufferTexture((UnityRenderBuffer)data->colorBuffer, UnityVulkanWholeImage, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_ACCESS_SHADER_READ_BIT, kUnityVulkanResourceAccess_PipelineBarrier, &image))
{
UnityLog("failed to access rendertexture color buffer");
return;
}
after calling the API, I print the image.layout, it's VK_IMAGE_LAYOUT_UNDEFINED
type instead of VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
. Because I want to sample the texture, so the image layout out must be VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
.
Do I need to transition image layout manully?
Hi, how can I get opengl context or GetProcAddress to get runtime fns?
I've recently encountered an issue with loading Native Rendering Plugins in order to intercept vkCreateInstance. If I enable "Load on Startup" I can intercept this in the Unity Editor, but built applications load the plugin after Vulkan Instance is created. I'm running Linux and haven't tested this on Windows.
Is this intended functionality? If not, how do I force builds to load a Native Rendering Plugin before Vulkan Instance is created?
Hi there. I am a newbie in unity and want to render some graphics using unity. can you please point the way to a guide to setup this plugin with my VS2015 C++ project?
I run make in the GNU folder and got errors--Undefined symbols for architecture x86_64. Is there any error in the makefile?
Hello,
I am trying to run my C++ 3D game in Unity using native plugin. The game is 32-bit and uses OpenGL. I commented out directX defines in PlatformBase.h. And the plugin doesn't work (no triangle drawn). My OS is Windows 7, Unity version - 5.6.7f1.
Hi, I'm trying to run the plugin sample under WebGL. It works fine in Editor, but the mesh is completely flat in web.
Looking at the code, it seems that modifying the mesh was intentionally disabled for WebGL.
NativeRenderingPlugin/PluginSource/source/RenderAPI_OpenGLCoreES.cpp
Lines 280 to 294 in cebe85a
When removing the check on SUPPORT_OPENGL_ES
, I get the following error when building from Unity :
'GL_WRITE_ONLY' is undefined
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.