如何将信息发送到 DirectX 10 中的 HLSL 效果?

发布于 2024-09-03 13:43:11 字数 261 浏览 1 评论 0原文

我想将视图向量发送到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

感性不性感 2024-09-10 13:43:11

使用 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.

漆黑的白昼 2024-09-10 13:43:11

在你的效果中,你应该有类似的东西:

cbuffer {
    float4x4 viewMatrix;
}

然后在你的渲染函数中,在绑定效果之前:

D3DXMatrix view = camera->getViewMatrix();
basicEffect->GetVariableByName("viewMatrix")->AsMatrix()->SetMatrix((float*) &view);

与大多数效果属性句柄一样,我建议“缓存”指向变量的指针。将矩阵变量存储在渲染循环之外的另一个指针中,例如:

ID3D10EffectMatrixVariable* vmViewMatrix = basicEffect->GetVariableByName("viewMatrix")->AsMatrix();

然后设置变量变为:

vmViewMatrix->SetMatrix((float*) &view);

In your effect, you should have something like:

cbuffer {
    float4x4 viewMatrix;
}

Then in your render function, before binding the effect:

D3DXMatrix view = camera->getViewMatrix();
basicEffect->GetVariableByName("viewMatrix")->AsMatrix()->SetMatrix((float*) &view);

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:

ID3D10EffectMatrixVariable* vmViewMatrix = basicEffect->GetVariableByName("viewMatrix")->AsMatrix();

And then setting the variable turns into:

vmViewMatrix->SetMatrix((float*) &view);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文