Effect parameters missing

I’m running into an odd issue where I defined an Effect file with 8 different Parameters, but when trying to use it when rendering, it only has 6 parameters I can assign to. Now I understand that MGCP is very aggressive about removing unused parameters when compiling shaders, but in my case the parameters are clearly used. I have tried cleaning and rebuilding the solution, cleaning and rebuilding the content assets - nothing. It just will not expose the “MorningTint” and “EveningTint” parameters. Added the code below.

        foreach (ModelMesh mesh in this.skyModel.Meshes) {

            foreach (Effect effect in mesh.Effects) {

                Matrix world = transforms[mesh.ParentBone.Index] * worldMatrix;

                effect.CurrentTechnique = effect.Techniques["Default"];
                
                effect.Parameters["World"].SetValue(world);
                effect.Parameters["View"].SetValue(this.cameraManager.View);
                effect.Parameters["Projection"].SetValue(this.cameraManager.Projection);

                effect.Parameters["DayColor"].SetValue(this.DayColor);
                effect.Parameters["NightColor"].SetValue(this.NightColor);
                effect.Parameters["HorizonColor"].SetValue(this.HorizonColor);
                //effect.Parameters["MorningTint"].SetValue(this.MorningTint);
                //effect.Parameters["EveningTint"].SetValue(this.EveningTint);

            }

            mesh.Draw();
        }

And the shader code

#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

matrix World;
matrix View;
matrix Projection;

float4 DayColor;
float4 NightColor;
float4 HorizonColor;

float4 EveningTint;
float4 MorningTint;

struct VertexShaderInput {
	float4 Position : SV_POSITION;
};

struct VertexShaderOutput {
	float4 Position : SV_POSITION;
	float4 Object : TEXCOORD0;
};

struct PixelShaderOutput {
	float4 Color : COLOR0;
};

VertexShaderOutput DefaultVertexShader(VertexShaderInput input) {
	VertexShaderOutput output;

	float4 worldPosition = mul(input.Position, World);
	float4 viewPosition = mul(worldPosition, View);

	output.Position = mul(viewPosition, Projection);
	output.Object = input.Position;

	return output;
}

PixelShaderOutput DefaultPixelShader(VertexShaderOutput input) {
	PixelShaderOutput output;

	float4 topColor = DayColor;
	float4 bottomColor = HorizonColor;
	float4 nightColor = NightColor;

	bottomColor += (MorningTint * .05) * (12 / 24);
	bottomColor += (EveningTint * .05) * (12 / 24);

	topColor += nightColor;
	bottomColor += nightColor;

	output.Color = lerp(bottomColor, topColor, saturate(input.Object.z / 0.9));	

	return output;
}

technique Default {
	pass P0 {
		VertexShader = compile VS_SHADERMODEL DefaultVertexShader();
		PixelShader = compile PS_SHADERMODEL DefaultPixelShader();
	}
};

Change these two lines:

bottomColor += (MorningTint * .05) * (12 / 24);
bottomColor += (EveningTint * .05) * (12 / 24);

to this:

bottomColor += (MorningTint * .05) * (12.0 / 24);
bottomColor += (EveningTint * .05) * (12.0 / 24);

The compiler went mad because 12 / 24 is an integer division which returns 0, so the input values are being omitted.

2 Likes

Holy crap… Wow, I would have never figured that one out myself. Thank you :slight_smile: