-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is there an example of generating a Unity Texture? #53
Comments
Sorry for this late response, If you are asking about pure OpenGL textures, I don't have enough experience with them. But if you just need some array with specific format, then I can help you. Even hello world example can be adjusted to generate an array with some format. I will add some here. |
For example, below code should generate 4096 element arrays with zero on all elements by initializing them as float4 (4-element float vectors) inside kernel (using 1024 threads spanning all GPUs, each thread initializing 1 float4 for a(f), 1 float4 for b(g)).
|
Also here is how I tried producing vertices (as height-map of a sphere) https://github.com/tugrul512bit/unityTestMeshDeformation/blob/master/gpgpu_test/Assets/Kamera.cs In there, to use "structs" of Unity, such as
you can use
it wraps around whole structs and treats all items in them as floats or whatever items in kernel as you like. Using byte type is just for treating as a data transmission buffer on host side. In kernel, you can use their elements by casting to different type on proper alignment points. You shouldn't dereference a non-multiple of 4 address as a float nor int. |
thanks, that's awesome! My goal is to evolve proceducerally generated
fragment shaders - so I'd like to bind the output to a texture and just
blit it to a flat quad. Unity won't allow me to compile a fragment shaders
on the fly, but this seems like it could work!
I'll get back to you if I make it work!
cheers,
m
Den tors 21 mars 2019 kl 20:16 skrev Hüseyin Tuğrul BÜYÜKIŞIK <
notifications@github.com>:
… For example, below code should generate 4096 element arrays with zero on
all elements by initializing them as float4 (4-element float vectors)
inside kernel.
ClPlatforms platforms = ClPlatforms.all();
var selectedDevices = platforms.devicesWithMostComputeUnits().gpus(true);
selectedDevices.logInfo();
ClNumberCruncher gpu = new ClNumberCruncher(selectedDevices, @"
__kernel void algorithmTest(__global float4 * a, __global float4 * b)
{
int i=get_global_id(0);
a[i]=(float4)(0.0f,0.0f,0.0f,0.0f);
b[i]=(float4)(0.0f,0.0f,0.0f,0.0f);
}
");
ClArray<float> f = new ClArray<float>(4096);
f.numberOfElementsPerWorkItem = 4;
f.readOnly=true;
f.zeroCopy=true;
f.write = false;
f.readOnly = true;
ClArray<float> g = new ClArray<float>(4096);
g.numberOfElementsPerWorkItem = 4;
g.zeroCopy=true;
g.read = false;
gpu.performanceFeed = true;
f.nextParam(g).compute(gpu, 1, "algorithmTest", 4096/4, 64);
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#53 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AMfe-cQ1BsMXEAFsndVsUXNW2MArn5iNks5vY9pvgaJpZM4b3oLF>
.
--
Mattias Fagerlund
Carretera AB
|
I'd like to use Cekirdekler to generate textures from kernels that I generate at runtime, is there any minimal demo showing how to do this?
cheers,
m
The text was updated successfully, but these errors were encountered: