Jump to content
  • Advertisement
Sign in to follow this  

HLSL - access to pixel - misconcept (pixelshader)

This topic is 2652 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
I dunno your algorithm.

1) Modern GPUs can render only 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

to bee more specific i have a pixelshader code here:

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;


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

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

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.


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!