Problem with Blur code from Frank Luna's book

Started by
2 comments, last by Andrey_K 2 years, 11 months ago

Compute shader code have following lines

Texture2D gInput;

RWTexture2D<float4> gOutput;

#define N 256

#define CacheSize (N + 2*gBlurRadius)

groupshared float4 gCache[CacheSize];

[numthreads(N, 1, 1)]

void HorzBlurCS(int3 groupThreadID : SV_GroupThreadID,

int3 dispatchThreadID : SV_DispatchThreadID)

{

if(groupThreadID.x < gBlurRadius)

{

int x = max(dispatchThreadID.x - gBlurRadius, 0);

gCache[groupThreadID.x] = gInput[int2(x, dispatchThreadID.y)];

}

if(groupThreadID.x >= N-gBlurRadius)

{

int x = min(dispatchThreadID.x + gBlurRadius, gInput.Length.x-1);

gCache[groupThreadID.x+2*gBlurRadius] = gInput[int2(x, dispatchThreadID.y)];

}

gCache[groupThreadID.x+gBlurRadius] = gInput[min(dispatchThreadID.xy, gInput.Length.xy-1)];

What is this gInput.Length.x and gInput.Length.xy ? Texture2D should not have length. In cpp side

InputMap = mFX->GetVariableByName("gInput")->AsShaderResource();

where InputMap is ID3DX11EffectShaderResourceVariable.

void SetInputMap(ID3D11ShaderResourceView* tex) { InputMap->SetResource(tex); }

So this is an SRV. Which means this is Texture2D, not some “hidden” constant buffer struct? But what is the length? I thought it's the width, which I can get from GetDimensions(), but what is xy then?

Advertisement

I’m not sure, but maybe because it‘s basically a 2D vector, you can do vector length? And .x would access just the U/X of the texture

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

Turned out it was a width and a height of the texture, and xy thing I changed to “cache[groupThreadID.x + blurRadius] = Input[dispathThreadID.xy];” works as intended. I'm not sure why it had min(), I don't think it's needed, it takes only pixels that aren't close to an edge.

This topic is closed to new replies.

Advertisement