Missing Effect Parameters

Hey, I am having some trouble porting a few shaders over for a deferred renderer. In all of them with multiple Texture parameters 1-2 out of 3 are always missing, seemingly randomly which ones from shader to shader though they all compile without error. I understand that the MonoGame pipeline removes unused parameters, but all of these are used in the PixelShader in each shader. I’ve tried with both the stable release Pipeline.exe and one pulled from the latest commit with the same results.

In the case below of this DirectionalLight shader “colorMap” and “depthMap” are missing when the Effect is loaded in MonoGame however “normalMap” isn’t. If I check the XNBs I can see there is no string for the missing texture parameters but there is one for “normalMap”. As you can see in the pixel shader all of these are used and sampled and should not be optimized out. I tried a few things I could dig up such as using the macros (SAMPLE_TEXTURE, DECLARE_TEXTURE) which made no difference and I also tried declaring them the DX11 way of just declaring the textures and one individual sampler and all of them compiled but were missing the same “colorMap” and “depthMap” parameters.

I must either be completely missing something or is this a bug in the shader pipeline?

Edit: Figured out where colorMap is optimized out, which makes sense as I pull it for a specular value but don’t use it in this case. However depthMap is used to pull depthValue out which is then used as part of the lighting calculations leading to the output.

Edit 2: Solved the issue myself. I was missing that I hadn’t re-hooked any of the specular values back in so it was optimizing out the specular calculations which depthMap was used for.

 #if OPENGL
#define SV_POSITION POSITION
#define VS_SHADERMODEL vs_3_0
#define PS_SHADERMODEL ps_3_0
#else
#define VS_SHADERMODEL vs_4_0_level_9_1
#define PS_SHADERMODEL ps_4_0_level_9_1
#endif

//direction of the light
float3 lightDirection;
//color of the light 
float3 Color;
//position of the camera, for specular light
float3 cameraPosition;
//this is used to compute the world-position
float4x4 InvertViewProjection;

Texture2D normalMap;
Texture2D colorMap;
Texture2D depthMap;
// normals, and specularPower in the alpha channel
sampler normalSampler = sampler_state
{
	Texture = <normalMap>;
	AddressU = CLAMP;
	AddressV = CLAMP;
	MagFilter = POINT;
	MinFilter = POINT;
	Mipfilter = POINT;
};
// diffuse color, and specularIntensity in the alpha channel
sampler colorSampler = sampler_state
{
	Texture = <colorMap>;
	AddressU = CLAMP;
	AddressV = CLAMP;
	MagFilter = POINT;
	MinFilter = POINT;
	Mipfilter = POINT;
};



sampler depthSampler = sampler_state
{
	Texture = <depthMap>;
	AddressU = CLAMP;
	AddressV = CLAMP;
	MagFilter = POINT;
	MinFilter = POINT;
	Mipfilter = POINT;
};



struct VertexShaderInput
{
	float3 Position : POSITION0;
	float2 TexCoord : TEXCOORD0;
};
struct VertexShaderOutput
{
	float4 Position : POSITION0;
	float2 TexCoord : TEXCOORD0;
};
float2 halfPixel;
VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
	VertexShaderOutput output;
	output.Position = float4(input.Position, 1);
	//align texture coordinates
	output.TexCoord = input.TexCoord - halfPixel;
	return output;
}

float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
	//get normal data from the normalMap
	float4 normalData = tex2D(normalSampler,input.TexCoord);
	//tranform normal back into [-1,1] range
	float3 normal = 2.0f * normalData.xyz - 1.0f;
	//get specular power, and get it into [0,255] range]
	float specularPower = normalData.a * 255;
	//get specular intensity from the colorMap
	float specularIntensity = tex2D(colorSampler, input.TexCoord).a;

	//read depth
	float depthVal = tex2D(depthSampler,input.TexCoord).r;
	//compute screen-space position
	float4 position;
	position.x = input.TexCoord.x * 2.0f - 1.0f;
	position.y = -(input.TexCoord.y * 2.0f - 1.0f);
	position.z = depthVal;
	position.w = 1.0f;
	//transform to world space
	position = mul(position, InvertViewProjection);
	position /= position.w;

	//surface-to-light vector
	float3 lightVector = -normalize(lightDirection);
	//compute diffuse light
	float NdL = max(0,dot(normal,lightVector));
	float3 diffuseLight = (0.6 + (NdL * 0.4)) * Color.rgb;
	//reflexion vector
	float3 reflectionVector = normalize(reflect(lightVector, normal));
	//camera-to-surface vector
	float3 directionToCamera = normalize(cameraPosition - position.xyz);
	//compute specular light
	float specularLight = specularIntensity * pow(saturate(dot(reflectionVector, directionToCamera)), specularPower);
	//output the two lights
	return float4(diffuseLight.rgb, normalData.a);
}
technique Technique0
{
	pass Pass0
	{
		VertexShader = compile VS_SHADERMODEL VertexShaderFunction();
		PixelShader = compile  PS_SHADERMODEL PixelShaderFunction();
	}
}