RenderTile unusual behaviour

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

Moderator: Moderators

Post Reply
User avatar
rrTea
Posts: 475
Joined: Sat Feb 15, 2014 9:54 am

RenderTile unusual behaviour

Post by rrTea »

After putting the code below into ZGE, lock the preview to the ZGE Application. The preview Window will show two things, a mesh on the left and a texture on the right (immediately next to it). Don't click Run yet!

1. Go to OnRender and move the RenderMesh below the transf_Tile:RenderTransform component, the mesh will disappear from the preview.

2. Run the project, you'll notice the texture (tile) part will change its color even though both the mesh and the tile use the same material that does not use lighting - in fact the mesh stays the same like it was before launching. Removing the light_Reflector (in Lights) makes the tile behave like an ordinary texture again.

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="Prg" Caption="Template (fps: 0)" ClearColor="0.502 0.502 0.7529 1" AmbientLightColor="0.502 0 1 0.5" Camera="cam_Front" FileVersion="2">
  <OnLoaded>
    <Variable Name="ScreenRatio"/>
    <Variable Name="ScreenEdgeTop"/>
    <Variable Name="ScreenEdgeRight"/>
    <Constant Name="TilesPerX" Type="1" IntValue="16"/>
    <Constant Name="TilesPerY" Type="1" IntValue="12"/>
    <Constant Name="TextureInBmpPerX" Type="1" IntValue="10"/>
    <Constant Name="TextureInBmpPerY" Type="1" IntValue="10"/>
    <ZExpression Comment="Calculate">
      <Expression>
<![CDATA[ScreenRatio = (1f*Prg.ViewportWidth/Prg.ViewportHeight);

ScreenEdgeTop   = cam_Front.OrthoZoom*1f;
ScreenEdgeRight = cam_Front.OrthoZoom*ScreenRatio;

//Just so the tiles are the same size as meshes
transf_Tile.Scale.X = 2f/((bmp_Paint.Width/TextureInBmpPerX));
transf_Tile.Scale.Y = 2f/((bmp_Paint.Width/TextureInBmpPerY));
rTile_First.OriginX = (1f*bmp_Paint.Width/TextureInBmpPerX)*0.5;
rTile_First.OriginY = (1f*bmp_Paint.Height/TextureInBmpPerY)*0.5;]]>
      </Expression>
    </ZExpression>
  </OnLoaded>
  <OnUpdate>
    <ZExpression Expression="Prg.Caption = "Template (fps: " + intToStr(Prg.FpsCounter) + ")";"/>
  </OnUpdate>
  <OnRender>
    <UseMaterial Material="mat_ColorAlpha"/>
    <RenderSetColor Color="0 1 1 1"/>
    <RenderMesh Mesh="mesh_Rect"/>
    <RenderTransformGroup Name="transf_Tile" Scale="0.0625 0.0625 1" Translate="2 0 1">
      <Children>
        <RenderTile Name="rTile_First" TileSet="tSet_Stickers" TileIndex="10" OriginX="16" OriginY="16"/>
      </Children>
    </RenderTransformGroup>
  </OnRender>
  <Lights>
    <Light Name="light_Reflector" Position="2 2 2" Color="1 1 1 1"/>
  </Lights>
  <Content>
    <Camera Name="cam_Front" Kind="1" Position="0 0 10" OrthoZoom="12"/>
    <Bitmap Name="bmp_Paint" Width="320" Height="320" Filter="1">
      <Producers>
        <BitmapFromFile Comment="Imported from images.png" Transparency="1" HasAlphaLayer="1" DataWidth="320" DataHeight="320">
          <BitmapFile>
<![CDATA[78DAEDDDD171DB30104551559C9E525466D28DD2412C92C2EEC3E29C19FF5A26045E811025BF5E0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000C0A7FEBE7FBDFFF76384707E381F4EEB9EE7DC3C38691E748E41C2989F74BE5F99F3A735F084E3BEF3FC573620790CA634F7D435EEA7635C352609E37E52FB9FB66FD598ECD0BFEEBF41FFBE3FDEDD73B273EC4F5BFFDE39BE8EB550EA58549D8BDDD7DF53F71CAEFEDEA9FDEB78ED4FE8EB93C73DA17F69EB90A9FB0F5D6BEFABBFAFA37FABC7FFCA187FF3EF4ADBE3B9F39855AFCDA9D74309EB90DDF71F3AF75B12FB57BD067C72EDB7D35A7FD5B14CEA5FC2F5474AA7BBD63A9FAE7DAB8F71EA7B5077F73FBFD9BF8EF587FE65CEF59431EA78BFBBFA789FEC794FEDDF95BD979DAFC156ED654EEC5FE53548F518A5DCEFD3312792EEF7EA6A60E218EC767D33AD7F5DD7C11DDDD4BFDCFB9E53DE079978DFBFFEEDDFC0DDFBD73D277638F6B4064E796CFDDBBB7F4FFEB6ABF73AECDEFB296BFCEEFE75AF3DF56FFF736ED55C99DCBFA47BA0A736306DEDB7FAD8F52FFFEF58796DF6D3EF48BA1755FF323E7799F0DC278EE9C4FB9F77E95FC5EB6E52E72BCEFFD31A78E573971DC795DCBFC99FFF48EEDF84EB9E8A75EED4FE55ED8126DC035A35EFF52FEFB3385DDFBB95789DBFEB1EE3B75E833AFA57B9FF50DD828A7D74FDCB9F8349E7FFB4F5D58AEBFF8EBDAB89FD7BF2BC4FFBFE97CA6BCE3BDD9DBC0E4C7CAF6B87EFDE5DB1075CFD3C25F6EFCEF598FF8BD033FF273420FD5E9BE4EF62AEFA1E96AEF761933F03A87DFDCFC1847550FA672E26CFF3B4FEFD74CD73C21A8439DF8FB662EE9DB80E4CEB60D763278D834A9DD3E0D3FAD7B91FE8F55E6F30FF9D07E680E71B0000000048F57EFD7EB7FE347BFD69FE01F44FFF00FDD33F40FFF40FD03FFD03F44FFF00FDD33F40FFF40FD03FFD03F44FFF00FDD33F40FFF40FD03FFD03F44FFF40FFF44FFF40FFF44FFF40FFF44FFF40FFF44FFF40FFF44FFF40FFF44FFF40FFF44FFF40FFF44FFF40FFF44FFF40FFF44FFF40FFF44FFF40FFF44FFF40FFF40FD03FFD03F44FFF00FDD33F40FFF40FD03FFD8321FE015EB434BB]]>
          </BitmapFile>
        </BitmapFromFile>
      </Producers>
    </Bitmap>
    <Material Name="mat_ColorAlpha" Shading="1" Light="0" Blend="1"/>
    <TileSet Name="tSet_Stickers" Bitmap="bmp_Paint" TileWidth="32" TileHeight="32"/>
    <Mesh Name="mesh_Rect">
      <Producers>
        <MeshBox/>
      </Producers>
    </Mesh>
    <Mesh Name="mesh_RectangleWithTC">
      <Producers>
        <MeshBox Grid2DOnly="255"/>
        <MeshExpression Comment="Color 0" HasTexCoords="255">
          <Expression>
<![CDATA[int WhichTileX = 2;

TexCoord.X = (1f/TextureInBmpPerX) * (1f*WhichTileX);
TexCoord.Y = 1;//(1f/tilesInBmpY) * (1f*WhichTileY);]]>
          </Expression>
        </MeshExpression>
      </Producers>
    </Mesh>
  </Content>
</ZApplication>
User avatar
VilleK
Site Admin
Posts: 2316
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: RenderTile unusual behaviour

Post by VilleK »

I've made an update that makes it behave better, but at the moment you will need to add another call to UseMaterial after using RenderTile or RenderSprite if you are using additional render commands in the same OnRender, because for performance reasons the tile/sprite texture is still active. Let me know if that helps. It might be best to move RendeSprite/Tile components to the end of the OnRender list if possible.
User avatar
rrTea
Posts: 475
Joined: Sat Feb 15, 2014 9:54 am

Re: RenderTile unusual behaviour

Post by rrTea »

Excellent, thanks! Luckily for me I already had it set up in my project somewhat like that - each Enemy is based on a model that renders a mesh by itself + enemy specific details which are rendered in the Child model (sometimes it's a mesh sometimes it's a tile), so UseMaterial is called twice even though it's the same material and RenderTile / Sprite is always at the end of rendering.

Edit: Might be worth adding to the Help, since it's not immediately obvious?
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Re: RenderTile unusual behaviour

Post by Rado1 »

VilleK wrote:but at the moment you will need to add another call to UseMaterial after using RenderTile or RenderSprite if you are using additional render commands in the same OnRender
Ville, is this true only for RenderTile and RenderSprite? I would like to put this information to help, but to ALL relevant places.
User avatar
VilleK
Site Admin
Posts: 2316
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: RenderTile unusual behaviour

Post by VilleK »

Rado1 wrote:Ville, is this true only for RenderTile and RenderSprite? I would like to put this information to help, but to ALL relevant places.
Yes, only for those two.
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Re: RenderTile unusual behaviour

Post by Rado1 »

Added to help file. Will appear in next beta release.
User avatar
VilleK
Site Admin
Posts: 2316
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: RenderTile unusual behaviour

Post by VilleK »

Thanks Rado1. I will replace the wiki-documentation with your html-generated one too. Sorry that it hasn't happened yet but it is on my todo-list.
Post Reply