Question

I'm new to direct3d , graphics, HLSL , c++ , and I'm trying to write a program to render different geometric multidimensional shapes (for example a hypercube), the program is supposed to receive vertices from the user after the user has defined the number of dimensions , draw , rotate and translate the shape .

  • The first problem is how to define a dynamic vertex structure (is it okay to use pointers).

  • Second: Where to project the shape from x-dimensional to 3-dimensional space ,should I do that in the code (CPU), or is it possible to pass the object vertices and projection matrices to the shader(HLSL) and if so how (especially that the matrices are of varying size defined at runtime).

  • Same problem as the above for the view matrix (let's say that the object is 4-d I want the program to zoom in/out-> approach , or move in x-direction in 4-d space "I want to deal with the object's space rather than it's projection's space")

  • Third: If all of the above wasn't possible in the shader can I use c++amp(or it's alternatives) to accelerate the execution of such operations in the main program or will this cause performance degradation for the "Draw()" function.

I have searched the web and "Stackoverflow" but I couldn't find anything of use.

Was it helpful?

Solution

Disclaimer: I'm not an expert in GPUs and shaders; and I've used OpenGL/WebGL/GLSL rather than Direct3D/HLSL. So I'm only answering this question because no one else has. :-)

Regarding pointers: I'm pretty sure you can't use pointers within the GPU, since data that you send to the GPU would have unpredictable addresses (locations) in GPU memory.

But regarding dynamic data structures (variable number of dimensions), it seems like you could do this by just varying the "size" parameter passed to vertexAttribPointer() or the equivalent. You pass in a flat array containing all your vertex coordinates, with n coordinates per vertex; and use the size parameter to tell the shader what n is.

Then in the vertex shader, you can project the data from n dimensions to 3, using a projection matrix that you construct in the shader from parameters passed in.

I think similarly, in the fragment (pixel) shader, you can the project the data from 3 dimensions to 2, using a view matrix that you construct in the shader from parameters passed in.

Hopefully this will get you started, so you can get to the point of asking more specific questions. To be honest, I've not found SO to be as productive a place for getting questions answered about graphics, as it is for some other topics, like Python. You might have better luck asking on a web site specific to Direct3D.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top