dx shader HLSL 红龙书 18章

实现书上的代码时出现一个错误.

HLSL源代码:


// 
// File: ps_alphablend.txt
// 
// Author: Frank Luna (C) All Rights Reserved
//
// System: AMD Athlon 1800+ XP, 512 DDR, Geforce 3, Windows XP, MSVC++ 7.0 
//
// Desc: Pixel shader that does multi texturing.
//          


//
// Globals
//

sampler BaseTex;
sampler SpotLightTex;
sampler StringTex;

//
// Structures
//


struct PS_INPUT
{
    float position   : POSITION;
    float color      : COLOR;
    float2 base      : TEXCOORD0;
    float2 spotlight : TEXCOORD1;
    float2 text      : TEXCOORD2;
};

struct PS_OUTPUT
{
    vector diffuse : COLOR0;
};


//
// Main
//

PS_OUTPUT Main(PS_INPUT input)
{
    // zero out members of output
    PS_OUTPUT output = (PS_OUTPUT)0;

    // sample appropriate textures
    vector b = tex2D(BaseTex,      input.base);
    vector s = tex2D(SpotLightTex, input.spotlight);
    vector t = tex2D(StringTex,    input.text);

    // combine texel colors
    vector c = b * s + t;

    // increase the intensity of the pixel slightly
    c += 0.1f;

    // save the resulting pixel color
    output.diffuse = c;

    return output;
}

在写HLSL代码时,我想先看看 b * s 效果, 于是写上 vector c = b * s;

然后就直接报错,错误原因访问空指针.

原因:

StringTexHandle    = MultiTexCT->GetConstantByName(0, "StringTex");
StringTexHandle 无法得到句柄.

我的猜测:

在HLSL中我没用到t, 于是编译器直接把 sampler StringTex; 和 vector t = tex2D(StringTex,    input.text); 这两条语句给"优化"掉了(在 D3DXCompileShaderFromFile的时候).



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值