All Projects → keijiro → Textureupdateexample

keijiro / Textureupdateexample

An example showing how to update textures from a native plugin in Unity.

Programming Languages

c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to Textureupdateexample

Klaksyphon
Syphon plugin for Unity
Stars: ✭ 149 (+12.03%)
Mutual labels:  unity, unity3d, graphics, plugin
Meshstreaminggrasshopper
Plugin for Grasshopper to stream mesh geometry through web socket.
Stars: ✭ 52 (-60.9%)
Mutual labels:  unity, unity3d, plugin
Pcxeffects3
Unity VFX with point cloud
Stars: ✭ 121 (-9.02%)
Mutual labels:  unity, unity3d, graphics
3d Game Shaders For Beginners
🎮 A step-by-step guide to implementing SSAO, depth of field, lighting, normal mapping, and more for your 3D game.
Stars: ✭ 11,698 (+8695.49%)
Mutual labels:  unity, unity3d, graphics
Unitypluginwithwsl
Unity native plugin with WSL (Windows Subsystem for Linux)
Stars: ✭ 39 (-70.68%)
Mutual labels:  unity, unity3d, plugin
Grubo
Audio visual experience with Roland Groovebox MC-101 and the Unity game engine
Stars: ✭ 41 (-69.17%)
Mutual labels:  unity, unity3d, graphics
Drawmeshwithmotionvectors
An example showing how to generate per-object motion vectors when using DrawMesh.
Stars: ✭ 65 (-51.13%)
Mutual labels:  unity, unity3d, graphics
Testbedhdrp
Testbed project for Unity HDRP (High Definition Render Pipeline)
Stars: ✭ 859 (+545.86%)
Mutual labels:  unity, unity3d, graphics
Temporalreprojectionexample
Temporal reprojection example for Unity
Stars: ✭ 82 (-38.35%)
Mutual labels:  unity, unity3d, graphics
Lwrpshaders
A collection of high customizable unlit shaders for Lightweight Render Pipeline
Stars: ✭ 125 (-6.02%)
Mutual labels:  unity, unity3d, graphics
Gpu Planetary Rendering
GPU atmosphertic scattering and planet generation in Unity 3D
Stars: ✭ 92 (-30.83%)
Mutual labels:  unity, unity3d, graphics
Packedrgbmshader
32-bit packed color format with RGBM encoding for shader use
Stars: ✭ 39 (-70.68%)
Mutual labels:  unity, unity3d, graphics
Minimumaudioplugin
Minimum implementation of a native audio plugin for Unity
Stars: ✭ 33 (-75.19%)
Mutual labels:  unity, unity3d, plugin
Kino
A collection of custom post processing effects for Unity
Stars: ✭ 1,054 (+692.48%)
Mutual labels:  unity, unity3d, graphics
Shadergraphexamples
Simple examples of Unity shader graphs.
Stars: ✭ 869 (+553.38%)
Mutual labels:  unity, unity3d, graphics
Nnao
Neural Network Ambien Occlusion based on http://theorangeduck.com/page/neural-network-ambient-occlusion
Stars: ✭ 57 (-57.14%)
Mutual labels:  unity, unity3d, graphics
Klak
Creative coding library for Unity
Stars: ✭ 1,347 (+912.78%)
Mutual labels:  unity, unity3d, plugin
Radialprogressbar
Customizable radial progress bar shader for Unity3D. Allows you to set arc range, minimum and maximum colors, textures, radius, and a few more things. Create HP Bars, Speedometers, rank progress, etc!
Stars: ✭ 714 (+436.84%)
Mutual labels:  unity, unity3d, graphics
Pcx
Point cloud importer & renderer for Unity
Stars: ✭ 806 (+506.02%)
Mutual labels:  unity, unity3d, graphics
Vertexanimationjob
Vertex animation with C# Job System and new Mesh API
Stars: ✭ 82 (-38.35%)
Mutual labels:  unity, unity3d, graphics

TextureUpdateExample

gif

Old-school plasma effect generated by C++ code

This is an example that shows how to use the CustomTextureUpdate callback that allows native plugins to update contents of textures in a thread safe and platform agnostic way.

How to implement the CustomTextureUpdate callback

The callback function should be implemented with the following signature:

void TextureUpdateCallback(int eventID, void* data)
{
  auto event = (UnityRenderingExtEventType)eventID;
  auto params = (UnityRenderingExtTextureUpdateParamsV2*)data;
}

The type of the event will be given to eventID, and the attributes of the target texture will be given with UnityRenderingExtTextureUpdateParamsV2 struct carried by the data pointer.

The possible values of eventID are defined in UnityRenderingExtEventType; Only kUnityRenderingExtEventUpdateTextureBeginV2 and kUnityRenderingExtEventUpdateTextureEndV2 are relevant to the texture update callback.

kUnityRenderingExtEventUpdateTextureBeginV2 event

This event is invoked right before updating the texture. You can give raw image data via the texData pointer in the parameter struct.

if (event == kUnityRenderingExtEventUpdateTextureBeginV2)
{
  uint8_t* img = new uint32_t[params->width * params->height * 4];

  // Set image data here.

  params->texData = img;
}

You can also give nullptr to texData when you don't like to update the texture in this frame.

kUnityRenderingExtEventUpdateTextureEndV2 event

This event is invoked right after updating the texture. You can safely release resources used to update the texture.

if (event == kUnityRenderingExtEventUpdateTextureEndV2)
{
  delete[] reinterpret_cast<uint32_t*>(params->texData);
}

Interface function

You have to implement an interface function that is used to retrieve the pointer of the callback function.

extern "C"
UnityRenderingEventAndData UNITY_INTERFACE_EXPORT GetTextureUpdateCallback()
{
    return TextureUpdateCallback;
}

For further details of the plugin implementation, please see the example source code contained in this repository.

How to update texture from C# script

In order to request texture update from a C# script, you can use IssuePluginCustomTextureUpdateV2 with a CommandBuffer. The pointer to the callback function and a reference to a texture object should be given to the command. You can also give a single uint value to the command that can be used as user data to the callback.

[DllImport("DllName")] static extern IntPtr GetTextureUpdateCallback();

var callback = GetTextureUpdateCallback();
m_CommandBuffer.IssuePluginCustomTextureUpdateV2(callback, texture, userData);
Graphics.ExecuteCommandBuffer(m_CommandBuffer);

Platform availability

At the moment of Unity 2018.3, the CustomTextureUpdate callback is only available in Direct3D 11, Metal, OpenGL (Core/ES), and Nintendo Switch. It's also available on Vulkan from Unity 2019.1. For other platforms, you have to implement the plugin without using this interface.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].