• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
iedoc

Loop through an ID3D11Texture2D object

3 posts in this topic

I would like to know how to iterate through the texels of an ID3D11Texture2D object, so i can do an operation that replaces certain texels with that of another ID3D11Texture2D object.

So what i'm doing is rendering two scenes onto two different render targets. What i'd like to do is, is do an operation that replaces certain texels of one with the other (like every other texel). I was first looking at the pixel shader to do this, but i suppose that might not be possible (i'm not very good with hlsl). How would one go about doing this?

How to iterate through the texels of an ID3D11Texture2D and edit them, or how to know the current pixel in the pixel shader. Or another method that i didn't think of would be just as well

You might think this sounds exactly like blending, and it kind of is, but i don't want the pixels to "bleed" into the pixels next to them
0

Share this post


Link to post
Share on other sites
Hi!

You could do that with a pixel shader by rendering a viewport quad with the viewport set to the size of the textures (I assume their resolutions match?). Then use the load intrinsic (avoids texture samplers) to fetch the texture colors from both input textures and combine them however you want.
[CODE]Texture2D<float4> inputTexture1;
Texture2D<float4> inputTexture2;
float4 PS(float4 pos: SV_Position) : SV_Target0
{
float4 texA = inputTexture1.Load(int3(pos.xy, 0));
float4 texB = inputTexture2.Load(int3(pos.xy, 0));
return magicallyCombineTheTextures(texA, texB, pos.xy);
}[/CODE]
You’d have to maintain two copies of the inputTexture1 in a ping-pong manner, since you read from and write to it. Well, unless the color in inputTexture1 doesn’t matter for your result color e.g. in case you just replace it with inputTexture2 under a certain condition (so no read involved). Then simple blending would do the trick.
In the sample above I passed the position to the magicallyCombineTheTextures function, since your ‘iterate’ sounded like you need to have the ID of the pixel for the combination of the textures. You could as well do this with a compute shader (and thereby bypass the rasterization overhead).

If you want to change (for instance) inputTexture1 in place (requires shader model 5) you could use an UnorderedAccessView (RWTexture2D<float> inputTexture1) and directly write the result back to inputTexture1. Though, you’d have to fetch the colors component wise from the UAV. Perhaps it would be beneficial to launch 4 threads and use the compute shader for that. Well, unless the context switch to the compute pipeline doesn’t cost too much. [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] I guess you’d need some experiments here.

[quote name='iedoc' timestamp='1330269013' post='4916720']
You might think this sounds exactly like blending, and it kind of is, but i don't want the pixels to "bleed" into the pixels next to them.
[/quote]
Shouldn’t happen if you don’t use samplers.

Or you could take a step back and look again whether you can avoid the rendering to the second texture at all. Maybe there is a clever way to use the stencil buffer or so to directly render the result to the target texture.

Cheers!
1

Share this post


Link to post
Share on other sites
you could use a point samper to avoid the blending problem. But even with blending, i needed to make sure that every other pixel was exactly the other texture, with blending, i can't be sure that the blending operation will do that perfectly. I needed an operation that was very predictable if you know what i mean

but this was actually a double post (although i only clicked the send button once...). The answer was solved already, all i needed was SV_Position to get the position of the current pixel. i didn't realize SV_Position could be used in the pixel shader (I mean, i knew that, but for some reason i had spaced it out... I'm really not very good with hlsl). Just knowing you can use SV_Position to get the position of the current pixel was all i really wanted to know though, but thanks for an in depth answer. My pixel shader ended up like this:

[code]float4 _3D_PS(VS_OUTPUT input) : SV_TARGET
{
float4 LeftEye = LeftEyeTexture.Sample( TexSamplerState, input.TexCoord );
float4 RightEye = RightEyeTexture.Sample( TexSamplerState, input.TexCoord );

int tempIntX = input.Pos.x % 2;
int tempIntY = input.Pos.y % 2;

if(tempIntX == 0)
{
if(tempIntY != 0)
{
return LeftEye;
}
}

return RightEye;
}[/code]
0

Share this post


Link to post
Share on other sites
[quote name='iedoc' timestamp='1330352992' post='4917002']
you could use a point samper to avoid the blending problem. But even with blending, i needed to make sure that every other pixel was exactly the other texture, with blending, i can't be sure that the blending operation will do that perfectly. I needed an operation that was very predictable if you know what i mean
[/quote]
Why not? Because of floating point inaccuracy?

[quote name='iedoc' timestamp='1330352992' post='4917002']
but this was actually a double post.
[/quote]
Oh, haven’t seen that. [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

[quote name='iedoc' timestamp='1330352992' post='4917002']
float4 LeftEye = LeftEyeTexture.Sample( TexSamplerState, input.TexCoord );
float4 RightEye = RightEyeTexture.Sample( TexSamplerState, input.TexCoord );
[/quote]
The load intrinsic is faster. [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

[CODE]uint tempIntX = (uint)(input.Pos.x) % 2u;
uint tempIntY = (uint)(input.Pos.y) % 2u;[/CODE]
Modulo on uints might be faster.

I’d rather place the two textures in a Texture2DArray. This way you only need to load from one texture, since you can dynamically index from which one to load.

Well, considering it again… In your case a stencil mask would be the best choice, I think, because you only need to shade the samples you use in the end. So you can avoid the second render target completely and don’t have to worry about the blending stuff. Besides you halve the pixel shader invocations, so the rendering should be faster, too. (Unless you need the pixels someplace else. [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img])

Cheers!
0

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  
Followers 0