每个实例纹理,以及顶点和像素着色器 [英] Per Instance Textures, and Vertex And Pixel Shaders

查看:83
本文介绍了每个实例纹理,以及顶点和像素着色器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如何实现每个实例纹理,顶点着色器和像素着色器?


How do you implement per instance textures, vertex shaders, and pixel shaders?

给定:

1.顶点缓冲区中的两个不同模型模板,Square&三角形$
2.具有[n]个实例类型为Square或Triangle的实例缓冲区。

Given:
1. Two different model templates in Vertex Buffer, Square & Triangle
2. Instance Buffer with [n] instances of type Square or Triangle.

如何将Texture,VertexShader或PixelShader ID添加到缓冲区数据这样HLSL或InputAssembly可以确定在绘制时使用哪个着色器?

How do I add a Texture, VertexShader or PixelShader ID to the buffer data so that HLSL or the InputAssembly can determine which Shader to use at draw time?

A。我如何"设置"将多个像素和顶点着色器放入DeviceContext,如何告诉Di​​rectX"切换"?在渲染时加载的顶点着色器?

A. How do I "Set" multiple Pixel and Vertex Shaders into the DeviceContext, and how do I tell DirectX to "switch" the Vertex Shader that is loaded at render time?

B。每种类型的着色器数量(顶点,像素,外壳等)可以与默认顶点中的模型模板相关联。缓冲区?

B. How many Shaders of each type, (Vertex, Pixel, Hull, etc), can I associate with model templates in the default Vertex  Buffer?

C。我可以在HLSL中使用某种着色器选择器吗?

C. Can I use some sort of Shader Selector in HLSL?

相关C ++代码

当我创建输入布局时,我可以不指定实际的顶点着色器,或以某种方式指定多个?

When I create an input layout, can I do this without specifying an actual Vertex Shader, or somehow specify more than one?




NS::ThrowIfFailed( result = NS::DeviceManager::Device->CreateInputLayout(
NS::ModelRenderer::InitialElementDescription, 2, vertexShaderFile->Data, vertexShaderFile->Length, & NS::ModelRenderer::StaticInputLayout) );



当我设置VertexShader和PixelShader时,如何将它们与VertexBuffer中的特定模型相关联?是否可以设置多个?


When I set the VertexShader and PixelShader, how do I associate them with a particular model in my VertexBuffer? Is it possible to set more than one of each?

DeviceManager::DeviceContext->IASetInputLayout(ModelRenderer::StaticInputLayout.Get());
DeviceManager::DeviceContext->VSSetShader(ModelRenderer::StaticVertexShader.Get(), nullptr, 0);
DeviceManager::DeviceContext->PSSetShader(ModelRenderer::StaticPixelShader.Get(), nullptr

推荐答案

每个Draw调用不能使用每个类型的多个着色器.Draw调用为绑定缓冲区中找到的几何执行每个绑定着色器。如果你想要不同的纹理,你会添加关于哪个您希望将纹理放入每个实例的
数据中,然后让像素着色器相应地选择正确的纹理(通过纹理数组或使用条件分支)。
You cannot use more than one shader of each type per Draw call. A Draw call executes each bound shader for the geometry it finds in the bound buffers. If you want different textures, you would add data about which texture you wanted into the per-instance data and then have the pixel shader choose the correct texture accordingly (either via a texture array or by using conditional branching).


这篇关于每个实例纹理,以及顶点和像素着色器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆