Shader 学习笔记 ---Screen Effect介绍

   screen effects是Shader最基本的功能,它的概念很简单:先把场景渲染到一张纹理上,通常叫做Render Target . 再对Render Target做一些处理,最后绘制到屏幕上。  这可以是一个非常强大的功能,因为无论绘制的场景多么复杂,对于shader来说,只不过是一张纹理上的一堆像素而已。简单的screen effects如过滤器,模糊,混合等。

   To render your render target to the screen,要做的很简单,只需绘制一个和screen一样大小的rectangle,把render target作为它的纹理即可。在RenderMonkey提供了ScreenAlignedQuad.3ds作为该矩形使用。

  

  

  

   这里值得注意的是Texture Coordinates纹理坐标的问题,必须要确认矩形的四个角的纹理坐标为(0,0), (1,0), (1,1) and(0,1)

 

   Because you want every pixel on the screen to correspond to a single pixel in your texture,there is one aspect of the rendering hardware that must be considered. If you take a lookat Figure 5.4, a specific coordinate when rendering to the screen corresponds to the top left of that pixel.

  

 

    矩形实际的4个顶点为(–1,–1,0) to (1,1,0),可以简单地把它们变换到(0,0) to (1,1).

    // Texture coordinates are setup so that the full texture
    // is mapped completely onto the screen
   Out.texCoord.x = 0.5 * (1 + Pos.x);
   Out.texCoord.y = 0.5 * (1 - Pos.y);
 

 

    另一种情况是,当纹理由硬件读取时,纹理坐标是以像素中间位置为准,所以如果还按上面的方式读取的话会出现纹理偏移,这不是我们想要的。 于是我们作出调整:需要偏移一个像素。

 

// Texture coordinates are setup so that the full texture
// is mapped completely onto the screen
Out.texCoord.x = 0.5 * (1 + Pos.x - viewport_inv_width);
Out.texCoord.y = 0.5 * (1 - Pos.y - viewport_inv_height);

 

最后在处理Render Target的矩形时,需要把render state的D3DRS_MODE 改为D3DCULL_NONE.

 

细节性的东西还是很多~~  

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值