Problem with TexCoords Generated on Android

Found a bug? Post information about it here so we can fix it!

Moderator: Moderators

Post Reply
User avatar
Ats
Posts: 762
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Problem with TexCoords Generated on Android

Post by Ats »

While doing my daily tests with the 64-bit stuff, I just realized that the texture positions are completely off on Android when the TexCoords is set to Generated, both in 32-bit and 64-bit. Didn't we already fix that? Or maybe I'm confusing it with something else, I don't know.

Anyway, here's what it looks in preview and PC mode:
Screenshot 2024-10-02 192159.png
Screenshot 2024-10-02 192159.png (331.85 KiB) Viewed 224 times
  • First row has the TexCoords Generated
  • Second row has the TexCoords ModelDefined
  • Then from left to right, the TextureWrapMode is Mirror, Tile and Clamp
And here's the same thing on Android:
Screenshot_20241002-192257.png
Screenshot_20241002-192257.png (381.18 KiB) Viewed 224 times
(to test Android 64, I used the hacked lib with threads completely deactivated)

Here's the example:

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" FileVersion="2" AndroidPackageName="com.mydomain.onrender">
  <OnRender>
    <Repeat Name="repeat" Count="6">
      <OnIteration>
        <ZExpression>
          <Expression>
<![CDATA[int i = repeat.Iteration;
transform.Translate.X = -2.5+(i % 3)*2.5;
transform.Translate.Y = 1.5-(i / 3)*3;

switch(i) {
case 0: @UseMaterial(MAterial:MaterialGeneratedMirror); break;
case 1: @UseMaterial(MAterial:MaterialGeneratedTile); break;
case 2: @UseMaterial(MAterial:MaterialGeneratedClamp); break;
case 3: @UseMaterial(MAterial:MaterialModelDefinedMirror); break;
case 4: @UseMaterial(MAterial:MaterialModelDefinedTile); break;
case 5: @UseMaterial(MAterial:MaterialModelDefinedClamp); break;
}]]>
          </Expression>
        </ZExpression>
        <RenderTransformGroup Name="transform" Translate="2.5 -1.5 0">
          <Children>
            <RenderTransform Rotate="0.1 0.1 0"/>
            <RenderMesh Mesh="CubeMesh"/>
          </Children>
        </RenderTransformGroup>
      </OnIteration>
    </Repeat>
  </OnRender>
  <Content>
    <Mesh Name="CubeMesh">
      <Producers>
        <MeshBox/>
      </Producers>
    </Mesh>
    <Bitmap Name="Bitmap1">
      <Producers>
        <BitmapCells RandomSeed="63"/>
      </Producers>
    </Bitmap>
    <Material Name="MaterialGeneratedMirror">
      <Textures>
        <MaterialTexture Texture="Bitmap1"/>
      </Textures>
    </Material>
    <Material Name="MaterialGeneratedTile">
      <Textures>
        <MaterialTexture Texture="Bitmap1" TextureWrapMode="1"/>
      </Textures>
    </Material>
    <Material Name="MaterialGeneratedClamp">
      <Textures>
        <MaterialTexture Texture="Bitmap1" TextureWrapMode="2"/>
      </Textures>
    </Material>
    <Material Name="MaterialModelDefinedMirror">
      <Textures>
        <MaterialTexture Texture="Bitmap1" TexCoords="1"/>
      </Textures>
    </Material>
    <Material Name="MaterialModelDefinedTile">
      <Textures>
        <MaterialTexture Texture="Bitmap1" TextureWrapMode="1" TexCoords="1"/>
      </Textures>
    </Material>
    <Material Name="MaterialModelDefinedClamp">
      <Textures>
        <MaterialTexture Texture="Bitmap1" TextureWrapMode="2" TexCoords="1"/>
      </Textures>
    </Material>
  </Content>
</ZApplication>
User avatar
Kjell
Posts: 1915
Joined: Sat Feb 23, 2008 11:15 pm

Re: Problem with TexCoords Generated on Android

Post by Kjell »

Hi Ats,

Generated texture coordinates aren't available on OpenGL ES. You can find the corresponding source code here.

That being said, this is what it looks like on my PC ( which looks correct to me ) .. not sure what's going on in your PC screenshot :(

Image

K
User avatar
Ats
Posts: 762
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Re: Problem with TexCoords Generated on Android

Post by Ats »

Oh, right. Thanks.

About the screenshot, I left some TexCoords coordinate numbers in my example that I edited afterwards. But that doesn't explain the bottom right cube... :?
(ModelDefined + Clamp)
User avatar
Kjell
Posts: 1915
Joined: Sat Feb 23, 2008 11:15 pm

Re: Problem with TexCoords Generated on Android

Post by Kjell »

Hmm,

Can you take a screenshot of this on PC? Bit easier to "read" than the cells bitmap :wink:

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" FileVersion="2" AndroidPackageName="com.mydomain.onrender">
  <OnRender>
    <Repeat Name="repeat" Count="6">
      <OnIteration>
        <ZExpression>
          <Expression>
<![CDATA[int i = repeat.Iteration;
transform.Translate.X = -2.5+(i % 3)*2.5;
transform.Translate.Y = 1.5-(i / 3)*3;

switch(i) {
case 0: @UseMaterial(MAterial:MaterialGeneratedMirror); break;
case 1: @UseMaterial(MAterial:MaterialGeneratedTile); break;
case 2: @UseMaterial(MAterial:MaterialGeneratedClamp); break;
case 3: @UseMaterial(MAterial:MaterialModelDefinedMirror); break;
case 4: @UseMaterial(MAterial:MaterialModelDefinedTile); break;
case 5: @UseMaterial(MAterial:MaterialModelDefinedClamp); break;
}]]>
          </Expression>
        </ZExpression>
        <RenderTransformGroup Name="transform" Translate="2.5 -1.5 0">
          <Children>
            <RenderTransform Rotate="0.1 0.1 0"/>
            <RenderMesh Mesh="CubeMesh"/>
          </Children>
        </RenderTransformGroup>
      </OnIteration>
    </Repeat>
  </OnRender>
  <Content>
    <Mesh Name="CubeMesh">
      <Producers>
        <MeshBox/>
      </Producers>
    </Mesh>
    <Bitmap Name="Bitmap1" Width="32" Height="32" Filter="1">
      <Producers>
        <BitmapExpression>
          <Expression>
<![CDATA[int u = X*32, v = Y*32;

if(u == 0 || u == 31 || v == 0 || v == 31)
{
  Pixel = 1;
}
else
{
  Pixel.R = X;
  Pixel.G = Y;
  Pixel.B = 1-X;
}]]>
          </Expression>
        </BitmapExpression>
      </Producers>
    </Bitmap>
    <Material Name="MaterialGeneratedMirror">
      <Textures>
        <MaterialTexture Texture="Bitmap1"/>
      </Textures>
    </Material>
    <Material Name="MaterialGeneratedTile">
      <Textures>
        <MaterialTexture Texture="Bitmap1" TextureWrapMode="1"/>
      </Textures>
    </Material>
    <Material Name="MaterialGeneratedClamp">
      <Textures>
        <MaterialTexture Texture="Bitmap1" TextureWrapMode="2"/>
      </Textures>
    </Material>
    <Material Name="MaterialModelDefinedMirror">
      <Textures>
        <MaterialTexture Texture="Bitmap1" TexCoords="1"/>
      </Textures>
    </Material>
    <Material Name="MaterialModelDefinedTile">
      <Textures>
        <MaterialTexture Texture="Bitmap1" TextureWrapMode="1" TexCoords="1"/>
      </Textures>
    </Material>
    <Material Name="MaterialModelDefinedClamp">
      <Textures>
        <MaterialTexture Texture="Bitmap1" TextureWrapMode="2" TexCoords="1"/>
      </Textures>
    </Material>
  </Content>
</ZApplication>
Should look like this ..

Image

K
User avatar
Ats
Posts: 762
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Re: Problem with TexCoords Generated on Android

Post by Ats »

I just verified, on my screenshot, the problem really was coming from the MaterialTexture.TextureX that was far from 0. I have the same screenshot as you...

But not with your example :?
I copied and paste your code to get this on PC:
Screenshot 2024-10-02 225701.png
Screenshot 2024-10-02 225701.png (73.29 KiB) Viewed 189 times
User avatar
Kjell
Posts: 1915
Joined: Sat Feb 23, 2008 11:15 pm

Re: Problem with TexCoords Generated on Android

Post by Kjell »

Oops,

My mistake .. should have used round() to prevent the possibility of rounding errors. Try this instead :wink:

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" FileVersion="2" AndroidPackageName="com.mydomain.onrender">
  <OnRender>
    <Repeat Name="repeat" Count="6">
      <OnIteration>
        <ZExpression>
          <Expression>
<![CDATA[int i = repeat.Iteration;
transform.Translate.X = -2.5+(i % 3)*2.5;
transform.Translate.Y = 1.5-(i / 3)*3;

switch(i) {
case 0: @UseMaterial(MAterial:MaterialGeneratedMirror); break;
case 1: @UseMaterial(MAterial:MaterialGeneratedTile); break;
case 2: @UseMaterial(MAterial:MaterialGeneratedClamp); break;
case 3: @UseMaterial(MAterial:MaterialModelDefinedMirror); break;
case 4: @UseMaterial(MAterial:MaterialModelDefinedTile); break;
case 5: @UseMaterial(MAterial:MaterialModelDefinedClamp); break;
}]]>
          </Expression>
        </ZExpression>
        <RenderTransformGroup Name="transform" Translate="2.5 -1.5 0">
          <Children>
            <RenderTransform Rotate="0.1 0.1 0"/>
            <RenderMesh Mesh="CubeMesh"/>
          </Children>
        </RenderTransformGroup>
      </OnIteration>
    </Repeat>
  </OnRender>
  <Content>
    <Mesh Name="CubeMesh">
      <Producers>
        <MeshBox/>
      </Producers>
    </Mesh>
    <Bitmap Name="Bitmap1" Width="32" Height="32" Filter="1">
      <Producers>
        <BitmapExpression>
          <Expression>
<![CDATA[int u = round(X*31), v = round(Y*31);

if(u == 0 || u == 31 || v == 0 || v == 31)
{
  Pixel = 1;
}
else
{
  Pixel.R = X;
  Pixel.G = Y;
  Pixel.B = 1-X;
}]]>
          </Expression>
        </BitmapExpression>
      </Producers>
    </Bitmap>
    <Material Name="MaterialGeneratedMirror">
      <Textures>
        <MaterialTexture Texture="Bitmap1"/>
      </Textures>
    </Material>
    <Material Name="MaterialGeneratedTile">
      <Textures>
        <MaterialTexture Texture="Bitmap1" TextureWrapMode="1"/>
      </Textures>
    </Material>
    <Material Name="MaterialGeneratedClamp">
      <Textures>
        <MaterialTexture Texture="Bitmap1" TextureWrapMode="2"/>
      </Textures>
    </Material>
    <Material Name="MaterialModelDefinedMirror">
      <Textures>
        <MaterialTexture Texture="Bitmap1" TexCoords="1"/>
      </Textures>
    </Material>
    <Material Name="MaterialModelDefinedTile">
      <Textures>
        <MaterialTexture Texture="Bitmap1" TextureWrapMode="1" TexCoords="1"/>
      </Textures>
    </Material>
    <Material Name="MaterialModelDefinedClamp">
      <Textures>
        <MaterialTexture Texture="Bitmap1" TextureWrapMode="2" TexCoords="1"/>
      </Textures>
    </Material>
  </Content>
</ZApplication>
K
User avatar
Ats
Posts: 762
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Re: Problem with TexCoords Generated on Android

Post by Ats »

Perfection :wink:
Post Reply