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

Get DX10 Texture object from classic DX9 sampler

11 posts in this topic

Hi all

 

In DX10/11 the sampler and texture objects have been separated, whereas in DX9 there was only one object for both.

 

Meaning, the Sample() and Gather() functions in HLSL require an object of type Texture which I do not have with a "classic" DX9 sampler2D object.

 

So is there a way to access the Texture object of a DX9 sampler2D object when compiling against DX10 / ps_4_0 or ps_5_0?

 

I'm talking pure HLSL here, so please no hints in C++ or C#.

 

Thanks in advance.

Edited by Meltac
0

Share this post


Link to post
Share on other sites

I use macros that define how to sample and declare a texture that just defines differently per platform. Like so:

 

#ifdef DX11
	#define DEFINE_2D_TEXTURE(tex, regIndex) Texture2D tex##Texture : register(t##regIndex); \
			                         SamplerState tex##Sampler : register(s##regIndex)
	#define SAMPLE_TEXTURE_2D(tex, coord) tex##Texture.Sample(tex##Sampler, coord)
#else
	#define DEFINE_2D_TEXTURE(tex, regIndex) sampler tex##Sampler : register(s##regIndex)
	#define SAMPLE_TEXTURE_2D(tex, coord) tex2D(tex##Sampler, coord)
#endif

 

It does require you to #define your platform when you create your shader though.

0

Share this post


Link to post
Share on other sites

Thanks, but that's not what I'm after. I do not want to just use a different sampling method depending on platform. Instead I want to make use of the Sample() and especially of the Gather() function from within a HLSL pixel shader that has only direct access to DX9 sampler objects. So I need a way of getting a Texture object "out of" a DX9 sampler object in order to apply the Gather() function on it.

Edited by Meltac
0

Share this post


Link to post
Share on other sites

You can't use the legacy "sampler2D" type at all in SM4.0/SM5.0 shader code. You have to use the new "Texture2D" and "SamplerState" types.

1

Share this post


Link to post
Share on other sites

You can't use the legacy "sampler2D" type at all in SM4.0/SM5.0 shader code. You have to use the new "Texture2D" and "SamplerState" types.

 

Hmm, but why am I able to compile my "legacy" code against ps_5_0 then?

 

I had to change "half" to "float" and some tex2D calls to tex2Dlod as the compiler complained about that, but sampler2D works without any issues!

0

Share this post


Link to post
Share on other sites

Are you compiling your shaders with this (D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY), flag? If so they will compile. Look at the MSDN page for tex2dlod at the bottom of the page here.

0

Share this post


Link to post
Share on other sites

Are you compiling your shaders with this (D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY), flag? If so they will compile. Look at the MSDN page for tex2dlod at the bottom of the page here.

 

Ah, ok, that explains it. Thanks.

 

However, my initial question is still unanswered. I'm intending to use something like the Gather() function on a ps_5_0 target, but with legacy HLSL shader code. I don't get any Texture object from the host application, which I would need to call Gather() on it. All I have is a legacy "sampler2D" object.

 

Is there a way to use something like Gather() in this scenario in order to benefit from the hardware multi-sampling feature of DX10/11? E.g. Create a Texture object out of my HLSL shader code, which in turn makes calls to my samper2D when queried? Or some specific function call that works on sampler2D objects but in fact returns a mutli-sample like the Gather() method?

Edited by Meltac
0

Share this post


Link to post
Share on other sites

You'll have to manually gather the texels you want.

So your code would find the width and height of a texel:

 

float texelWidth = 1.0f/textureWidth;
float texelHeight = 1.0f/textureHeight;

 

Then you would manually sample the texture using texel width and height as an offset:

 

float4 color = 0;

float2 offsetUp = texCoords + float2( 0.0f, texelHeight );
float2 offsetDown = texCoords + float2( 0.0f, -texelHeight );
float2 offsetLeft = texCoords + float2( -texelWidth, 0.0f );
float2 offsetRight = texCoords + float2( texelWidth, 0.0f );

color += tex2D( tex, offsetUp );
color += tex2D( tex, offsetDown );
color += tex2D( tex, offsetLeft );
color += tex2D( tex, offsetRight );

color /= 4.0f;

 

This will sample the texture data in the cardinal directions of your input texcoord.
Note: This is just pseudo-code, I haven't tested this exact code, but the principle still stands.

0

Share this post


Link to post
Share on other sites

Yeah, but then I don't benefit from the hardware accelerated way of sampling four texels in just one procedure call like it's possible under DX10/11 using Gather().

 

My goal is improving runtime performance by the use of new hardware features of DX10/11, i.e. bring those improvements into my legacy DX9-like code (which compiles against Shader Model 5 and runs on a DX11 GPU). Is this not possible at all?

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