如何将信息发送到 DirectX 10 中的 HLSL 效果?
我想将视图向量发送到 ID3D10Effect 变量以计算镜面照明。如何从正在运行的 DirectX 程序向 HLSL 发送向量甚至标量值?我想做类似的事情
render() {
//do transformations
D3DXMatrix view = camera->getViewMatrix();
basicEffect.setVariable(viewVector, view);
//render stuff
}
I'd like to send my view vector to an ID3D10Effect variable in order to calculate specular lighting. How do I send a vector or even just scalar values to the HLSL from the running DirectX program? I want to do something like
render() {
//do transformations
D3DXMatrix view = camera->getViewMatrix();
basicEffect.setVariable(viewVector, view);
//render stuff
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 GetVariableByName 获取指定变量的接口HLSL 中的变量。调用 AsVector (请注意文档这一点是错误的。它返回一个指针!)在返回的接口上获取向量变量接口,然后调用 SetFloatVector。
Use GetVariableByName to get an interface to the named variable in the HLSL. Call AsVector (Note the documentation at this point is wrong. It returns a pointer!) on the returned interface to get a vector variable interface and then call SetFloatVector.
在你的效果中,你应该有类似的东西:
然后在你的渲染函数中,在绑定效果之前:
与大多数效果属性句柄一样,我建议“缓存”指向变量的指针。将矩阵变量存储在渲染循环之外的另一个指针中,例如:
然后设置变量变为:
In your effect, you should have something like:
Then in your render function, before binding the effect:
As with most effect attribute handles, I would suggest 'caching' the pointer to the variable. Storing the matrix variable in another pointer outside of your render loop, like:
And then setting the variable turns into: