Skip to content

Texture coords upside down on Android #3

Description

@k4G17eYWI

Prerequisites

  • I have verified this issue is present in the develop branch
  • I have searched open and closed issues to ensure it has not already been reported.

MonoGame Version

3.8.3

Which MonoGame platform are you using?

MonoGame Android Application (mgandroid)

Operating System

WIndows, Android

Description

I'm drawing on a texture. After switching to 5_0 shaders from 3_0 my textures draws upside down but only on Android. On a desktop it draws as "normal" in without flipping vertically. I have same FX file for Android and Desktop without any platform definitions.

What could cauise such diffirecies in behaviuor and how to deal them? I could detect platform and flip Y optionaly but Y want to wind out the reason.

Steps to Reproduce

  1. Set texture as a RenderTarget
  2. Set transform
        var m = Matrix.CreateScale(
            1f / texture.width * 2,
            1f / texture.height * 2,
            1
        );
        var t = Matrix.CreateTranslation(-1, -1, 0);
        var s = Matrix.CreateScale(1, -1, 1);
        SetTransform(m * t * s);
  1. Load shader
#define VS_SHADERMODEL vs_5_0
#define PS_SHADERMODEL ps_5_0

matrix Transform;

Texture2D MainTex; // primary texture.
SamplerState MySampler
{
    magfilter = Point;
    minfilter = Point;
    mipfilter = Point;
    AddressU = Clamp;
    AddressV = Clamp;
};

struct VsInputQuad
{
    float4 Position : POSITION0;
    float4 Color : COLOR0;
    float2 TexureCoordinateA : TEXCOORD0;
};

struct VsOutputQuad
{
    float4 Position : SV_POSITION0;
    float4 Color : COLOR0;
    float2 TexureCoordinateA : TEXCOORD0;
};

struct PsOutputQuad
{
    float4 Color : SV_TARGET;
};

// ____________________________
VsOutputQuad VertexShaderQuadDraw(VsInputQuad input)
{
    VsOutputQuad output;
    output.Position = mul(input.Position, Transform); // Transform by WorldViewProjection
    output.Color = input.Color;
    output.TexureCoordinateA = input.TexureCoordinateA;
    return output;
}

PsOutputQuad PixelShaderQuadDraw(VsOutputQuad input)
{
    PsOutputQuad output;
    output.Color = MainTex.Sample(MySampler, input.TexureCoordinateA) * input.Color;
    return output;
}

technique Draw
{
    pass
    {
        VertexShader = compile VS_SHADERMODEL VertexShaderQuadDraw();
        PixelShader = compile PS_SHADERMODEL PixelShaderQuadDraw();    
    }
}

  1. Draw some geometry on it on a desktop and Android platform and compare results. Resulting textures will be interflipped vertically.

AppAndroid.csproj:

        <PackageReference Include="MonoGame.Framework.Compute.Android" Version="3.8.3" />
        <PackageReference Include="MonoGame.Content.Builder.Task.Compute" Version="3.8.3" />

AppDesktop.csproj:

        <PackageReference Include="MonoGame.Framework.Compute.DesktopGL" Version="3.8.3"/>
        <PackageReference Include="MonoGame.Content.Builder.Task.Compute" Version="3.8.3"/>

Minimal Example Repo

No response

Expected Behavior

Texture Y axis should be same on Android and Desktop or we need a clarification how to deal with it.

Resulting Behavior

Texture Y axis should be same on Android and Desktop or we need a clarification how to deal with it.

Files

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions