   [DirectX 10/HLSL] Strange problem
  I have a function in my effect file that calculates the shadow factor in each pixel. If the effect file has this linefloat shadowFactor = cShadowFac(gShadowMap, in.projTexC);DirectX debug this lines:D3D10: WARNING: ID3D10Device::OMSetRenderTargets: Resource being set to OM DepthStencil is still bound on input! [ STATE_SETTING WARNING #9: DEVICE_OMSETRENDERTARGETS_HAZARD ]D3D10: WARNING: ID3D10Device::OMSetRenderTargets: Forcing PS shader resource slot 3 to NULL. [ STATE_SETTING WARNING #7: DEVICE_PSSETSHADERRESOURCES_HAZARD ]But if I cheat that line to look like this:float shadowFactor = 1.0f;DirectX dont debug any error.So I think the problem isnt really in the OMSetRenderTargets function but in cShadowFac() HLSL function.This is the cShadowFac() implementation:static const float SHADOW_EPSILON = 0.001f;static const float SMAP_SIZE = 4096.0f;static const float SMAP_DX = 1.0f / SMAP_SIZE;SamplerState gShadowSam{Filter = MIN_MAG_MIP_POINT;AddressU = Clamp;AddressV = Clamp;};float CalcShadowFactor(Texture2D gShadowMap, float4 projTexC){// Complete projection by doing division by w.projTexC.xyz /= projTexC.w;// Points outside the light volume are in shadow.if( projTexC.x < -1.0f || projTexC.x > 1.0f ||projTexC.y < -1.0f || projTexC.y > 1.0f ||    projTexC.z < 0.0f )    return 0.0f;    // Transform from NDC space to texture space.projTexC.x = +0.5f*projTexC.x + 0.5f;projTexC.y = -0.5f*projTexC.y + 0.5f;// Depth in NDC space.float depth = projTexC.z;// Sample shadow map to get nearest depth to light.float s0 = gShadowMap.Sample(gShadowSam, projTexC.xy).r;float s1 = gShadowMap.Sample(gShadowSam, projTexC.xy + float2(SMAP_DX, 0)).r;float s2 = gShadowMap.Sample(gShadowSam, projTexC.xy + float2(0, SMAP_DX)).r;float s3 = gShadowMap.Sample(gShadowSam, projTexC.xy + float2(SMAP_DX, SMAP_DX)).r;// Is the pixel depth <= shadow map value?float result0 = depth <= s0 + SHADOW_EPSILON;float result1 = depth <= s1 + SHADOW_EPSILON;float result2 = depth <= s2 + SHADOW_EPSILON;float result3 = depth <= s3 + SHADOW_EPSILON;// Transform to texel space.float2 texelPos = SMAP_SIZE*projTexC.xy;// Determine the interpolation amounts.float2 t = frac( texelPos );// Interpolate results.return lerp( lerp(result0, result1, t.x),    lerp(result2, result3, t.x), t.y);}
  Resources cannot be bound to the pipeline for reading and writing at the same time.  The warning message indicate that the d3druntime is taking a stab at trying to fix the problem by unbinding the resource from the pixel shader for reading.  (this way it will be available for the OM DepthStencil for writing).You'll can't read from the depth surface while it's collecting data so you'll have to approach your algorithm differently.  One way to do this is to have a simple depth pass in order to create a readable resource for the info you want, and then rendering the scene a second time to use the depth info.   ;Quote:Original post by DieterVWOne way to do this is to have a simple depth pass in order to create a readable resource for the info you want, and then rendering the scene a second time to use the depth info.I'm already doing that...Ive an effect to create the shadow map and another to render the shadow map in the geometry.;  You may intend to do that, but the D3D runtime doesn't think that you have it set correctly, or at least that you're not unbinding the resource from the previous usage.  The sdk layers doesn't lie.Can you paste your entire fx file?  We need to see if you're setting render targets and depth targets in effects or in the runtime.We may also need to see some runtime code on how you wired up the objects, views, and effects resources.   ;  I think we're still missing the code that calls OMSetRenderTargets().Next, I don't think that setting an effect variable actually changes the pipeline until you call Aplly();  If I'm right, it's because Effects wants to minimize DX API calls, so it tries to set several resources at the same time instead of just one at at time by caching changes and submitting them only when necessary. (mFxShadowMapVar->SetResource(NULL);You can actually verify this.Create two arrays for sharer resource handles.  Then call device->PSGetShaderResources() before and after setting the resource to NULL and see if the corresponding handle becomes NULL in the array.Don't forget to release all of these handles once your done.   ;Quote:Original post by DieterVWNext, I don't think that setting an effect variable actually changes the pipeline until you call Aplly();You were right. :DI added these lines after rendering the scene:mFxShadowMapVar->SetResource(NULL);mTech->GetPassByIndex(0)->Apply(0); 