用RenderMonkey编写shader[1]


1.使用RenderTarget进行全屏渲染

     首先需建立Renderable Texture,然后在你需要生成全屏截图纹理的pass中添加一个Render Target指向建立的Renderable Texture。这时窗口将不再显示任何东西。这时需要新建一个PASS来将这个全屏纹理渲染到backbuffer显示在屏幕上,需要添加一个模型,为ScreenAlignedQuad.3ds,一个材质指向这个Renderable Texture,对模型进行顶点变换,使得这个四边形面片占满窗口。


   Output.Position = float4(Input.Position.xy,0,1);
   Output.Texture.x = 0.5f*(1+Input.Position.x - fViewportWidth);
   Output.Texture.y = -0.5f*(1+Input.Position.y - fViewportHeight);


注意需要添加RenderState,把D3DRS_CULLMODE设置成D3DCULL_NONE。

rfx文件:点击打开链接

 2.filter滤镜效果

所谓filter-滤镜,就是一个float4x4矩阵,乘以颜色分量,或者是将颜色分量乘以不同的系数。


Effect添加float4x4变量

 //D3D中采用行主序

float4 color = tex2D(renderTex,Input.Texture);
return mul(color,color_filter);

 common color manipulation matrices:
rfx文件:点击打开链接


3.HLSL浮雕效果

实现方法:把图象的每一个象素和左上方的象素进行求差运算,并加上一个灰度。这个灰度就是表示背景颜色。

   float2  upLeftUV = float2(Input.Texture.x - 1.0/fViewportWidth , Input.Texture.y - 1.0/fViewportHeight);
   float4  bkColor = float4(0.5 , 0.5 , 0.5 , 1.0);
   float4  curColor    =  tex2D( renderTex, Input.Texture );
   float4  upLeftColor =  tex2D( renderTex, upLeftUV );
   //相减得到颜色的差
   float4  delColor = curColor - upLeftColor;
   //去色
  float  h = 0.3 * delColor.x + 0.59 * delColor.y + 0.11* delColor.z;
   float4  outColor =  float4(h,h,h,0.0)+ bkColor;
   return  outColor;

rfx文件:点击打开链接




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值