Hi, i', trying to make super simple GPU RayTracer using Compute Shader. It works well, however there is something strange to me. I am not familiar with shaders to much. So i have a loop body with triangles buffer and a ray which tests every triangle. This is part of the shader, the problem is explained inside:
[loop][allow_uav_condition]
for (uint i = 0; i < tris.Length; i++)
{
// Getting triangle vertices and doing some math
float3 pt0 = tris[i].v0;
float3 pt1 = tris[i].v1;
float3 pt2 = tris[i].v2;
float3 edge0 = rayO - pt0;
float3 edge1 = rayO - pt1;
float3 edge2 = rayO - pt2;
float3 cross1 = cross(edge0, edge1);
float3 cross2 = cross(edge1, edge2);
float3 cross3 = cross(edge2, edge0);
float dot1 = dot(rayD, cross1);
float dot2 = dot(rayD, cross2);
float dot3 = dot(rayD, cross3);
// Some more math
float3 n = tris[i].n;
float3 w0 = rayO - pt0;
float _a = -dot(n, w0);
float b = dot(n, rayD);
float r = _a / b;
float3 I = rayO + rayD * r;
hDis = distance(rayO, I);
// Calculating if there is intersection or not
bIntersect = dot1 < 0 && dot2 < 0 && dot3 < 0 && _a < 0 && hDis < fRadius && pixel.valid;
if(bIntersect == 1)
{
// If there is intersection we would like to break;
// However breaking or not performance is slow if using "bIntersect"
// in the calculations next after the loop body
break;
}
}
// THE PROBLEM: - Setting pixel color based on "bIntersect" value -> 1.0 or 0.0. When multiplying with "bIntersect", pixelColor either changes or not its value. However including "bIntersection" in the line below, makes the calculation to happen for 8 secconds. And when replaced with some float value, it is calculated for 0.4 secconds which is about 16 times faster. So no matter what variable which was used within the Loop body i use in the calculation below, the performance is terrible. Is that normal and how i suppose to set some variable in the loop body and use it outside the loop. I tested a lot of options like making calculations inside the loop body with no success.
pixel.pixelColor -= _step * bIntersect; // Using "bIntersect" here breaks the performance
rendTex[id.xy] = float4(pixel.pixelColor, pixel.pixelColor, pixel.pixelColor, pixel.valid );
pixels[pixelID].pixelColor = pixel.pixelColor;
↧
Compute Shaders and For Loops !?
↧
How do you see the results of compute shaders in the debugger?
I'm trying to write some particularly complex functionality on the gpu that would be really good if I could at least see the raw data but I have no idea how.
Initially i thought my code was broken which led me to post this on stack exchange ...
http://gamedev.stackexchange.com/questions/116323/how-do-i-build-a-3d-array-result-set-from-a-compute-shader-in-unity
... I now think its possible that unity has some sort of wierd bug that prevents me looking at the result of populating a 3d array from a compute shader result.
The code in this example isn't complex so there's no reason why it shouldn't behave just like debugging any other cpu code as all I want to do is put some values in to the buffer on the gpu then download and view them by putting a breakpoint in after my buffer.GetData(cpuArray) call.
Does anyone know if there's a work around or something for this?
It's worth noting that in the edit where I generate a 3,3,3 array of voxels where all but the center one are "empty" (-1 values) and the center is full (1 value) the array in the debugger tells me all elements are 0 values (apparently not populated) but the cpu meshing code is then able to generate the correct cube mesh from it after (not included in the question).
So what must I do to inspect arrays populated from the GPU?
I have tried the following with 0 success ...
- Normal VS debugging (breapoint look
at value / add to watch window to see
value)
- Load solution in to MonoDev and
repeat the VS procedure
- Debug.Log(values)
↧
↧
Compute Shader Pass RWStructuredBuffer by Reference
I was curious if there is a way to pass a structured buffer around by reference. With both structured buffers and arrays I don't want them to be copied entirely when passed to a function, because this would be ridiculously inefficient. Is there a way to do this properly in HLSL for compute shaders?
I saw the in, out, and inout keywords, but the documentation makes it seem like this just performs a copy anyway. Is a copy for structured buffers and arrays just a pointer copy? Or is it by values?
↧
advice for computing and rendering many, many line segments ?
I'm thinking about a unity port of my iOS app "[Prism HD][1]".
The fundamental rendering task each frame is this:
1. Compute a whole bunch of line segments to simulate optical effects.
" many" = maybe 10,000 or so. each segment has x & y data plus a u & v texture coordinate.
for what it's worth, the simulation is 2D, not 3D.
2. Draw them.
so i have two questions:
1. if C# turns out not to be fast enough to crunch 10,000 rays at 60Hz, would i be better off doing the math in C (that's how i do it in iOS), or should i learn how to use compute shaders ? I'm only interested in targeting iOS, Android, and maybe desktop, so i don't need it to work in WebGL. There's not a lot of computer shader examples w/ unity.
2. how do I draw these things ? I'm super lazy. CommandBuffers seem pretty mesh-oriented, and this isn't a mesh. I'd prefer not to convert each line segment to a quad, because that quadruples the number of vertices which need to go over the bus. Again, is a shader the way ? I've never stepped outside of the fixed-function pipeline.
[1]: https://itunes.apple.com/us/app/prism-hd/id439622311?mt=8
↧
fragment shader different color for every vertex?
can i make different colors fore every instance of this shader? do i have to send instance to o.output or something? how can i do it?
StructuredBuffer buf_Points;
StructuredBuffer buf_Positions;
struct ps_input {
float4 pos : SV_POSITION;
};
ps_input vert (uint id : SV_VertexID, uint inst : SV_InstanceID)
{
ps_input o;
float3 worldPos = buf_Points[id] + buf_Positions[inst];
o.pos = mul (UNITY_MATRIX_VP, float4(worldPos,1.0f));
return o;
}
float4 frag (ps_input i) : COLOR
{
return float4(1,0.5f,0.0f,1);
}
ENDCG
↧
↧
Computer Shader parsing
I am trying to set a StructuredBuffer from a C# file.
I'm not sure how I would do this as C# as far as i'm aware does not support the float3 type, so I was thinking that maybe it would be a Vector3 since it has 3 floats in it.
I know how to set a buffer, but i'm not sure which variable I would use to parse it.
If someone could tell me which type I would use in the array I am using to set the buffer I would greatly appreciate it.
↧
How to get the Cascaded Shadows' split spheres positions?
Hello!
In order to compute the directional cascaded shadows in a shader (as in Internal-PrePassCollectShadows.shader or UnityCG.cginc) we need several informations easily findable through the QualitySettings class.
Except that I cannot figue out how to get the split sphere positions or how to compute them.
I need them to create an VFX in compute shader and declaring "float4 unity_ShadowSplitSpheres[4];" does not work.
Thank you very much in advance!
Cheerz!
↧
DrawProcedural draws nothing although buffers are assigned properly
Hi, it's the first time I acually need help from you guys.
I have a compute shader that calculates the mesh for a tube along a spline. The resulting mesh looks like this:
![alt text][1]
This was drawn with Debug.Drawline and the data retrieved from the ComputeBuffer.
The Computebuffer stores 3 structs for each triangle to render. Each struct contains a position and a normal:
struct1{posX, poxY, posZ,pad0, normX....}, struct2{...}, struct3{...},...
|-------------------------------One Triangle-----------------------------------------|--next Triangle----...
When I try to draw the mesh on the graphics card nothing appears on the screen, even though I should see some white stuff floating around, right?
This is the simple shader I use to draw the buffer:
Shader "Custom/CurveRenderShader" {
SubShader{
Tags{ "RenderType" = "Transparent" }
LOD 200
Pass{
Blend SrcAlpha OneMinusSrcAlpha
ZWrite On ZTest LEqual
Cull Off
CGPROGRAM
#pragma target 5.0
#pragma vertex vert
#pragma fragment frag
struct VertexOutput {
float4 position : SV_POSITION;
float3 normal: NORMAL;
};
struct computeOutLayout {
float posX;
float posY;
float posZ;
float pad0;
float normX;
float normY;
float normZ;
float pad1;
};
StructuredBuffer computeOutBuffer;
VertexOutput vert(uint id : SV_VertexID) {
VertexOutput OUT;
OUT.position = mul(UNITY_MATRIX_MVP, float4(computeOutBuffer[id].posX, computeOutBuffer[id].posY, computeOutBuffer[id].posZ, 1.0));
OUT.normal = float3(computeOutBuffer[id].normX, computeOutBuffer[id].normY, computeOutBuffer[id].normZ);
return OUT;
}
//____ Fragment Shader ____//
fixed4 frag(VertexOutput IN) : SV_TARGET{
return fixed4(1.0,1.0,1.0,1.0); // <--- I guess I should see my mesh rendered purely white
}
ENDCG
}
}
}
Can some genius around here shine some light on this? :D
The mesh is not yet closed and the Mesh drawn with Debug.DrawLine jitters quite a lot in the viewport but I think that should not matter when it comes to drawing the mesh with a shader.
/---EDIT:
These are the lines where I dispatch the compute shader and try to and draw the thing:
computeShader.Dispatch(kernels[(int)settings.mode], amountOfAdjacencies, 1, 1);
renderMaterial.SetPass(0);
renderMaterial.SetBuffer("computeOutBuffer", computeOutBuffer);
Graphics.DrawProcedural(MeshTopology.Points, 6 * settings.segments * settings.sectors);
The Settings class just stores some properties of the Mesh. I already tried drawing with MeshTopology.Triangles but it didn't work either.
[1]: /storage/temp/69693-debugmesh.png
↧
Unity Shader Stream Output Stage
Do Unity 5 shaders have access to the stream output stage in the DX11 pipeline?
Reference: https://msdn.microsoft.com/en-us/library/windows/desktop/bb205121%28v=vs.85%29.aspx
I want to compute new vert data in the shader and then output this information to a script for non rendering purposes.
I am currently using a GPGPU shader to achieve this, however the load on the pipeline during return is not desirable. This can't really change as it is proportionate to the number of verts in the mesh, so I figure that if I could use the stream output stage in the DX11 render pipeline which Unity uses then this could mitigate such load as the vert data will only need to be passed to the GPU once during the rendering stage, instead of twice.
Is this methodology correct and can I access the stream output stage?
↧
↧
Posible Bug with Compute Shaders and DirectX11?
Hi everyone.
I am experiencing some kind of bug. I am using the Capture Panorama Asset on my project. It is quite simple, so no big deal is involved. I have taken several pictures with said asset on the last couple of days but now the following warning appears, stopping me from capturing image or video:
"CapturePanorama requires compute shaders. Your system does not support them. On PC, compute shaders require DirectX 11, Windows Vista or later, and a GPU capable of Shader Model 5.0."
I am running on DX11 so I don't have the tiniest of ideas of what is happening.
Thank you
↧
Setting color for compute shader structure trough c#
I have shader that has structure
struct Particle
{
float3 position;
float3 velocity;
float3 color;
};
And is used here
o.color = particleBuffer[instance_id].color;
Here's my c# structure
public struct Particle
{
public Vector3 position;
public Vector3 velocity;
public Vector3 color;
}
I set color using Vector3 but it doesn't work. Everything else works as expected.
How can I set a color while creating struct for it to be used in my shader?
↧
How can you detect judder in VR?
I've been working in OpenVR (the Steam API), and every once and a while I will get some judder. Is there a way to detect exactly what frames juddered/when juddering will occur? I'd like to minimize this, and I can change processing of my application dynamically based on how much judder might occur (to make things run faster to prevent judder), but I need some way of "profiling" the judder.
I'm in Unity, but I'm doing all my processing on the graphics card (using a Compute Shader), so the profiler says the framerate is very fast, yet sometimes judder occurs. I thought maybe taking the maximum frame rate over, say, 5000 frames might work, but sometimes judder occurs when the maximum hasn't changed. So is there a way I can actually measure it?
↧
Problem with ComputeShader and RHalf RenderTexture
There is a simply compute shader:
#pragma kernel CSMain
RWTexture2D _Texture;
[numthreads(32, 32, 1)]
void CSMain (uint2 id : SV_DispatchThreadID)
{
_Texture[id] += 0.1;
}
Code which creates a RHalf RW texture:
texture = new RenderTexture( 32, 32, 0, RenderTextureFormat.RHalf, RenderTextureReadWrite.Linear );
texture.enableRandomWrite = true;
texture.filterMode = FilterMode.Point;
texture.Create();
And shader using:
shader.SetTexture( 0, "_Texture", texture );
shader.Dispatch( 0, texture.width/32, texture.height/32, 1 );
But I'm getting a strange behavior.
![alt text][1]
![alt text][2]
Why is it?
RFloat works good.
Also just setting constant value works good.
But reading and writing RHalf doesn't work.
[1]: /storage/temp/73043-1.png
[2]: /storage/temp/73044-2.png
↧
↧
Pass Matrix4x4 to ComputeShader?
How can I pass a Matrix4x4 parameter to a ComputeShader?
Materials have the SetMatrix method but ComputeShaders lack this.
I thought maybe SetFloats to pass the Matrix4x4 as a float array like I would do with OpenGL but there doesn't seem to be any straightforward way to get an array from a Matrix4x4.
Using version 5.4b.
↧
getting texture from shader into c# script. Also: best way to get values from GPU to CPU?
Dear unity community
as I am pretty new to unity I would be happy for some guidance into the right direction.
I use a shader to modify an image sequence in runtime. This shader is applied as a texture to a material. Now I need to access the color values of this texture in a c# script.
my first practical question would be: How do I get the texture from my shader into my c# script? From what I know I could use .GetPixel from there.
Since I am aware of the fact that getting these values from the gpu to the cpu is always a bottleneck, I was wondering whether there is a best practice to do this?
I was thinking about passing the texture to a compute shader and fill a RWStructuredBuffer there and somehow getting the data back from there? Would that be faster?
↧
Do uninitialized RenderTexture areas lead to wrong texturing (tiled RenderTexture problem)?
I am working on a procedural planet engine and face a problem when creating a tiled RenderTexture which can hold e.g. a NormalMap for a larger number of planet planes.
Now I am trying to implement a hint by zeroyao from Unity3D in this very interesting thread about GPU instancing. http://forum.unity3d.com/threads/gpu-instancing.376635/page-4#post-2651648
To sum the process of how I create a planet plane: To render planet planes, I pass over (per planet plane) a RenderTexture and a ComputeBuffer to a ComputeShader which fills the ComputeBuffer e.g. with position data and the RenderTexture with NormalMap Data. Everything is then passed to Vertex/Surface shader that displaces the meshes vertices with the ones from the ComputeBuffer, and applies the NormalMap and SurfaceMap RenderTexture.
What I am now trying is to create one large tiled RenderTexture (so, a TextureAtlas) where I draw into each tile e.g. a NormalMap of a plane. So in case if my normalmaps are 64x64 each, I create a large 1024x1024 RenderTexture I can use across many planes. The ComputeShader and the Vertex/Surface shaders are receiving the necessary Offset information to write (in the ComputeShader) and read (in the SurfaceShader) from the right location of the RenderTexture.
When done something similar with ComputeBuffers, so that lots (thousands) of plane scan share the same large RenderTexture and ComputeBuffer, Batching should start to do its magic, resulting in a lot less draw calls.
I am facing one problem now while implementing this for RenderTextures. I implemented a SharedTextureManager that on demand creates a new mega-RenderTexture and manages which of these slots are used. If a new plane requires a RenderTexture to create e.g. a NormalMap, it requests a slot (= a tile of that mega RenderTexture) from the SharedTextureManager. it receives the reference to the texture and some offset information. If all slots of a texture are used, the SharedTextureManager creates a new one and adds it to the list. Then the usual process keeps going, the RenderTexture reference including the offset information is being passed to the ComputeShader which fills the Pixels with the Normal-Information.
C#
this.sharedTextureManager = new SharedTextureManager(nPixelsPerEdge, 1, 2, RenderTextureFormat.ARGBHalf);
quadtreeTerrain.sharedNormalMapTextureSlot = this.sharedTextureManager.GetSharedTextureSlot();
quadtreeTerrain.patchGeneratedNormalMapTexture = quadtreeTerrain.sharedNormalMapTextureSlot.Texture();
....
ComputeShader
RWTexture2D patchGeneratedNormalMapTexture;
#pragma kernel CSMain2
[numthreads(1,1,1)]
void CSMain2 (uint2 id : SV_DispatchThreadID)
{
// Get the constants
GenerationConstantsStruct constants = generationConstantsBuffer[0];
[... calculate normals...]
// Prepare Texture ID
uint2 textureID = uint2(id.y+constants.sharedNormalMapTextureSlotPixelOffset.x,id.x+constants.sharedNormalMapTextureSlotPixelOffset.y);
// Create the ObjectSpace NormalMap
float w = constants.nPixelsPerEdge;
float h = constants.nPixelsPerEdge;
// Store the normal vector (x, y, z) in a RGB texture.
float3 normalRGB = normal.xyz /2;
patchGeneratedNormalMapTexture[textureID] = float4(normalRGB,1)
}
After the dispatch to the ComputerShader the RenderTexture and Offset information is pased to to the Vertex/Surface Shader. A _NormalMapOffset float4 is passed, where X and Y define the downscale of the tile compared to the overal texture, Z and W define the UV offset.
C#
quadtreeTerrain.material.SetTexture("_NormalMap", quadtreeTerrain.patchGeneratedNormalMapTexture);
quadtreeTerrain.material.SetVector("_NormalMapOffset", quadtreeTerrain.sharedNormalMapTextureSlot.Offset());
Shader
uniform float4 _NormalMapOffset;
void vert(inout appdata_full_compute v, out Input o)
{
UNITY_INITIALIZE_OUTPUT(Input, o);
#ifdef SHADER_API_D3D11
// Read Data from buffer
float4 position = patchGeneratedFinalDataBuffer[v.id].position;
float3 patchCenter = patchGeneratedFinalDataBuffer[v.id].patchCenter;
// Perform changes to the data
// Translate the patch to its 'planet-space' center:
position.xyz += patchCenter;
// Apply data
v.vertex = float4(position);
o.uv_NormalMap = v.texcoord.xy;
o.worldPos = mul(unity_ObjectToWorld, v.vertex);
o.objPos = v.vertex;
#endif
}
void surf(Input IN, inout SurfaceOutputStandard o)
{
// Apply normalmap
fixed3 normal = tex2D(_NormalMap, IN.uv_NormalMap * _NormalMapOffset.xy + _NormalMapOffset.zw);
o.Normal = normal;
}
=> Everything works fine until there is a "free" slot in the RenderTexture, "free" meaning not all areas of the RenderTexture were written to previously in the ComputeShader.
If the RenderTexture is 1x1 slots, everything is fine.
![alt text][1]
If the RenderTexture is 1x2 slots, everything is still fine.For each RenderTexture both slots were used.
If the RenderTexture is 1x4 slots, the texturing gets wrong, the area is textured grey. In the debugger you can see that only half of the RenderTexture was used (which is correct).
![alt text][2]
Although by using offsets to read from the RenderTexture, my impression is that this (uninitialized RenderTexture areas although not read from in the shader) seem to lead to this behavior.
Is that possible or the expected behavior when using RenderTextures? I was hoping that this wouldnt become an issue, as I guessed using the Offset information and only reading areas of the RenderTexture that were written too previously should work.
Does anyone know please, especially how to solve this? That would really help me a lot as I get to struggle a little (while I hope that getting this to work could be my breakthrough in the number of drawcall issues).
[1]: /storage/temp/76222-01-sharedtextures-03-1x1.jpg
[2]: /storage/temp/76224-01-sharedtextures-03-1x4.jpg
↧
ComputeShader buffer, change count at runtime
Is it possible to change the buffer count, once it's been initialized? For example every update call (sometimes the point cloud is bigger or smaller than the init value)
buffer = new ComputeBuffer ( count, sizeof(float) * 7, ComputeBufferType.Default);
↧
↧
ComputeBuffer low-level access in Direct3D 11 in Unity 5.5.0B3
Hi all,
I just discovered **ComputeBuffer.GetNativeBufferPtr** in Unity 5.5.0B3. Very very awesome!!
I'm trying to use the ID3D11Buffer with CUDA interop but it keeps crashing.
When looking at the buffer description, Direct3D reveals this no matter what size or type I specify:
- ByteWidth: 256
- Usage: 256
- BindFlags: 1
- CPUAccessFlags: 1
- MiscFlags: 2
- StructureByteStride: 1
I'm wondering whether this feature is ready to use yet or I'm doing something wrong.
Thank you so much!
David
↧
Geometry Shader is drawing triangles in wrong vertex positions
Hi,
After learning about shaders in past couple of weeks, I wanted to try something on my own.
So I tried to draw a face for a cube using Compute Shader and Geometry Shader.
Compute shader is generating 16 points ( 2x2 x 2x2) which are equally spaced by 1 unit and bottom left vertex is at origin. Below is the result without Geometry shader.
![alt text][1]
When I use Geometry Shader for generating triangles on each point. It is changing the vertices in x and y axis a little bit as you can see below. There is a gap between rows of triangles.
![alt text][2]
Here is my compute and geometry shader code.
Shader "Custom/CubeShader"
{
SubShader
{
Pass
{
CGPROGRAM
#pragma target 5.0
#pragma vertex vert
#pragma geometry GS_Main
#pragma fragment frag
#include "UnityCG.cginc"
StructuredBuffer square_points;
struct ps_input {
float4 pos : POSITION;
};
struct gs_input {
float4 pos : POSITION;
};
ps_input vert(uint id : SV_VertexID)
{
ps_input o;
float3 worldPos = square_points[id];
o.pos = mul(UNITY_MATRIX_MVP, float4(worldPos,1.0f));
return o;
}
[maxvertexcount(3)]
void GS_Main(point gs_input p[1], inout TriangleStream triStream)
{
float4 v[3];
v[0] = float4(p[0].pos.x, p[0].pos.y, p[0].pos.z, 1);
v[1] = float4(p[0].pos.x + 1.0f, p[0].pos.y + 0.0f, p[0].pos.z + 0.0f, 1);
v[2] = float4(p[0].pos.x + 1.0f, p[0].pos.y + 1.0f, p[0].pos.z + 0.0f, 1);
float4x4 vp = mul(UNITY_MATRIX_VP, _World2Object);
gs_input pIn;
pIn.pos = mul(vp, v[2]);
triStream.Append(pIn);
pIn.pos = mul(vp, v[1]);
triStream.Append(pIn);
pIn.pos = mul(vp, v[0]);
triStream.Append(pIn);
}
float4 frag(ps_input i) : COLOR
{
return float4(1,0,0,1);
}
ENDCG
}
}
Fallback Off
}
#pragma kernel CSMain
#define thread_group_size_x 2
#define thread_group_size_y 2
#define thread_group_size_z 1
#define group_size_x 2
#define group_size_y 2
#define group_size_z 1
struct PositionStruct
{
float3 pos;
};
RWStructuredBuffer output;
// I know this function is unnecessary. But only for now :) I would like to add more things here.
float3 GetPosition(float3 p, int idx)
{
return p;
}
[numthreads(thread_group_size_x, thread_group_size_y, thread_group_size_z)]
void CSMain(uint3 id : SV_DispatchThreadID)
{
int idx = id.x + (id.y * thread_group_size_x * group_size_x) +
(id.z * thread_group_size_x * group_size_y * group_size_z);
float3 pos = float3(id.x, id.y, id.z);
pos = GetPosition(pos, idx);
output[idx].pos = pos;
}
Please help me debug it. Thanks in advance :)
[1]: /storage/temp/78258-pnts-1.png
[2]: /storage/temp/78259-trngs-1.png
↧
UVs are not mapped properly in my unity surface shader
Hi,
I am trying to use compute shaders with surface shaders with dx11 tesselation shaders ( Using unity's distance base tesselation example from unity guide ). I copied the generated code from surface shaders and used it as a seperate shader.
I am generating vertices for a plane in compute shader. The triangles are being generated properly but I seem to have to a problem with mapping the UVs. With using any texture all I get the is black plane.
Here is my surface shader's vertex shader:
InternalTessInterp_appdata tessvert_surf(appdata v, uint id:SV_VertexID) {
InternalTessInterp_appdata o;
o.vertex = float4(vertexBuffer[id],1);
o.tangent = v.tangent;
o.normal = v.normal;
o.texcoord = float2(o.vertex.x/16,o.vertex.y/16);
return o;
}
Here is my Compute shader (the value of thread group size x, group size y and z is 4)
void GenerateMesh(uint3 id : SV_DispatchThreadID)
{
int idx = id.x + (id.y * thread_group_size_x * group_size_x) +
(id.z * thread_group_size_x * group_size_y * group_size_z);
float3 pos = float3(id.x, id.y, id.z);
output[6 * idx + 0].pos = pos + float3(1, 1, 0);
output[6 * idx + 1].pos = pos + float3(1, 0, 0);
output[6 * idx + 2].pos = pos;
output[6 * idx + 3].pos = pos;
output[6 * idx + 4].pos = pos + float3(0, 1, 0);
output[6 * idx + 5].pos = pos + float3(1, 1, 0);
}
Here is my CSharp code
void DrawMesh()
{
planetComputeShader.Dispatch(kernel, 4, 4, 1);
planetTesselationMaterial.SetPass(0);
planetTesselationMaterial.SetBuffer("vertexBuffer",vertexBuffer);
Graphics.DrawProcedural(MeshTopology.Triangles,6 * 289);
}
My final aim to create a procedural planet generated on GPU. I know I am far way from doing this but I am taking small steps :-) Please help me debug this. Thanks in advance.
↧