原文:Directx11教程40 纹理映射(10)

     本章尝试使用纹理行列式,或者说纹理数组,在ps中,使用2个纹理,最终的像素颜色,是光照颜色*纹理1采样颜色*纹理2采样颜色,主要是想达到如下的效果:

   把这两个图像以及光照产生的颜色融合生成以下图像:

  为此我们新建一个lighttex2.ps文件,在其中定义:

//两个纹理,可用于纹理混合,bump mapping等等
Texture2D shaderTexture[2];
SamplerState SampleType;

float4 textureColor1 = shaderTexture[0].Sample(SampleType, input.tex);
float4 textureColor2 = shaderTexture[1].Sample(SampleType, input.tex);

textureColor = saturate((textureColor1 + textureColor2)/2.0);

//2.2是gamma校正值
finalcolor = finalcolor * pow(textureColor, 2.2)

另外定义一个LightTex2ShaderClass,专门用来处理lightex2.vs和lighttex2.ps,在该类中,我们通过

// 设置ps shader资源.
deviceContext->PSSetShaderResources(0, 2, texArray);

装入一个纹理数组。

最后就是Graphics渲染类的修改,我们在左侧再画一面墙,是用一个纹理,而正面的墙,使用纹理融合。

m_textures[0] = m_TexManager->createTex(m_D3D->GetDevice(),string("stone01.dds"));
m_textures[1] = m_TexManager->createTex(m_D3D->GetDevice(),string("dirt01.dds"));

//执行平移操作,得到最终的模型世界矩阵
D3DXMatrixRotationX(&worldMatrix1, -1.57); //pai/2
D3DXMatrixTranslation(&worldMatrix2, 0.0, 0.0, 8.0);
D3DXMatrixMultiply(&worldMatrix3, &worldMatrix1, &worldMatrix2);

result = m_LightTex2Shader->Render(m_D3D->GetDeviceContext(), m_PlaneModel->GetIndexCount(), worldMatrix3, viewMatrix, projectionMatrix,
    light, material, camera,m_textures);
if(!result)
    {
    return false;
    }

//执行平移操作,得到最终的模型世界矩阵
D3DXMatrixRotationZ(&worldMatrix1, -1.57); //pai/2
D3DXMatrixTranslation(&worldMatrix2, -10.0, 0.0, 0.0);
D3DXMatrixMultiply(&worldMatrix3, &worldMatrix1, &worldMatrix2);

result = m_LightTexShader->Render(m_D3D->GetDeviceContext(), m_PlaneModel->GetIndexCount(), worldMatrix3, viewMatrix, projectionMatrix,
    light, material, camera,m_TexManager->createTex(m_D3D->GetDevice(),string("stone01.dds")));
if(!result)
    {
    return false;
    }

程序执行的界面如下:

完整的代码请参考:

工程文件myTutorialD3D11_35

代码下载:

http://files.cnblogs.com/mikewolf2002/d3d1127-28.zip

http://files.cnblogs.com/mikewolf2002/pictures.zip

最新文章

  1. Java性能调优之:idea变慢解决
  2. angular源码阅读的起点,setupModuleLoader方法
  3. 关于OJ1028的参考解法
  4. comboBox 手动输入后回车自动更新数据
  5. QTP处理各类鼠标事件fireEvent
  6. ECLIPSE ANDROID PROJECT IMPORT SUMMARY
  7. SSRS报表参数设置
  8. php 得到一个文件夹下的所有文件,包括子文件中的文件
  9. POJ2817 WordStack(状压DP)
  10. U盘启动
  11. Delphi XE5教程5:程序的结构和语法
  12. Solr学习笔记-在Tomcat上部署执行Solr
  13. 2015 南阳ccpc The Battle of Chibi (uestc 1217)
  14. mysql8.0.主从复制搭建
  15. CF1129B 【Wrong Answer】
  16. 利用chrome浏览器爬取数据
  17. steam Depot 生成与应用脚本
  18. [PHP]更新中间关联表数据的两种思路
  19. SQL文件的BOM问题导致的invalid character错误及解决
  20. Linux杀毒软件ClamAV初次体验

热门文章

  1. HTML5 drag拖动事件
  2. 此处有加速 apt-get github docker pull
  3. 【JAVA】Class.getResource()与ClassLoader.getResource()的区别
  4. PAT甲级——A1046 Shortest Distance
  5. JSP - (Java Server Pages) - Java服务器界面
  6. ongl与Struts标签
  7. 2019.10.29 csp-s模拟测试92 反思总结
  8. Leetcode476.Number Complement数字的补数
  9. 【python之路35】网络编程之socket相关
  10. 搭建单向HTTPS