Sign in to follow this  
pulo

DX11 DirectX Render to Texture problem

Recommended Posts

pulo    276
i was trying to render to a texture to use it for post-processing. I've read a lot of tutorials about this stuff und have tried it for myself now, but apparently i am doing something wrong.
So first of all these are the error message im getting over and over:

[CODE]
D3D11: ERROR: ID3D11DeviceContext::OMSetRenderTargets: The RenderTargetView at slot 0 is not compatable with the DepthStencilView. DepthStencilViews may only be used with RenderTargetViews if the effective dimensions of the Views are equal, as well as the Resource types, multisample count, and multisample quality. The RenderTargetView at slot 0 has (w:400,h:300,as:1), while the Resource is a Texture2D with (mc:1,mq:0). The DepthStencilView has (w:1280,h:720,as:1), while the Resource is a Texture2D with (mc:1,mq:0). D3D11_RESOURCE_MISC_TEXTURECUBE factors into the Resource type, unless GetFeatureLevel() returns D3D_FEATURE_LEVEL_10_1 or greater. [ STATE_SETTING ERROR #388: OMSETRENDERTARGETS_INVALIDVIEW ]
D3D11: ERROR: ID3D11DeviceContext::Draw: Rasterization Unit is enabled (PixelShader is not NULL or Depth/Stencil test is enabled and RasterizedStream is not D3D11_SO_NO_RASTERIZED_STREAM) but position is not provided by the last shader before the Rasterization Unit. [ EXECUTION ERROR #362: DEVICE_DRAW_POSITION_NOT_PRESENT ][/CODE]

And:

[CODE]
D3D11: ERROR: ID3D11DeviceContext::Draw: Vertex Shader - Geometry Shader linkage error: Signatures between stages are incompatible. The input stage requires Semantic/Index (RADIUS,0) as input, but it is not provided by the output stage. [ EXECUTION ERROR #342: DEVICE_SHADER_LINKAGE_SEMANTICNAME_NOT_FOUND ]
D3D11: ERROR: ID3D11DeviceContext::Draw: Vertex Shader - Geometry Shader linkage error: Signatures between stages are incompatible. The input stage requires Semantic/Index (TEXTUREINDEX,0) as input, but it is not provided by the output stage. [ EXECUTION ERROR #342: DEVICE_SHADER_LINKAGE_SEMANTICNAME_NOT_FOUND ]
D3D11: ERROR: ID3D11DeviceContext::Draw: Geometry Shader - Pixel Shader linkage error: Signatures between stages are incompatible. The input stage requires Semantic/Index (POSITION,0) as input, but it is not provided by the output stage. [ EXECUTION ERROR #342: DEVICE_SHADER_LINKAGE_SEMANTICNAME_NOT_FOUND ]
D3D11: ERROR: ID3D11DeviceContext::OMSetRenderTargets: The RenderTargetView at slot 0 is not compatable with the DepthStencilView. DepthStencilViews may only be used with RenderTargetViews if the effective dimensions of the Views are equal, as well as the Resource types, multisample count, and multisample quality. The RenderTargetView at slot 0 has (w:400,h:300,as:1), while the Resource is a Texture2D with (mc:1,mq:0). The DepthStencilView has (w:1280,h:720,as:1), while the Resource is a Texture2D with (mc:1,mq:0). D3D11_RESOURCE_MISC_TEXTURECUBE factors into the Resource type, unless GetFeatureLevel() returns D3D_FEATURE_LEVEL_10_1 or greater. [ STATE_SETTING ERROR #388: OMSETRENDERTARGETS_INVALIDVIEW ][/CODE]

I am pretty sure that i am misunterstanding a major aspect of this rendertarget switching and stuff.
When my DirectX Device is created i am also creating this:

[CODE] D3D11_TEXTURE2D_DESC textureDesc;
D3D11_RENDER_TARGET_VIEW_DESC renderTargetViewDesc;
D3D11_SHADER_RESOURCE_VIEW_DESC shaderResourceViewDesc;

ZeroMemory(&textureDesc, sizeof(textureDesc));

textureDesc.Width = 800/2;
textureDesc.Height = 600/2;
textureDesc.MipLevels = 1;
textureDesc.ArraySize = 1;
textureDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
textureDesc.SampleDesc.Count = 1;
textureDesc.Usage = D3D11_USAGE_DEFAULT;
textureDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
textureDesc.CPUAccessFlags = 0;
textureDesc.MiscFlags = 0;


pDevice->CreateTexture2D(&textureDesc, NULL, &renderTargetTextureMap);

renderTargetViewDesc.Format = textureDesc.Format;
renderTargetViewDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
renderTargetViewDesc.Texture2D.MipSlice = 0;

.
pDevice->CreateRenderTargetView(renderTargetTextureMap, &renderTargetViewDesc, &renderTargetViewMap);

shaderResourceViewDesc.Format = textureDesc.Format;
shaderResourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
shaderResourceViewDesc.Texture2D.MostDetailedMip = 0;
shaderResourceViewDesc.Texture2D.MipLevels = 1;

pDevice->CreateShaderResourceView(renderTargetTextureMap, &shaderResourceViewDesc, &shaderResourceViewMap);

D3DVERTEX quad[4] = {
{D3DXVECTOR3(0,0,0), D3DXVECTOR2(0,0)},
{D3DXVECTOR3(1,1,0), D3DXVECTOR2(1,1)},
{D3DXVECTOR3(1,0,0), D3DXVECTOR2(1,0)},
{D3DXVECTOR3(0,1,0), D3DXVECTOR2(0,1)}};

HRESULT hr;

D3D11_SUBRESOURCE_DATA InitData;
InitData.pSysMem = &quad[0];
InitData.SysMemPitch = sizeof(D3DVERTEX);
InitData.SysMemSlicePitch = 0;

D3D11_BUFFER_DESC bufferDesc;
bufferDesc.Usage = D3D11_USAGE_DEFAULT;
bufferDesc.ByteWidth = 4 * InitData.SysMemPitch;
bufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
bufferDesc.CPUAccessFlags = 0;
bufferDesc.MiscFlags = 0;

V_RETURN(pDevice->CreateBuffer( &bufferDesc, &InitData, &m_pVertexBuffer ));

const D3D11_INPUT_ELEMENT_DESC layout[] =
{
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
};
UINT numElements = sizeof( layout ) / sizeof( layout[0] );
D3DX11_PASS_DESC passDesc;
m_pEffect->GetTechniqueByName("Render")->GetPassByName("P0_PP")->GetDesc(&passDesc);

V_RETURN( pDevice->CreateInputLayout( layout, numElements, passDesc.pIAInputSignature,
passDesc.IAInputSignatureSize, &m_pInputLayout ) ); [/CODE]

So i am creating a ShaderResourceView and a RenderTargetView aswell as a cube with a vertex buffer to draw this cube where the texture will be drawn on.

Now in every frame update after ALL the other stuff was drawn im using this:


[CODE] pDevice->GetImmediateContext(&pd3dImmediateContext);
pd3dImmediateContext->OMSetRenderTargets( 1, &renderTargetViewMap, pDSV );

pd3dImmediateContext->ClearRenderTargetView(renderTargetViewMap, g_ClearColor);
ID3D11Buffer* vbs[] = { m_pVertexBuffer, };
unsigned int strides[] = { sizeof(D3DVERTEX), }, offsets[] = { 0, };

pd3dImmediateContext->IASetVertexBuffers(0,1, vbs, strides, offsets);
pd3dImmediateContext->IASetInputLayout(m_pInputLayout);
pd3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);

//TODO: Move to header file.
ID3DX11EffectShaderResourceVariable* g_SpriteEV;

g_SpriteEV = m_pEffect->GetVariableByName("g_PostProcessTex")->AsShaderResource();

g_SpriteEV->SetResource(shaderResourceViewMap);
m_pEffect->GetTechniqueByName("Render")->GetPassByName("P0_PP")->Apply(0, pd3dImmediateContext);

pd3dImmediateContext->Draw(4, 0); [/CODE]

I have not explicitly created a depthStencilView which i would guess is my main error here. But i have no idea how to create something like this right.
I am pretty much confused about how this all is working in the background...maybe someone cares to explain this.
Am i doing anything right here or is this just wrong? [img]http://public.gamedev.net//public/style_emoticons/default/tongue.png[/img]

Thanks for anyone who cares to help.

Share this post


Link to post
Share on other sites
Martin Perry    1553
I see several problems with posted snipsets.
1) If you render to texture, that is smaller than your standard render target, you must change viewport to texture dimensions. (maybe last error is due to this)
2) Before you render to texture, save your targets. After you render to texture, dont forget to unbind render targets from device and restore original ones (aka. classic "screen")
3) If you render "classic way" to the screen, can you see some errors ? Because errors with shaders are not render-to-texture relevant. In DX11 rendering geometry to texture is exactly the same as classic rendering, except for render targets changes.

Do you know this tutorial: [url="http://www.rastertek.com/dx11tut22.html"]http://www.rastertek.com/dx11tut22.html[/url]
It´s a good start and my renderer to texture is based on it. Everything works correctly.

Share this post


Link to post
Share on other sites
pulo    276
Hey, thanks for your advices.
I've reworked my whole Render to Texture process based on this tutorial and it gives me no errors and it seems like that i can work with the texture.
The only problem left now ist, that it seems like i cannot draw a simple square to draw my texture on anymore. This is how it looks like at the moment (with a black/ white shader):
[url="http://imgur.com/HrKXR"]http://imgur.com/HrKXR[/url]

this is the code AFTER RenderToTexture() and RenderScene():


[CODE]

Vertex v[] =
{
Vertex( -0.5f, -0.5f, 0.5f, 1.0f, 0.0f, 0.0f, 1.0f ),
Vertex( -0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 1.0f ),
Vertex( 0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f ),
Vertex( 0.5f, -0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 1.0f ),
};

DWORD indices[] = {
0, 1, 2,
0, 2, 3,
};

HRESULT hr;

D3D11_BUFFER_DESC indexBufferDesc;
ZeroMemory( &indexBufferDesc, sizeof(indexBufferDesc) );

indexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
indexBufferDesc.ByteWidth = sizeof(DWORD) * 2 * 3;
indexBufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
indexBufferDesc.CPUAccessFlags = 0;
indexBufferDesc.MiscFlags = 0;

D3D11_SUBRESOURCE_DATA iinitData;

iinitData.pSysMem = indices;
pDevice->CreateBuffer(&indexBufferDesc, &iinitData, &m_pIndexBuffer);

// Fill in the subresource data.
D3D11_SUBRESOURCE_DATA InitData;
InitData.pSysMem = &v[0];
InitData.SysMemPitch = sizeof(Vertex);
InitData.SysMemSlicePitch = 0;

D3D11_BUFFER_DESC bufferDesc;
bufferDesc.Usage = D3D11_USAGE_DEFAULT;
bufferDesc.ByteWidth = 4 * InitData.SysMemPitch;
bufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
bufferDesc.CPUAccessFlags = 0;
bufferDesc.MiscFlags = 0;

V_RETURN(pDevice->CreateBuffer( &bufferDesc, &InitData, &m_pVertexBuffer ));

const D3D11_INPUT_ELEMENT_DESC layout[] = // http://msdn.microsoft.com/en-us/library/bb205117%28v=vs.85%29.aspx
{
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
//{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
};
UINT numElements = sizeof( layout ) / sizeof( layout[0] );
D3DX11_PASS_DESC passDesc;
m_pEffect->GetTechniqueByName("Render")->GetPassByName("P0_PP")->GetDesc(&passDesc);

V_RETURN( pDevice->CreateInputLayout( layout, numElements, passDesc.pIAInputSignature,
passDesc.IAInputSignatureSize, &m_pInputLayout ) );


ID3D11Buffer* vbs[] = { m_pVertexBuffer, };
unsigned int strides[] = { sizeof(D3DVERTEX), }, offsets[] = { 0, };

pd3dImmediateContext->IASetVertexBuffers(0,1, vbs, strides, offsets);
pd3dImmediateContext->IASetIndexBuffer( m_pIndexBuffer, DXGI_FORMAT_R32_UINT, 0);
pd3dImmediateContext->IASetInputLayout(m_pInputLayout);
pd3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

//TODO: Move to header file.
ID3DX11EffectShaderResourceVariable* g_SpriteEV;

g_SpriteEV = m_pEffect->GetVariableByName("g_PostProcessTex")->AsShaderResource();

g_SpriteEV->SetResource(m_shaderResourceView);
m_pEffect->GetTechniqueByName("Render")->GetPassByName("P0_PP")->Apply(0, pd3dImmediateContext);

pd3dImmediateContext->DrawIndexed( 6, 0, 0 );

g_SpriteEV->SetResource(NULL);
m_pEffect->GetTechniqueByName("Render")->GetPassByName("P0_PP")->Apply(0, pd3dImmediateContext);
[/CODE]

If you want me to post all the code for the different render processes just let me know. Edited by pulo

Share this post


Link to post
Share on other sites
pulo    276
Okay...i found one of my problems..the stride of the vertex buffer was set to an "old" value.. Now i've set up the square with these values:

[CODE]
Vertex v[] =
{
Vertex( -1.f, -1.f, 0.f ),
Vertex( 1.f, -1.f, 0.f ),
Vertex( 1.f, 1.f, 0.f ),
Vertex( -1.f, 1.f, 0.f ),
};
DWORD indices[] = {
0, 1, 2,
0, 2, 3,
};
[/CODE]

But it produces this:

[url="http://imgur.com/EsmV3"]http://imgur.com/EsmV3[/url]

so basically it splits the whole thing in 4 parts. There are some things i've noticed aswell.
1. The Texture on the square seems to be exaclty mirrored (this could be fixed through the shader though)
2. The 4 tiles are not present at the beginning - i have to move my camera just a little bit then it appears.
3. Its disappearing in random intervals. Edited by pulo

Share this post


Link to post
Share on other sites
Martin Perry    1553
Do you have correct TEXCOORDs ? Also try to turn off DepthBuffer and DepthWrites.

I am setting my full screen quad this way:
[CODE]
float startX = -1;
float startY = -1;
float endX = 1;
float endY = 1;

MyMath::Vector3 vecA = MyMath::Vector3(startX, startY, 0);
MyMath::Vector3 vecB = MyMath::Vector3(endX , startY, 0);
MyMath::Vector3 vecC = MyMath::Vector3(startX, endY, 0);
MyMath::Vector3 vecD = MyMath::Vector3(endX , endY, 0);

std::vector<QuadVertex> pos;
QuadVertex a = {vecA.X, vecA.Y, vecA.Z, 0, 1, 0};
QuadVertex b = {vecB.X, vecB.Y, vecB.Z, 1, 1, 1};
QuadVertex c = {vecC.X, vecC.Y, vecC.Z, 0, 0, 3};
QuadVertex d = {vecD.X, vecD.Y, vecD.Z, 1, 0, 2};

std::vector<short> ind;
ind.push_back(0); ind.push_back(1); ind.push_back(2);
ind.push_back(2); ind.push_back(1); ind.push_back(3);
[/CODE]

Share this post


Link to post
Share on other sites
pulo    276
Hey,

thanks for your help. I really appreciate it. Your hint with the TexCoords was a hit. I was using an old calculation for them. Now i can render the whole texture over my scene with a black and white shader. I have a few questions / problems left though:

1. I understand that for the coordinate system for rendering 0,0 is the center and -1,-1 is the lower left corner, isnt it? But what about the texture coordinates. If i understand the numbers correctly there 0,0 is the upper left corner? Why is there such a difference?
2. My shader seems not to be active at first startup , i have to move my camera a bit before it comes active.
3. The shader effect seems to disappear from time to time (random)

I have tried to disable the depth for the Stencil with something like this:

[CODE]
D3D11_DEPTH_STENCIL_DESC depthDisabledStencilDesc;
ID3D11DepthStencilState* m_depthDisabledStencilState;
depthDisabledStencilDesc.DepthEnable = false;
depthDisabledStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
depthDisabledStencilDesc.DepthFunc = D3D11_COMPARISON_LESS;
depthDisabledStencilDesc.StencilEnable = true;
depthDisabledStencilDesc.StencilReadMask = 0xFF;
depthDisabledStencilDesc.StencilWriteMask = 0xFF;
depthDisabledStencilDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
depthDisabledStencilDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR;
depthDisabledStencilDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
depthDisabledStencilDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
depthDisabledStencilDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
depthDisabledStencilDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR;
depthDisabledStencilDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
depthDisabledStencilDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
pd3dDevice->CreateDepthStencilState(&depthDisabledStencilDesc, &m_depthDisabledStencilState);
pd3dImmediateContext->OMSetDepthStencilState(m_depthDisabledStencilState, 1);


g_PostProcessing->RenderPostProcess(pd3dDevice, g_Camera, g_ClearColor);

depthDisabledStencilDesc.DepthEnable = true;
pd3dDevice->CreateDepthStencilState(&depthDisabledStencilDesc, &m_depthDisabledStencilState);
pd3dImmediateContext->OMSetDepthStencilState(m_depthDisabledStencilState, 1);
[/CODE]

The renderpostprocess call is rendering the quad with the texture on the screen after RenderToTexture() and RenderScene() was called.

Share this post


Link to post
Share on other sites
pulo    276
I was able to solve all the problems by just setting the DepthStencilState to DepthEnable = false in the shader file :)
Thanks for your help!

Share this post


Link to post
Share on other sites
pulo    276
Hello again,

now i have researched some stuff and there are some open questions in my mind which i hope some of you can answer me. I am now trying to downsample the rendered texture to the 4th of the original size. After that i want to use a bloom effect or something and (upsample?) it again to merge it with the original rendered scene.
Now my question is fairly simple: how can i let my original texture (full screen size) walk through some shader passes so at the end i will have a downsampled texture with effects and the original texture to work with?
i dont understand how to work with multiple passes. How do i pass the texture from one pass to another and at the end merge the original one with the edited one?
Thanks in advance

Share this post


Link to post
Share on other sites
mhagain    13430
You basically create two rendertargets. Size doesn't matter - they just need to be big enough for the largest (typically your screen dimensions).

So, in pass 1 you draw from target 0 to target 1 as a half-sized quad (the size of the quad doesn't have to be the same as your render target size).
In pass 2 you draw from 1 to 0 as a half-sized quad (halving again the half size from above).
Repeat until you get it down to the size you want, flipping the render targets each pass.

After the final pass you set back your default render target, then draw from the target set in the final pass to this.

[b]Edit[/b]: silly me, I forgot that with D3D11 you can autogen mipmaps from a render target. I've never used this, but it does present another option for you that may be faster. Edited by mhagain

Share this post


Link to post
Share on other sites
pulo    276
I think i understood this. But i cant really image how to draw from one target to another? is it a simple draw() call with a fullscreen quad textured by the texture i want to pass and the render target i want to use next?

Share this post


Link to post
Share on other sites
pulo    276
The only thing i dont understand is you i pass one texture from pass to pass. Is this a simple Draw() call with just the render target set, or is there a "better" way?

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  

  • Similar Content

    • By gsc
      Hi! I am trying to implement simple SSAO postprocess. The main source of my knowledge on this topic is that awesome tutorial.
      But unfortunately something doesn't work... And after a few long hours I need some help. Here is my hlsl shader:
      float3 randVec = _noise * 2.0f - 1.0f; // noise: vec: {[0;1], [0;1], 0} float3 tangent = normalize(randVec - normalVS * dot(randVec, normalVS)); float3 bitangent = cross(tangent, normalVS); float3x3 TBN = float3x3(tangent, bitangent, normalVS); float occlusion = 0.0; for (int i = 0; i < kernelSize; ++i) { float3 samplePos = samples[i].xyz; // samples: {[-1;1], [-1;1], [0;1]} samplePos = mul(samplePos, TBN); samplePos = positionVS.xyz + samplePos * ssaoRadius; float4 offset = float4(samplePos, 1.0f); offset = mul(offset, projectionMatrix); offset.xy /= offset.w; offset.y = -offset.y; offset.xy = offset.xy * 0.5f + 0.5f; float sampleDepth = tex_4.Sample(textureSampler, offset.xy).a; sampleDepth = vsPosFromDepth(sampleDepth, input.uv).z; const float threshold = 0.025f; float rangeCheck = abs(positionVS.z - sampleDepth) < ssaoRadius ? 1.0 : 0.0; occlusion += (sampleDepth <= samplePos.z + threshold ? 1.0 : 0.0) * rangeCheck; } occlusion = saturate(1 - (occlusion / kernelSize)); And current result: http://imgur.com/UX2X1fc
      I will really appreciate for any advice!
    • By isu diss
       I'm trying to code Rayleigh part of Nishita's model (Display Method of the Sky Color Taking into Account Multiple Scattering). I get black screen no colors. Can anyone find the issue for me?
       
      #define InnerRadius 6320000 #define OutterRadius 6420000 #define PI 3.141592653 #define Isteps 20 #define Ksteps 10 static float3 RayleighCoeffs = float3(6.55e-6, 1.73e-5, 2.30e-5); RWTexture2D<float4> SkyColors : register (u0); cbuffer CSCONSTANTBUF : register( b0 ) { float fHeight; float3 vSunDir; } float Density(float Height) { return exp(-Height/8340); } float RaySphereIntersection(float3 RayOrigin, float3 RayDirection, float3 SphereOrigin, float Radius) { float t1, t0; float3 L = SphereOrigin - RayOrigin; float tCA = dot(L, RayDirection); if (tCA < 0) return -1; float lenL = length(L); float D2 = (lenL*lenL) - (tCA*tCA); float Radius2 = (Radius*Radius); if (D2<=Radius2) { float tHC = sqrt(Radius2 - D2); t0 = tCA-tHC; t1 = tCA+tHC; } else return -1; return t1; } float RayleighPhaseFunction(float cosTheta) { return ((3/(16*PI))*(1+cosTheta*cosTheta)); } float OpticalDepth(float3 StartPosition, float3 EndPosition) { float3 Direction = normalize(EndPosition - StartPosition); float RayLength = RaySphereIntersection(StartPosition, Direction, float3(0, 0, 0), OutterRadius); float SampleLength = RayLength / Isteps; float3 tmpPos = StartPosition + 0.5 * SampleLength * Direction; float tmp; for (int i=0; i<Isteps; i++) { tmp += Density(length(tmpPos)-InnerRadius); tmpPos += SampleLength * Direction; } return tmp*SampleLength; } static float fExposure = -2; float3 HDR( float3 LDR) { return 1.0f - exp( fExposure * LDR ); } [numthreads(32, 32, 1)] //disptach 8, 8, 1 it's 256 by 256 image void ComputeSky(uint3 DTID : SV_DispatchThreadID) { float X = ((2 * DTID.x) / 255) - 1; float Y = 1 - ((2 * DTID.y) / 255); float r = sqrt(((X*X)+(Y*Y))); float Theta = r * (PI); float Phi = atan2(Y, X); static float3 Eye = float3(0, 10, 0); float ViewOD = 0, SunOD = 0, tmpDensity = 0; float3 Attenuation = 0, tmp = 0, Irgb = 0; //if (r<=1) { float3 ViewDir = normalize(float3(sin(Theta)*cos(Phi), cos(Theta),sin(Theta)*sin(Phi) )); float ViewRayLength = RaySphereIntersection(Eye, ViewDir, float3(0, 0, 0), OutterRadius); float SampleLength = ViewRayLength / Ksteps; //vSunDir = normalize(vSunDir); float cosTheta = dot(normalize(vSunDir), ViewDir); float3 tmpPos = Eye + 0.5 * SampleLength * ViewDir; for(int k=0; k<Ksteps; k++) { float SunRayLength = RaySphereIntersection(tmpPos, vSunDir, float3(0, 0, 0), OutterRadius); float3 TopAtmosphere = tmpPos + SunRayLength*vSunDir; ViewOD = OpticalDepth(Eye, tmpPos); SunOD = OpticalDepth(tmpPos, TopAtmosphere); tmpDensity = Density(length(tmpPos)-InnerRadius); Attenuation = exp(-RayleighCoeffs*(ViewOD+SunOD)); tmp += tmpDensity*Attenuation; tmpPos += SampleLength * ViewDir; } Irgb = RayleighCoeffs*RayleighPhaseFunction(cosTheta)*tmp*SampleLength; SkyColors[DTID.xy] = float4(Irgb, 1); } }  
    • By amadeus12
      I made my obj parser
      and It also calculate tagent space for normalmap.
      it seems calculation is wrong..
      any good suggestion for this?
      I can't upload my pics so I link my question.
      https://gamedev.stackexchange.com/questions/147199/how-to-debug-calculating-tangent-space
      and I uploaded my code here


      ObjLoader.cpp
      ObjLoader.h
    • By Alessandro Pozzer
      Hi guys, 

      I dont know if this is the right section, but I did not know where to post this. 
      I am implementing a day night cycle on my game engine and I was wondering if there was a nice way to interpolate properly between warm colors, such as orange (sunset) and dark blue (night) color. I am using HSL format.
      Thank  you.
    • By thefoxbard
      I am aiming to learn Windows Forms with the purpose of creating some game-related tools, but since I know absolutely nothing about Windows Forms yet, I wonder:
      Is it possible to render a Direct3D 11 viewport inside a Windows Form Application? I see a lot of game editors that have a region of the window reserved for displaying and manipulating a 3D or 2D scene. That's what I am aiming for.
      Otherwise, would you suggest another library to create a GUI for game-related tools?
       
      EDIT:
      I've found a tutorial here in gamedev that shows a solution:
      Though it's for D3D9, I'm not sure if it would work for D3D11?
       
  • Popular Now