Advertisement

Why I cant render red? (Monogame/DesktopGL)

Started by August 07, 2023 09:43 PM
5 comments, last by scott8 1ย year, 4ย months ago

Hi, I have a little shader written for basic lighting, I just rewrote the example from LearnOpenGL to hlsl but I can't render the red color at all. Thank you for all your responses.

float4 MainPS(VertexShaderOutput input) : SV_Target {
	float3 ambientLightColor = float3(1.0, 1.0, 1.0);
	float3 diffuseLightColor = float3(1.0, 1.0, 1.0);
	float3 specularLightColor = float3(1.0, 1.0, 1.0);

	// ambient
	float ambientStrength = 0.1;
	float3 ambient = ambientLightColor * ambientStrength;

	// diffuse
	float3 lightDir = normalize(pointLight - input.Position);
	float diff = max(dot(input.Normal.xyz, lightDir), 0.0);
	float3 diffuse = diff * diffuseLightColor;

	// specular
	float specularStrength = 0.4;
	float3 viewDir = normalize(cameraSource - input.Position);
	float3 reflectDir = reflect(-lightDir, input.Normal.xyz);
	float spec = pow(max(dot(viewDir, reflectDir), 0.0), 64);
	float3 specular = specularStrength * spec * specularLightColor;

	// output
	float3 outputColor = (ambient + diffuse + specular) * input.Color.rgb;

	return float4(outputColor, 1.0);
}
Advertisement

That block of code looks like it provides 3 white lights, although it doesn't have a cap so ambient + diffuse + specular can be greater than 100%, which might be okay for you. I'd say the next stop would be to double-check the input. Verify the data is what you expect, with an actual red-colored or red-textured object. Is the input.Color rgb value what you expect?

abdullahhhh01011 said:

Review your code and configurations to identify the source of the problem and ensure proper rendering of red.

If you're not a bot then you should apply to be one.

๐Ÿ™‚๐Ÿ™‚๐Ÿ™‚๐Ÿ™‚๐Ÿ™‚<โ†The tone posse, ready for action.

Dear @abdullahhhh01011 ,

I want to assure you that you are a unique individual, distinct from AI. While your communication style may resemble AI due to technological influences, it's your personal thoughts, emotions, and experiences that define your true identity. Embrace your humanity and continue expressing yourself authentically.

Advertisement

OMG, they got SuperVGA

๐Ÿ™‚๐Ÿ™‚๐Ÿ™‚๐Ÿ™‚๐Ÿ™‚<โ†The tone posse, ready for action.

@Jimmyberf Along the lines of what Frob suggested:

// output

float3 outputColor = saturate(ambient + diffuse + specular) * input.Color.rgb;

This topic is closed to new replies.

Advertisement