• 9
• 13
• 18
• 19
• 27
• Similar Content

• By cozzie
Hi all,
As a part of the debug drawing system in my engine,  I want to add support for rendering simple text on screen  (aka HUD/ HUD style). From what I've read there are a few options, in short:
1. Write your own font sprite renderer
2. Using Direct2D/Directwrite, combine with DX11 rendertarget/ backbuffer
3. Use an external library, like the directx toolkit etc.
I want to go for number 2, but articles/ documentation confused me a bit. Some say you need to create a DX10 device, to be able to do this, because it doesn't directly work with the DX11 device.  But other articles tell that this was 'patched' later on and should work now.
Can someone shed some light on this and ideally provide me an example or article on  how to set this up?
All input is appreciated.
• By stale
I've just started learning about tessellation from Frank Luna's DX11 book. I'm getting some very weird behavior when I try to render a tessellated quad patch if I also render a mesh in the same frame. The tessellated quad patch renders just fine if it's the only thing I'm rendering. This is pictured below:
'
However, when I attempt to render the same tessellated quad patch along with the other entities in the scene (which are simple triangle-lists), I get the following error:

I have no idea why this is happening, and google searches have given me no leads at all. I use the following code to render the tessellated quad patch:
for (unsigned int i = 0; i < scene->GetEntityList()->size(); i++) { Entity* entity = scene->GetEntityList()->at(i); if (entity->m_VisualComponent->m_visualType == VisualType::MESH) DrawMeshEntity(entity, cam, sun, point); else if (entity->m_VisualComponent->m_visualType == VisualType::BILLBOARD) DrawBillboardEntity(entity, cam, sun, point); else if (entity->m_VisualComponent->m_visualType == VisualType::TERRAIN) DrawTerrainEntity(entity, cam); } HR(m_swapChain->Present(0, 0)); Any help/advice would be much appreciated!

• Am trying a basebones tessellation shader and getting unexpected result when increasing the tessellation factor. Am rendering a group of quads and trying to apply tessellation to them.
OutsideTess = (1,1,1,1), InsideTess= (1,1)

OutsideTess = (1,1,1,1), InsideTess= (2,1)

I expected 4 triangles in the quad, not two. Any idea of whats wrong?
Structs:
struct PatchTess { float mEdgeTess[4] : SV_TessFactor; float mInsideTess[2] : SV_InsideTessFactor; }; struct VertexOut { float4 mWorldPosition : POSITION; float mTessFactor : TESS; }; struct DomainOut { float4 mWorldPosition : SV_POSITION; }; struct HullOut { float4 mWorldPosition : POSITION; }; Hull shader:
PatchTess PatchHS(InputPatch<VertexOut, 3> inputVertices) { PatchTess patch; patch.mEdgeTess[ 0 ] = 1; patch.mEdgeTess[ 1 ] = 1; patch.mEdgeTess[ 2 ] = 1; patch.mEdgeTess[ 3 ] = 1; patch.mInsideTess[ 0 ] = 2; patch.mInsideTess[ 1 ] = 1; return patch; } [domain("quad")] [partitioning("fractional_odd")] [outputtopology("triangle_ccw")] [outputcontrolpoints(4)] [patchconstantfunc("PatchHS")] [maxtessfactor( 64.0 )] HullOut hull_main(InputPatch<VertexOut, 3> verticeData, uint index : SV_OutputControlPointID) { HullOut ret; ret.mWorldPosition = verticeData[index].mWorldPosition; return ret; }
[domain("quad")] DomainOut domain_main(PatchTess patchTess, float2 uv : SV_DomainLocation, const OutputPatch<HullOut, 4> quad) { DomainOut ret; const float MipInterval = 20.0f; ret.mWorldPosition.xz = quad[ 0 ].mWorldPosition.xz * ( 1.0f - uv.x ) * ( 1.0f - uv.y ) + quad[ 1 ].mWorldPosition.xz * uv.x * ( 1.0f - uv.y ) + quad[ 2 ].mWorldPosition.xz * ( 1.0f - uv.x ) * uv.y + quad[ 3 ].mWorldPosition.xz * uv.x * uv.y ; ret.mWorldPosition.y = quad[ 0 ].mWorldPosition.y; ret.mWorldPosition.w = 1; ret.mWorldPosition = mul( gFrameViewProj, ret.mWorldPosition ); return ret; }
Any ideas what could be wrong with these shaders?
• By simco50
Hello,
I've stumbled upon Urho3D engine and found that it has a really nice and easy to read code structure.
I think the graphics abstraction looks really interesting and I like the idea of how it defers pipeline state changes until just before the draw call to resolve redundant state changes.
This is done by saving the state changes (blendEnabled/SRV changes/RTV changes) in member variables and just before the draw, apply the actual state changes using the graphics context.
It looks something like this (pseudo):
void PrepareDraw() { if(renderTargetsDirty) { pD3D11DeviceContext->OMSetRenderTarget(mCurrentRenderTargets); renderTargetsDirty = false } if(texturesDirty) { pD3D11DeviceContext->PSSetShaderResourceView(..., mCurrentSRVs); texturesDirty = false } .... //Some more state changes } This all looked like a great design at first but I've found that there is one big issue with this which I don't really understand how it is solved in their case and how I would tackle it.
I'll explain it by example, imagine I have two rendertargets: my backbuffer RT and an offscreen RT.
Say I want to render my backbuffer to the offscreen RT and then back to the backbuffer (Just for the sake of the example).
You would do something like this:
//Render to the offscreen RT pGraphics->SetRenderTarget(pOffscreenRT->GetRTV()); pGraphics->SetTexture(diffuseSlot, pDefaultRT->GetSRV()) pGraphics->DrawQuad() pGraphics->SetTexture(diffuseSlot, nullptr); //Remove the default RT from input //Render to the default (screen) RT pGraphics->SetRenderTarget(nullptr); //Default RT pGraphics->SetTexture(diffuseSlot, pOffscreenRT->GetSRV()) pGraphics->DrawQuad(); The problem here is that the second time the application loop comes around, the offscreen rendertarget is still bound as input ShaderResourceView when it gets set as a RenderTargetView because in Urho3D, the state of the RenderTargetView will always be changed before the ShaderResourceViews (see top code snippet) even when I set the SRV to nullptr before using it as a RTV like above causing errors because a resource can't be bound to both input and rendertarget.
What is usually the solution to this?

Thanks!
• By MehdiUBP
Hello,
I wrote a MatCap shader following this idea:
Given the image representing the texture, we compute the sample point by taking the dot product of the vertex normal and the camera position and remapping this to [0,1].
This seems to work well when I look straight at an object with this shader. However, in cases where the camera points slightly on the side, I can see the texture stretch a lot.
Could anyone give me a hint as how to get a nice matcap shader ?
Here's what I wrote:

{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
}
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog work

#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float3 normal : NORMAL;
};
struct v2f
{
float2 worldNormal : TEXCOORD0;
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.worldNormal = mul((float3x3)UNITY_MATRIX_V, UnityObjectToWorldNormal(v.normal)).xy*0.3 + 0.5;  //UnityObjectToClipPos(v.normal)*0.5 + 0.5;
return o;
}

fixed4 frag (v2f i) : SV_Target
{
// sample the texture
fixed4 col = tex2D(_MainTex, i.worldNormal);
// apply fog
return col;
}
ENDCG
}
}
}

Thanks!

DX11 DXGI_FORMAT_R8_UNORM for luminance gives me only red channel

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

Recommended Posts

Hi...
I am trying to load a texture with the DXGI_FORMAT_R8_UNORM to obtain its luminance version(grayScale), in D3D9 i was used D3DFMT_L8 and the result is okay but in D3D11 i only obtain the red channel, what i am doing wrong?

Rendered Color image:

here is the code:

	D3DX11_IMAGE_INFO* pImgInfo = 0;
HRESULT imghr = D3DX11GetImageInfoFromFile( L"Tiles.png", NULL, pImgInfo, NULL);

m_Texture = m_pRenderer11->LoadTexture( L"Tiles.png", &imgLoadInfo  );

Share on other sites

R8_UNORM means you have a texture with just a red channel. If you load an RGB texture with that format, you will only get the red channel from that texture. If you want a texture containing the luminance of the RGB values, you'll need to do that yourself.

Share on other sites
R8_UNORM means you have a texture with just a red channel. If you load an RGB texture with that format, you will only get the red channel from that texture. If you want a texture containing the luminance of the RGB values, you'll need to do that yourself.

Is there no a way like in D3D9 with the format  D3DFMT_L8? when i used these forma to load a texture it visually return a gray scale version

Share on other sites

Use the R value from your DXGI_FORMAT_R8_UNORM texture for all channels of the returned color except for A, which should be set to 1.0f.

L. Spiro

Share on other sites
Use the R value from your DXGI_FORMAT_R8_UNORM texture for all channels of the returned color except for A, which should be set to 1.0f.

L. Spiro

i'm so sorry L.Spiro, i'm a beginner in d3d11, may you be more specific? When i call LoadTexture how can i set the channels as you said?

Share on other sites

As noted in the documentation, you can replicate the D3D9 behavior by using .r to swizzle the data in the shader.

So something like this:

float4 color = float4(textureColor.rrr, 1.0f);

Share on other sites

Now i have errors with the texture sampler, it is only happening with the R8_unorm format.

Here is the result:

And here is the source image:

// Pixel Shader
float4 main_ps( v2p input ) : SV_TARGET
{
float4 l_color0;
l_color0 = g_frostTexture.Sample(SampleType, input.texCoord);
l_color1 = float4( l_color1.rrr, 1.0f);
returnl_color1;
}

Share on other sites

I don’t use Ogre but the error seems apparent: The image is now 4 times as wide and the RGB channels are all the same (so every 3 pixels are grey) and the A channel is white (so every 4th pixel is white).

In other words, something is expecting 1 result but is being fed 4.  For whatever reason it is actually using all 4 results and treating them as separate results.  Instead of combining the RGBA values into one pixel, it is spreading them out over 4 pixels.

That is basically the problem, but I have never seen this and I am not familiar with Ogre, so I can’t tell you where to look.  The first things I would check would be the texture-creation values and the render-target creation values.

L. Spiro