• 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
lomateron

read and write texture2D

14 posts in this topic

its simple, but i am not secure if my code is correct, this is what i have made.
the texture will be used on this way: each pixel is a vector.

What i need is a:
new Texture------the main thing
ShaderResouceView with an effectShaderResourceVariable---- to read it
RenderTargetView-------- to write to it

This are the variables used:
ID3D10Texture2D* VectorsBuffer;
ID3D10ShaderResourceView* g_pTexture2 = NULL;
ID3D10EffectShaderResourceVariable* g_pTx2 = NULL;
ID3D10RenderTargetView* g_pRenderTargetView2 = NULL;

AND THE CODE

[code]ID3D10Texture2D* VectorsBuffer;
D3D10_TEXTURE2D_DESC texD;
texD.Width = width;
texD.Height = height;
texD.MipLevels = 1;
texD.ArraySize = 1;
texD.Format = DXGI_FORMAT_R32G32B32_FLOAT;
texD.SampleDesc.Count = 1;
texD.SampleDesc.Quality = 0;
texD.Usage = D3D10_USAGE_DEFAULT;
texD.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
texD.CPUAccessFlags = 0;
texD.MiscFlags = 0;
hr = g_pd3dDevice->CreateTexture2D(&texD, 0, &VectorsBuffer);
if( FAILED( hr ) )
return hr;
hr = g_pd3dDevice->CreateRenderTargetView( VectorsBuffer, 0, &g_pRenderTargetView2 );
if( FAILED( hr ) )
return hr;
D3D10_SHADER_RESOURCE_VIEW_DESC srvD;
srvD.Format = DXGI_FORMAT_R32G32B32_FLOAT;
srvD.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
srvD.Texture2D.MipLevels = 1;
srvD.Texture2D.MostDetailedMip = 0;
hr = g_pd3dDevice->CreateShaderResourceView(VectorsBuffer,&srvD, &g_pTexture2);
if( FAILED( hr ) )
return hr;
g_pTx2 = g_pEffect->GetVariableByName( "TextureRW" )->AsShaderResource();
g_pTx2->SetResource( g_pTexture2 );[/code]

is it ok?
0

Share this post


Link to post
Share on other sites
I'm pretty sure you'll have to use
D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE
as Bind flags.

Without this CreateRenderTargetView() should fail.
0

Share this post


Link to post
Share on other sites
ohhh i thought i was missing something there, but apart from that do i need anything else.
0

Share this post


Link to post
Share on other sites
Why don't you just run the code with a directx debug device?
If something is wrong dx will most likely print error messages to the console explaining to you what you're doing wrong.
0

Share this post


Link to post
Share on other sites
Yeah use D3D10_CREATE_DEVICE_DEBUG when creating your device, and then check the debug output window for error messages.
0

Share this post


Link to post
Share on other sites
questions!
Can i put a texture in a hlsl texture variable to read it and put it in the render target of that same hlsl code at the same time?
I have already a texture in an hlsl variable now how do i get a pixel of that texture and put it in a float3 if the resolution of the texture is 800X600? or whatever resolution.
0

Share this post


Link to post
Share on other sites
please answer
for the second question can i do this inside the pixel shader method?
my texture is only RGB
[color=#000000]uint3 sampleCoord [/color][color=#666600]=[/color][color=#000000] uint3[/color][color=#666600]([/color][color=#000000]x[/color][color=#666600],[/color][color=#000000] y[/color][color=#666600],[/color][color=#000000] mipLevel[/color][color=#666600]);[/color]
[color=#000000] float3 sample [/color][color=#666600]=[/color][color=#000000] texture[/color][color=#666600].[/color][color=#660066]Load[/color][color=#666600]([/color][color=#000000]sampleCoord[/color][color=#666600]);[/color]
0

Share this post


Link to post
Share on other sites
[quote][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left]Can i put a texture in a hlsl texture variable to read it and put it in the render target of that same hlsl code at the same time?[/quote][/left][/size][/font][/color]
[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left]No, you cannot bind a resource as a render target and shader resource at the same time.[/left][/size][/font][/color]

[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left][quote][/left][/size][/font][/color][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left]I have already a texture in an hlsl variable now how do i get a pixel of that texture and put it in a float3 if the resolution of the texture is 800X600? or whatever resolution.[/quote][/left][/size][/font][/color]
What are you trying to do? That sounds like standard texture sampling to me.
Define a sampler state and use texture.sample() in dx10/dx11 or tex2d() in dx9.
There are other methods to get get pixels from specific mip levels or directly read specific samples from multisampled textures.
[url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb509700(v=vs.85).aspx"]http://msdn.microsoft.com/en-us/library/windows/desktop/bb509700(v=vs.85).aspx[/url]
0

Share this post


Link to post
Share on other sites
i am using the texture as a place to put vectors where each pixel is a 3D vector, so then i want to make calculations with the vectors i have,
HOW DO I GET A PIXEL? i have the

Texture2D Vectors;

then inside the pixel shader metod i put this code to GET A PIXEL, can i?(this is my first question now)

[color=#000000]uint3 sampleCoord [/color][color=#666600]=[/color][color=#000000] uint3[/color][color=#666600]([/color][color=#000000]x[/color][color=#666600],[/color][color=#000000] y[/color][color=#666600],[/color][color=#000000] 1[/color][color=#666600]);[/color]
[color=#000000]float3 sample [/color][color=#666600]=[/color][color=#000000] [/color]Vectors[color=#666600].[/color][color=#660066]Load[/color][color=#666600]([/color][color=#000000]sampleCoord[/color][color=#666600]);[/color]
so "sample" is the pixel at the (x, y) coordinate(is it?)

If that's true then i can continue and now i wanna modify the vectors depending on the calculations, how do i do that? writing them to another texture, yeah a render target texture.
Now in the .fx file what's the code to write a vector that is float3([color=#000000]float3 sample[/color]) into a pixel of the render target texture? the return value of the pixel shader method is the one that will be in a pixel of the render target texture, isnt it? then if for example my (Texture2D Vectors;) has only 3 pixels then, how do i run across those 3 pixels so i modify the 3 pixels? thats my second question because i am stuck there, the pixel shader method runs when.....?
0

Share this post


Link to post
Share on other sites
Yes, you can sample individual pixels like that.

A common way to modify texture data is to just run a fullscreen pass. (render a screenspace quad covering the whole screen)
This way every iteration of the pixelshader will match 1 pixel from the texture.
You can use texture coordinates from the fullscreen quad to sample the texture.

You'll have to bind another texture with the same dimensions to write to, as you cannot write to the texture you're currently reading.
You write to it by returning a value from the pixel shader.
If you need to perform multiple operations on the texture, you can ping pong between 2 textures of the same dimension.
0

Share this post


Link to post
Share on other sites
NOW I SEE. I remembered that the SDK tutorial 3 existed, a simple yellow triangle is drawn. I discovered that the pixel shader runs depending on the PrimitiveTopology and the vertex shader position. With only one point in the vertex buffer and the primitive tipology set to point list, the point position will be transformed into a pixel position of the back buffer texture, using the viewport, so normally without world, view, projection matrices and depth things, if the point position is D3DXVECTOR3( 1.0f, 1.0f, 0.0f ), the pixel in the upper right corner will be the one processed by the pixel shader method(the z value in the point never matters here). With 2 points in the vertex buffer one in the upper left corner D3DXVECTOR3( -1.0f, 1.0f, 0.0f ) and the other in the upper right corner D3DXVECTOR3( 1.0f, 1.0f, 0.0f ) and the PrimitiveTopology set to line strip, the pixel shader method will run across all the pixels between thos point(and logically in the point position too), yeahhhhh, now maybe you think that was simple, yesss it is, but if you understand it, that will take your knowledge of directx to a next LEVEL!! MOAHAHAHAHAHAHAHAHA
Now the problem is solved, bye.
0

Share this post


Link to post
Share on other sites
I have succeed, very fast without any problem, but one last question, having this:

Texture2D Vectors;
[color=#000000]uint3 sampleCoord [/color][color=#666600]=[/color][color=#000000] uint3[/color][color=#666600]([/color][color=#000000]x[/color][color=#666600],[/color][color=#000000] y[/color][color=#666600],[/color][color=#000000] 1[/color][color=#666600]);[/color]
[color=#000000]float3 sample [/color][color=#666600]=[/color][color=#000000] [/color]Vectors[color=#666600].[/color][color=#660066]Load[/color][color=#666600]([/color][color=#000000]sampleCoord[/color][color=#666600]);[/color]

then if (x,y)=(0,0), do I get the pixel that is in the upper left corner of the texture?
lest say the image is 50x50 pixels, then if (x,y)=(50,50), that will be the down right corner pixel of the texture?
0

Share this post


Link to post
Share on other sites
Damm i was wrong when i say, 3 posts back , if the point position is D3DXVECTOR3( 1.0f, 1.0f, 0.0f ), the pixel in the upper right corner will be the one processed by the pixel shader method, that pixel isn't in the upper right corner, that pixel is out of view, i mean it is just a little bit more up-right, north-east, that's really bad, why did the creators of directx did it like that.
0

Share this post


Link to post
Share on other sites
hoo now i know how to fix that, just change the top left and right of the viewport.................. ohh no that dint fixed it, the pixel is never draw. what can i do :(
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