有关XNA中的HLSL的帮助 [英] Help about HLSL in XNA

查看:105
本文介绍了有关XNA中的HLSL的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是HLSL(高级着色器语言XNA 4.0)的初学者.编写HLSL代码非常困难,因为它没有视觉智能功能,并且公式的光学非常困难.在Visual Studio中像在记事本中一样编写代码HLSL.您能告诉我程序最好编写代码HLSL 解释光学公式.谢谢!

I''m beginner in HLSL(High Level Shader Language XNA 4.0). Write code HLSL is very hard beause it''s not have function Visual Intelligence and formula''s optical is very hard . Write code HLSL in Visual Studio like write in notepad. Can you tell me program write code HLSL best and explain formula''s optical . Thanks!

推荐答案

对不起,但您不清楚要查找的内容.我最好的猜测是,您需要一个用于着色器的可视化编辑器,从而为您提供结果外观的示例.

哇.我只是搜索HLSL编辑器,而仅获得语法突出显示或智能感知的文本编辑器的结果.这可能是有很好的理由的.虽然可以将着色器的代码显示为具有可编辑属性的某种图形,但这并不会消除用户理解着色器实现的算法的需要.如果没有运气,只有运气才能编辑一些值并查看结果,这会带来任何有用的结果.

恐怕您别无选择,只能像其他所有人一样努力奋斗.着色器很短,通常是线性过程.在大多数情况下,没有循环或其他令人困惑的事情.

顶点着色器用于将数据从3D对象空间转换为3D世界空间,然后转换为2D视图空间.通常在关于计算机图形学的好书中解释这些问题,以及线性代数的基础知识.着色器本身的代码可能很简单,但是如果您不了解那些3D和2D空间以及所涉及的数学知识,那么您几乎没有机会了解其目的.

像素着色器用于确定多边形的每个像素的颜色.多边形实际上是由三个顶点组成的三角形.至此,由于有了顶点着色器,我们已经知道了顶点的2D屏幕坐标.但是顶点只是角点.那三角形里面的像素呢?

像素的颜色可以是常数,可以插值附加在每个顶点的颜色值之间,并可以从纹理贴图中以更多方式进行采样.您甚至可以结合使用这些技术或发明新技术.再次,我建议您先阅读一本有关计算机图形学的书籍,并了解一些基本技术.然后,您将能够了解实现它们的顶点着色器,并最终还可以对其进行修改.

光线计算也是如此,像素着色器中也进行了计算.基本上,它只是根据来自一个或多个光源的多少光到达该像素,才使像素的计算出的颜色更亮或更暗.但是,再次有许多简单或更高级的方法可以完成此操作,只有研究它们才能为您提供帮助.

底线:为自己准备一本涵盖3D图形基础的好书.本书是否稍旧一点都没关系.自从所有这些工作仍在软件中完成以来,这些事情并没有真正改变.那些功能强大的图形处理器仅允许我们每秒执行更多操作.

从书中汲取知识(例如如何将纹理应用于多边形),并为自己获取实现该技术的示例着色器.一旦您了解了该理论,着色器将不再对您神秘.
Sorry, but it''s not quite clear what you are looking for. My best guess is that you want a visual editor for shaders that gives you a sample of what the result looks like.

Wow. I just searched for HLSL editors and only got results for text editors with syntax highlighting or intellisense. This is probably for a very good reason. While it''s possible to display the code of a shader as some kind of graph with editable properties, this would not take away the need for the user to understand the algorithm that is implemented by the shader. The ability to edit some values and see the results would only by luck lead to anything useful without that understanding.

I''m afraid you have little choice than going the hard way like everybody else. Shaders are short and usually linear procedures. In most cases there are no loops or other confusing things.

Vertex shaders are used to transform the data from 3D object space to 3D world space and then to 2D view space. Those things usually are explained in a good book about computer graphics, along with the basics of linear algebra. The code of the shader by itself may be simple, but you will have little chance of understanding its purpose without knowing about those 3D and 2D spaces and the math which is involved.

Pixel shaders are about determining the color of each pixel of a polygon. The polygons are actually triangles, formed by three of the vertices. At this point we already know the 2D screen coordinates of the vertices, thanks to the vertex shader. But the vertices are only the corner points. What about the pixels inside this triangle?

The color of a pixel may be a constant, interpolated between color values attached to each vertex, sampled from a texture map and in many more ways. You can even combine those techniques or invent new ones. Again I would suggest you start by consulting a book about computer graphics and understanding some of the basic techniques. Then you will be able to understand vertex shaders that implement them and eventually also be able to modify them.

The same goes for light calculations, which are also done in the pixel shader. Basically it''s just making the calculated color for the pixel lighter or darker, according to how much light from one or more light sources reaches that pixel. But once again there are many simple or more advanced ways to accomplish this and only studying them will help you.

Bottom line: Get yourself a good book that covers the basics of 3D graphics. It does not matter if the book is a little older. Those things have not really changed since the days when all this was still done in software. Those powerful graphics processors only allow us to do much more of it every second.

Take your knowledge from the book (like how to apply a texture to a polygon) and get yourself a sample shader that implements exactly this technique. Once you have understood the theory, the shader will not be mysterious at all for you anymore.


这篇关于有关XNA中的HLSL的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆