简体   繁体   English

Direct3d和hlsl可变大小的顶点和多维几何对象?

[英]Direct3d and hlsl varying size vertices and multiddimensional geometric objects?

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 . 我是Direct3d,Graphics,HLSL,c ++的新手,并且我试图编写一个程序来呈现不同的几何多维形状(例如,超立方体),该程序应该在用户定义后从用户那里接收顶点绘制尺寸,绘制,旋转和平移形状的数量。

  • 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). 第二:将形状从x维空间投影到3维空间,我应该在代码(CPU)中执行此操作,还是可以将对象顶点和投影矩阵传递给着色器(HLSL),如果可以,如何(尤其是在运行时定义的矩阵大小不同)。

  • 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") 与上述视图矩阵问题相同(假设对象是4-d,我希望程序放大/缩小->方法,或者在4-d空间中沿x方向移动“我想处理对象的空间而不是投影的空间”)

  • 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. 第三:如果无法在着色器中实现上述所有功能,我可以使用c ++ amp(或其替代方法)来加速主程序中此类操作的执行,还是会导致“ Draw()”的性能下降功能。

I have searched the web and "Stackoverflow" but I couldn't find anything of use. 我已经搜索过网络和“ Stackoverflow”,但是找不到任何有用的东西。

Disclaimer: I'm not an expert in GPUs and shaders; 免责声明:我不是GPU和着色器方面的专家; and I've used OpenGL/WebGL/GLSL rather than Direct3D/HLSL. 而且我使用的是OpenGL / WebGL / GLSL,而不是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. 关于指针:我非常确定您不能在GPU内使用指针,因为发送到GPU的数据在GPU内存中将具有不可预测的地址(位置)。

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. 但是对于动态数据结构(可变数量的维),似乎可以通过更改传递给vertexAttribPointer()或等效参数的“ size”参数来vertexAttribPointer() You pass in a flat array containing all your vertex coordinates, with n coordinates per vertex; 您传入包含所有顶点坐标的平面数组,每个顶点n个坐标; and use the size parameter to tell the shader what n is. 并使用size参数告诉着色器n是什么。

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. 然后,在顶点着色器中,可以使用在着色器中根据传入的参数构造的投影矩阵,将数据从n维投影到3维。

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. 我认为类似地,在片段(像素)着色器中,可以使用从传入的参数在着色器中构造的视图矩阵,将数据从3维投影到2维。

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. 老实说,我还没有发现SO可以像回答Python之类的其他主题一样有效地解决图形问题。 You might have better luck asking on a web site specific to Direct3D. 在特定于Direct3D的网站上询问运气可能会更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM