DX11 in Ogre 1.9 - HLSL texture access

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
Thillbucci
Gnoblar
Posts: 13
Joined: Thu Dec 10, 2009 12:15 pm
Location: Germany

DX11 in Ogre 1.9 - HLSL texture access

Post by Thillbucci »

Hi there,

I'm trying to access a 2D texture in my HLSL domain shader via the Load() function but even though I get no error message from DX11 shader compiler, the return value is always float4(0, 0, 0, 0).
That's how my HLSL code looks like:

Code: Select all

float4 color = Tex0.Load( int3( 1 , 1 , 0 ) );
If I'm using the exact same line of code in the Pixel Shader, it works fine and returns the suitable color value of the texture, but I need it in the domain shader.

So maybe I missed to configure something special in the material file?

Does anybody know about an ogre example where textures are used in the domain shader?
User avatar
robert_sasu
Google Summer of Code Student
Google Summer of Code Student
Posts: 237
Joined: Mon Apr 02, 2012 11:07 am
x 42

Re: DX11 in Ogre 1.9 - HLSL texture access

Post by robert_sasu »

It is a strange question. I have never used texture in a domain shader, nor tried it in Ogre3D. But there is a limitation from the part of DirectX 11 and hlsl.
http://msdn.microsoft.com/en-us/library ... s.85).aspx

Code: Select all

Minimum Shader Model
This function is supported in the following shader models.
vs_4_0	vs_4_11	ps_4_0	ps_4_11	gs_4_0	gs_4_11
Texturing in general is resolved by sampling in vertex shader, and calculating colors in pixel shader.
Google Summer of Code 2013 Student
Topic: "DirectX 11 & Tessellation samples"
Project links: Project thread, WIKI page, Code fork for the project
Mentor: Assaf Raman
User avatar
robert_sasu
Google Summer of Code Student
Google Summer of Code Student
Posts: 237
Joined: Mon Apr 02, 2012 11:07 am
x 42

Re: DX11 in Ogre 1.9 - HLSL texture access

Post by robert_sasu »

You can load the color from the texture via vertex shader, and pass it through the hull shader and after that the hull shader will pass to the domain shader :)
This should resolve your problem, if you really need the color of a pixel in the domain shader.
Google Summer of Code 2013 Student
Topic: "DirectX 11 & Tessellation samples"
Project links: Project thread, WIKI page, Code fork for the project
Mentor: Assaf Raman
Thillbucci
Gnoblar
Posts: 13
Joined: Thu Dec 10, 2009 12:15 pm
Location: Germany

Re: DX11 in Ogre 1.9 - HLSL texture access

Post by Thillbucci »

Thank you for quick response :D

Actually I'm implementing something similar to the Nvidia "Fermi Hair Demo" (http://www.geforce.com/games-applicatio ... -hair-demo) and therefore it's absolutely necessary to access values (rather position information than colors) from buffers and textures in the domain shader.

But even for displacement, how could I ever move vertices generated by the tessellation stage based on a displacement texture? Isn't the domain shader designed for giving the new vertices their final position, based on additional information? And what would be the benefit of the tessellation engine when the shape of my geometry looks the same after tessellation like it did before (only subdivided)?

The Microsoft documentation of DX11 (shader model 5) says: "Texture2D type (as it exists in Shader Model 4) plus resource variables. This texture object supports the following methods in addition to the methods in Shader Model 4."
Further it's available for "Vertex-, Hull-, Domain-, Geometry-, Pixel- and Compute-Shader"

-> http://msdn.microsoft.com/en-us/library ... 85%29.aspx

I need to read information from buffers/textures within the domain shader based on the patch- and segment-IDs and it makes unfortunately no sense to me to provide all this data by the vertex shader (besides it would be too much data).

It sounds like you haven't ever tested this feature yet, but if it works for you or you see what the problem is, I would be very happy and thankful if you could share the information :)
User avatar
robert_sasu
Google Summer of Code Student
Google Summer of Code Student
Posts: 237
Joined: Mon Apr 02, 2012 11:07 am
x 42

Re: DX11 in Ogre 1.9 - HLSL texture access

Post by robert_sasu »

Yes, it is true that texture2D object can exist in every shader type, but you can't use the load method just in vertex, geometry or pixel shader.
Google Summer of Code 2013 Student
Topic: "DirectX 11 & Tessellation samples"
Project links: Project thread, WIKI page, Code fork for the project
Mentor: Assaf Raman
Thillbucci
Gnoblar
Posts: 13
Joined: Thu Dec 10, 2009 12:15 pm
Location: Germany

Re: DX11 in Ogre 1.9 - HLSL texture access

Post by Thillbucci »

It's not only the Microsoft shader model 5 documentation, that says the texture2D.Load() method should work in the domain shader (DS), it's even heavily used in some example shader implementations by Nvidia, like in the Hair Demo.

And what's the use of the texture2D object in the DS, when I can't use its methods? Is there another way to access texture data within the domain shader. Anything, that I've tried so far, wasn't successful...

Assumed I'm right and the Load() method should work in the DS, do you have any idea why it's return value is always (0,0,0,0) instead of the correct value from the texture? Is there anything to configure in the DX interface?
As I said in my first post, there is no shader compiler error or warning about the Load() function.
markusrapp
Gnoblar
Posts: 3
Joined: Tue May 06, 2014 4:46 pm

Re: DX11 in Ogre 1.9 - HLSL texture access

Post by markusrapp »

I had the same problem like Thillbucci. I needed to access textures in the domain shader. It is possible to assign textures to the domain shader and this function is also used for displacement mapping inside the domain shader after tessellation.

I added following lines of code to void D3D11RenderSystem::_render(const RenderOperation& op)

Code: Select all

if (mFeatureLevel >= D3D_FEATURE_LEVEL_11_0)
{
	mDevice.GetImmediateContext()->DSSetSamplers(static_cast<UINT>(0), static_cast<UINT>(opState->mSamplerStatesCount), opState->mSamplerStates);
	if (mDevice.isError())
	{
		String errorDescription = mDevice.getErrorDescription();
		OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, 
			"D3D11 device cannot set domain shader samplers\nError Description:" + errorDescription,
			"D3D11RenderSystem::_render");
	}

	mDevice.GetImmediateContext()->DSSetShaderResources(static_cast<UINT>(0), static_cast<UINT>(opState->mTexturesCount), &opState->mTextures[0]);
	if (mDevice.isError())
	{
		String errorDescription = mDevice.getErrorDescription();
		OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, 
			"D3D11 device cannot set domain shader resources\nError Description:" + errorDescription,
			"D3D11RenderSystem::_render");
	}
}
With that it works fine for me and I can access the value with the Load() function.
Is there a reason why you did not implement this functionality in the D3D11RenderSystem?
Post Reply