I’m transitioning my monogame project to OpenGL for compatibility with Android etc down the line.
Everything is working except one of my custom shaders. I have two custom shaders that I use in the project, one works like normal under OpenGL and the other one does not. The working one is a very basic texture shader, the non working one is more or less the same except it is billboarding and animates the top corners of the mesh.
Spent a day trying to figure this out, temporarily running out of ideas. What could be the issue here?
I get no compiler errors but my billboarding meshes are invisible under OpenGL.
The only difference in the code from a fully working DirectX build and the half working OpenGL is I changed the
compile vs_4_0_level_9_1
to:
compile vs_3_0
Heres my Billboarding shader that seemingly stops working under OpenGL:
float4x4 World;
float4x4 View;
float4x4 Projection;
float Alpha = 1;
float animationTime;
float animationScaleFactor;
texture ColorMap;
sampler colorMapSampler = sampler_state
{
Texture = <ColorMap>;
AddressU = clamp;
AddressV = clamp;
};
struct VertexInput
{
float4 Position : POSITION;
float4 TexCoord : TEXCOORD0;
float2 Offsets : TEXCOORD1;
};
struct VertexOutput
{
float4 Position : POSITION;
float2 TexCoord : TEXCOORD0;
};
//-----------------------------------------------------------------------------
// Vertex shaders.
//-----------------------------------------------------------------------------
VertexOutput VS_BillboardingCameraAligned(VertexInput input)
{
//Input
float2 offsets = input.Offsets.xy;
float2 texCoord = input.TexCoord.xy;
float3 inPos = input.Position.xyz;
//Billboarding magic
float4x4 worldViewProjection = mul(mul(World, View), Projection);
float3 xAxis = float3(View._11, View._21, View._31);
float3 yAxis = float3(View._12, View._22, View._32);
float animationDisplacement = input.Position.w * sin(animationTime) * animationScaleFactor;
float3 pos = inPos + ((offsets.x + animationDisplacement) * xAxis) + ((offsets.y) * yAxis);
float4 outPos = mul(float4(pos, 1.0f), worldViewProjection)
//Output
VertexOutput output;
output.Position = outPos;
output.TexCoord.xy = texCoord.xy;
return output;
}
//-----------------------------------------------------------------------------
// Pixel shaders.
//-----------------------------------------------------------------------------
float4 PS_Standard(VertexOutput input) : COLOR
{
float alphaTestDirection = 1.0f;
float alphaTestThreshold = 0.95f;
float4 outColor = tex2D(colorMapSampler, input.TexCoord);
outColor.rgba *= Alpha;
return outColor;
}
//-----------------------------------------------------------------------------
// Techniques.
//-----------------------------------------------------------------------------
technique Standard
{
pass
{
VertexShader = compile vs_3_0 VS_BillboardingCameraAligned();
PixelShader = compile ps_3_0 PS_Standard();
}
}
Or am I wrong to assume that it’s shader that’s the issue?
EDIT: Formatting