Directx11教程40 纹理映射(10)

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

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

pic0047.gifpic0048.gif

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

pic0049.gif

  为此我们新建一个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;
    }

程序执行的界面如下:

image

完整的代码请参考:

工程文件myTutorialD3D11_35

代码下载:

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

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

posted on 2019-05-06 08:38 NET未来之路 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/lonelyxmas/p/10817634.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值