游戏开发论坛

 找回密码
 立即注册
搜索
查看: 2243|回复: 5

有办法缓存vertex shader计算的结果吗?

[复制链接]

4

主题

10

帖子

10

积分

新手上路

Rank: 1

积分
10
发表于 2005-4-5 18:18:00 | 显示全部楼层 |阅读模式
看了sdk里的shadow volume的code和doc
doc里写道:

Finally, there is another area that could call for some performance optimization. As shown earlier, the rendering algorithm with shadow volumes requires that the scene be rendered in multiple passes (one plus the number of lights in the scene, to be precise). Every time the scene is rendered, the same vertices get sent to the device and processed by the vertex shaders. This can be avoided if the application employs deferred lighting with multiple rendertargets. With this technique, the application renders the scene once and outputs a color map, a normal map, and a position map. Then, in subsequent passes, it can retrieve the values in these maps in the pixel shader and apply lighting based on the color, normal and position data it reads. The benefit of doing this is tremendous. Each vertex in the scene only has to be processed once (during the first pass), and each pixel is processed exactly once in subsequent passes, thus ensuring that no overdraw happens in these passes.

而源文件没有做这一步优化,而上面提到的"the application renders the scene once and outputs a color map, a normal map, and a position map"这一步不知怎么实现,希望大家能指点小弟一下,谢谢了!

1

主题

50

帖子

50

积分

注册会员

Rank: 2

积分
50
发表于 2005-4-5 22:21:00 | 显示全部楼层

Re:有办法缓存vertex shader计算的结果吗?

你的问题和你的题目没有关系。
sdk doc的说法跟shadow volume也没有直接的关系,几乎对所有需要多遍渲染的场景都有效。
sdk doc的意思是,你可以使用另外的光照模型来渲染整个场景(不是shadow volume)。在这种方法中,先利用MRT同时渲染出color map, normal map和position map,然后再利用ps对每个pixel计算光照,一遍渲染出整个场景。
原来的方法里面,场景模型要被渲染n+1次,n是光源数,像素填充数也非常多,而在新的方法里面,场景模型仅被渲染固定为1次,像素填充也固定为屏幕的像素数,所以可以极大的提高应用程序的效率。

4

主题

10

帖子

10

积分

新手上路

Rank: 1

积分
10
 楼主| 发表于 2005-4-6 01:01:00 | 显示全部楼层

Re:有办法缓存vertex shader计算的结果吗?

万分感谢.
只是我的显卡不支持per pixel lighting,暂时不能去实现一下了.还有doc里说了有的显卡只支持相同位数的象素格式,那么position map和normal map是否都要分成三个不同的render target了?

另外
我取的题目是我刚才的一个想法:
每一帧开头把每个顶点 position 和normal暂时保存下来,只是省去了多余的顶点空间变换;
暂时还是没办法实现,所以试验另一个方法中.........

1

主题

50

帖子

50

积分

注册会员

Rank: 2

积分
50
发表于 2005-4-6 09:38:00 | 显示全部楼层

Re:有办法缓存vertex shader计算的结果吗?

Vertex shader的计算结果到目前的Shader model 3.0为止似乎都没有办法保存。
未来的Shader model 4.0的vs/ps统一结构可能就可以了。

a系的卡我用过9800 pro,n系的卡我用过5200/6600,都没有只支持相同位数的象素格式的问题,别的芯片的卡就很难说了...

8

主题

553

帖子

560

积分

高级会员

Rank: 4

积分
560
发表于 2005-4-6 12:33:00 | 显示全部楼层

Re: Re:有办法缓存vertex shader计算的结果吗?

nmmgb: Re:有办法缓存vertex shader计算的结果吗?

万分感谢.
只是我的显卡不支持per pixel lighting,暂时不能去实现一下了.还有doc里说了有的显卡只支持相同...

doc里说的“相同像素“的问题应该是指MRT时不同RT的size,pixel format必须相同,因为目前还没有支持不同像素格式MRT的硬件(包括nv4x)。
在目前的主流硬件上,保存vs的计算结果还是有办法的,在OpenGL下可以用nv的RTV扩展,在D3D9下可以使用32bit浮点类型的texture,然后在vs和ps里玩些花招,最后用vertex texture fetch就可以做到,但这样做效率还是比较低下的,如果vs不是非常复杂(比如非常多的指令条数和动态跳转),根本没有必要这样做。
可目前支持vertex texture的硬件只有nv4x,支持MTR的硬件也只有nv4x和r3xx/rv3xx。
从目前WGF2.0的未最终定下的文档看,D3D10完全改变了VB/IB -> DIP/DP的绘制方式,它引入了geometry shader和tessellation engine,在经过tessellation engine之前和之后会执行两套不同或相同的vs,除了tessellation engine不可编程以外,gs/vs/ps都是可编程的,在ps里还可以读取destination bufer的color/depth/stencil信息。引用它文档里面的原话说就是:它可以单pass绘制出一个多光源下的基于shadow volume的阴影,呵呵,非常值得期待的东西。

6

主题

444

帖子

457

积分

中级会员

Rank: 3Rank: 3

积分
457
发表于 2005-4-6 15:26:00 | 显示全部楼层

Re:有办法缓存vertex shader计算的结果吗?

to kypck:
MRT其实只要RT的size和bit相同就可以(至少R300上是这样)pixel format可以不同,比如可以A16R16G16B16F+A16R16G16B16,或者A16R16G16B16F+R32G32F等……
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-12-25 04:42

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表