对多个纹理进行采样并在同一像素着色器中渲染为多个纹理

发布于 2024-10-28 04:55:43 字数 1055 浏览 1 评论 0原文

我的总体目标是能够创建一个像素着色器,它将多个纹理作为输入,并渲染到多个目标。 以及通过初始化和完成着色器,通过重复运行该着色器,我将得到结果。

我之前创建过具有多个输入纹理的着色器,以及渲染到多个目标的着色器,但我从未将这两者结合起来。

我认为导致问题的是我对语义以及如何正确设置输入缺乏充分的理解和输出纹理。

我见过几种不同的获取输入纹理的方法,但对于如何设置它感到困惑。

下面是由 init 和 iterate 着色器输出的共享结构的代码(finalize 着色器仅输出颜色):

struct FRACTAL_OUTPUT
{
    float4 IterationsAndControl : COLOR0;
    float4 Variables1And2 : COLOR1;
    float4 Variables3And4 : COLOR2;
};

下面是 itterate 和 Finalize 着色器的纹理声明(init 着色器不使用任何纹理):

Texture2D IterationsAndControl;
sampler IterationsAndControlSampler : register(s4)
{
    Texture = <IterationsAndControl>;
};

纹理2D变量1和2; 采样器变量1和2采样器:寄存器(s5) { 纹理 = ; };

纹理2D变量3和4; 采样器变量3And4Sampler:寄存器(s6) { 纹理 = ; };

在 C# XNA 代码中,我设置渲染目标(通过执行 GraphicsDevice.SetRenderTargets(),然后设置纹理参数(通过执行 Effect.Parameter["TextureVariableName"].SetValue()),然后绘制一个四边形(通过精灵批处理)。

任何帮助将不胜感激,因为我找不到任何做这样的事情的例子。

My overall goal is to be able to create a pixel shader that takes multiple textures as input, and renders to multiple targets.
As well as via an initialise and finalise shader, through repeated runs of this shader i will get my result.

I've created shaders with multiple input textures before, and shaders that render to multiple targets, but i've never combined the 2.

What i belive is causing issues is my lack of full understanding of semantics, and how to properly set up input and output textures.

I've seen several different ways of getting input textures and am getting confused as to how it should be set up.

Below is the code for a shared struct that is output by the init and itterate shaders (the finalise shader simply outputs a colour):

struct FRACTAL_OUTPUT
{
    float4 IterationsAndControl : COLOR0;
    float4 Variables1And2 : COLOR1;
    float4 Variables3And4 : COLOR2;
};

Below is the texture declarations for the itterate and finalise shaders (the init shader doesn't use any textures):

Texture2D IterationsAndControl;
sampler IterationsAndControlSampler : register(s4)
{
    Texture = <IterationsAndControl>;
};

Texture2D Variables1And2; sampler Variables1And2Sampler : register(s5) { Texture = <IterationsAndControl>; };

Texture2D Variables3And4; sampler Variables3And4Sampler : register(s6) { Texture = <IterationsAndControl>; };

In c# XNA code, i set the render targets (by doing GraphicsDevice.SetRenderTargets() then set the texture parameters (by doing Effect.Parameter["TextureVariableName"].SetValue(), then draw a quad (via a sprite batch).

Any help would be much appreciated, as i can't find any examples of doing something like this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

冰雪之触 2024-11-04 04:55:43

对于其他感兴趣的人,我已经设法(通过大量的试验和错误!)使其工作。

由于我正在进行数字运算,因此我将渲染目标格式设置为 Vector4(我以前有 rgba64,但似乎不起作用)。
因为我现在使用矢量格式,所以我还必须将设备采样器更改为 SamplerState.Point:

GraphicsDevice.SamplerStates[0] = SamplerState.PointClamp;
GraphicsDevice.SamplerStates[1] = SamplerState.PointClamp;
GraphicsDevice.SamplerStates[2] = SamplerState.PointClamp;
GraphicsDevice.SamplerStates[3] = SamplerState.PointClamp;

我的 FRACTAL_OUTPUT 结构尚未更改。

改变的是采样器。我正在使用 XNA 效果采样器中定义的宏:

#define DECLARE_TEXTURE(Name, index) \
Texture2D<float4> Name : register(t##index); \
sampler Name##Sampler : register(s##index);

然后,要采样多个纹理,我执行以下操作:

DECLARE_TEXTURE(IterationsAndControl, 1);
....
return tex2D(IterationsAndControlSampler, texCoord).x;

然后在 c# 中,我以通常的方式设置渲染目标,设置我的输入纹理,就像设置任何其他纹理一样效果参数。

For anyone else who's interested, i've managed (through a lot of trial and error!) to get this working.

Since i'm doing number crunching i set my render targets format to Vector4 (i previously had rgba64 which didn't seem to work).
Because i'm now using a vector format i also had to change the device samplers to be SamplerState.Point:

GraphicsDevice.SamplerStates[0] = SamplerState.PointClamp;
GraphicsDevice.SamplerStates[1] = SamplerState.PointClamp;
GraphicsDevice.SamplerStates[2] = SamplerState.PointClamp;
GraphicsDevice.SamplerStates[3] = SamplerState.PointClamp;

My FRACTAL_OUTPUT struct hasn't changed.

What has changed is the samplers. I'm using the macro defined in the XNA effect samplers:

#define DECLARE_TEXTURE(Name, index) \
Texture2D<float4> Name : register(t##index); \
sampler Name##Sampler : register(s##index);

Then, to sample multiple textures i'm doing the following:

DECLARE_TEXTURE(IterationsAndControl, 1);
....
return tex2D(IterationsAndControlSampler, texCoord).x;

Then in c# I set the render targets in the usual way, setting my input textures as i'd set any other effect parameter.

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