keijiro / Pcx

Point cloud importer & renderer for Unity
The Unlicense
1.35k stars 196 forks source link

Metal support #2

Open keijiro opened 7 years ago

keijiro commented 7 years ago

Metal doesn't have geometry shader. It has to be emulated by using compute + procedural indirect draw.

millerhooks commented 7 years ago

Thanks so much for the quick response! I'm really new at this fancy shader stuff, but I found this discussion over here with this snippet.

I reading the Disk shader it looks to me that I'd do the combination in the geometry phase in Disk.cginc. I'm going to keep playing with it, but I figured I'd mention my thinking here and see if you have any resources to point me at. The topic seems to be sparsely discussed on the internet or I just have no idea what I'm trying to google.

https://forums.developer.apple.com/thread/4818

render_vertex(const device VertexInput* v_in [[ buffer(0) ]],  
              constant float4x4& mvp_matrix [[ buffer(1) ]],  
              constant LightDesc& light_desc [[ buffer(2) ]],  
              device VertexOutput* xform_output [[ buffer(3) ]],  
              uint v_id [[ vertex_id ]] )  
{  
    VertexOutput v_out;  
    v_out.position = v_in[v_id].position * mvp_matrix;  
    v_out.color = do_lighting(v_in[v_id].position,  
                    v_in[v_id].normal,  
                    light_desc);  

    v_out.texcoord = v_in[v_id].texcoord;  

    // output position to a buffer  
    xform_output[v_id] = v_out.position;  
}  
keijiro commented 7 years ago

That thread in the Apple forum is not relevant to Unity. Please ignore it. That's almost meaningless for this case.

I've implemented a non-geometry shader variant of the disk shader in compute-2 branch. https://github.com/keijiro/Pcx/commits/compute-2

I rejected this variant because it's not performant compared to the original (geometry shader).

I've verified that it works on Metal, so, I should rethink about it. It's not performant but useful for compatibility.

millerhooks commented 7 years ago

Oh perfect. That’ll get me where I’m going with this demo. Thank you!