Sign in to follow this  
circassia

HLSL - access to pixel - misconcept (pixelshader)

Recommended Posts

circassia    100
Hi guys,

i implemented the HUGO-Elias Algorithm in C++, now i want to implement it as shader, would be nice if you could explain me some misconceptions:

1) Can i access a specific point of a texture? for example, i want to draw a rectangle in the middle of the texture?

2) is there an disadvantage of using loops?

thank you very much for your help ;)

Share this post


Link to post
Share on other sites
pcmaster    982
I dunno your algorithm.

1) Modern GPUs can render [b]only[/b] triangles. They don't really do anything else (sorry for oversimplification). So if you want to render a rectangle, just draw it with whatever coordinates you want. Your GPU will rasterise it and run a pixel shader for each fragment. That means you cannot "spawn" rectangles from within a pixel shader (which is again a part of a rasterised shape), if that's what you're asking. With DX11 you are able to store values to arbitrary offsets (coordinates) for a huge performance loss, AFAIK.

2) What does that mean? "Loops" translate to branch/jump instructions and you're fine to use them (as long as a whole bunch of neighbouring units end up with the same result, otherwise there might be a performance penalty).

Your questions are extremely general, no way to answer them in a simple manner.

Share this post


Link to post
Share on other sites
circassia    100
Hi,

to bee more specific i have a pixelshader code here:

[code]sampler Txr1b;
sampler Txr1w;
float4 ps_main( float4 inDiffuse: COLOR0,
float2 inTxr1: TEXCOORD0 ) : COLOR0
{
// Output color from texture, specify sampler (Texture0) with texture coordinate (inTxr1)


float4 memTex = tex2D(Txr1b, inTxr1)/2;
float4 memTex2 = tex2D(Txr1w, inTxr1)/2;
float4 memTemp = memTex;



float4 color;
color.rgb = memTex.rgb * 0.4 + memTex2.rgb * 0.6;

return color;


}[/code]

I would like to know how i can check something like that

if(pixel(x,y)) > 0.8)

i want to now if i can access to the pixels value, and how?

thank you very much!

Share this post


Link to post
Share on other sites
kauna    2922
[quote name='circassia' timestamp='1313586688' post='4850298']
i want to now if i can access to the pixels value, and how?
[/quote]


You can read any texel in a texture (I suggest using LOAD instead of sample). The restriction is that you cannot write to a texture which is bound for reading.

Also, writing to a rendertarget is defined by the shape of primitive (triangle, line, point) as stated earlier.

Compute shaders may be the thing you are looking for (or maybe not). They allow some things done differently.

Cheers!




Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this