OMEGANAUT

Post screenshots, binaries and projectfiles of the projects you have made with ZGE that you want to share!

Moderator: Moderators

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

Re: OMEGANAUT

Post by Ats » Tue May 04, 2021 10:48 am

try switching to ES2/GL3 then saving the file as ShaderDemoES2 and then reloading it. Maybe it's using cached shader objects or something.
I did that and it's still the same. Switching to ES2/GL3 seems to be not simple and with random results... I'm not sure if I want to do that.

(but I'll do it anyway :lol: )

User avatar
Kjell
Posts: 1787
Joined: Sat Feb 23, 2008 11:15 pm

Re: OMEGANAUT

Post by Kjell » Tue May 04, 2021 11:30 am

Hi Ats,
Ats wrote:
Tue May 04, 2021 10:48 am
I did that and it's still the same. Switching to ES2/GL3 seems to be not simple and with random results... I'm not sure if I want to do that.
Sorry, my mistake. When you switch to ES2/GL3 on PC you can still use "legacy" features ( such as gl_Vertex ) due to backwards compatibility* There's no easy way to force ZGE to use OpenGL 3.3 ( the first version that isn't backwards-compatible ) without changing a bunch of stuff in the source code.

* ES 2.0 isn't backwards compatible with ES 1.1 though. But ES 1.1 doesn't support shaders ( and ES 2.0 doesn't support legacy shaders ) so you can't test it on Android either.

K

User avatar
Kjell
Posts: 1787
Joined: Sat Feb 23, 2008 11:15 pm

Re: OMEGANAUT

Post by Kjell » Tue May 04, 2021 12:01 pm

:idea:

Just to clear this up:

Code: Select all

┌─────────────┬──────────────┬───────────┬───────────────────┬────────────────┐
│             │PC(Compatible)│PC(ES2/GL3)│Android(Compatible)│Android(ES2/GL3)│
├─────────────┼──────────────┼───────────┼───────────────────┼────────────────┤
│Legacy Shader│OK            │OK         │ERROR              │ERROR           │
├─────────────┼──────────────┼───────────┼───────────────────┼────────────────┤
│Modern Shader│ERROR*        │OK         │ERROR              │OK              │
└─────────────┴──────────────┴───────────┴───────────────────┴────────────────┘
*Might not always produce compilation errors, but won't produce correct results.

K

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

Re: OMEGANAUT

Post by Ats » Sun Oct 31, 2021 8:09 pm

Hi guys, it's been a long time.
I'm currently integrating my random planets in Omeganaut, and I have an interesting z order problem to show you.
Right now, I'm displaying the planet far away from the main camera with another fixed camera, so it doesn't move around with the player ship:
pic1.png
pic1.png (69.34 KiB) Viewed 253 times
The problem is that the Material's ZBuffer of the planet gets in the way of the player ship, even if the planet coordinates are very far away from everything.
pic2.png
pic2.png (59.69 KiB) Viewed 253 times
It works when I deactivate the ZBuffer of the planet and his ring:
pic3.png
pic3.png (57.83 KiB) Viewed 253 times
But then again, I need the Zbuffer activated for the ring to display correctly on the planet...
What would be the correct way in order to solve this pesky problem?

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

Re: OMEGANAUT

Post by Ats » Mon Nov 01, 2021 9:30 am

I made a strip down example:

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" Camera="CameraGame" FileVersion="2">
  <OnLoaded>
    <ZExpression>
      <Expression>
<![CDATA[App.Camera = CameraGame;

CameraPlanet.Position.X = 1000;
CameraPlanet.Position.Y = 0;
CameraPlanet.Position.Z = 0;]]>
      </Expression>
    </ZExpression>
    <SpawnModel Model="PlanetModel" Position="1000 0 -5"/>
    <SpawnModel Model="ShipModel" Position="0 -1 -8"/>
  </OnLoaded>
  <Content>
    <Model Name="PlanetModel" Rotation="0.05 0.05 0">
      <OnRender>
        <ZExpression Expression="App.Camera = CameraPlanet;"/>
        <UseMaterial Material="PlanetMaterial"/>
        <RenderMesh Mesh="SphereMesh"/>
        <UseMaterial Material="RingMaterial"/>
        <RenderMesh Mesh="RingMesh"/>
        <ZExpression Expression="App.Camera = CameraGame;"/>
      </OnRender>
    </Model>
    <Mesh Name="SphereMesh">
      <Producers>
        <MeshSphere ZSamples="32" RadialSamples="32"/>
      </Producers>
    </Mesh>
    <Material Name="PlanetMaterial">
      <Textures>
        <MaterialTexture Texture="PlanetBitmap"/>
      </Textures>
    </Material>
    <Bitmap Name="PlanetBitmap">
      <Producers>
        <BitmapCells PointsPlacement="2" RandomSeed="39" BorderPixels="0" PointCount="4"/>
      </Producers>
    </Bitmap>
    <Mesh Name="RingMesh">
      <Producers>
        <MeshSphere Scale="2 0.001 2" ZSamples="64" RadialSamples="4"/>
      </Producers>
    </Mesh>
    <Material Name="RingMaterial">
      <Textures>
        <MaterialTexture Texture="RingBitmap"/>
      </Textures>
    </Material>
    <Bitmap Name="RingBitmap">
      <Producers>
        <BitmapExpression>
          <Expression>
<![CDATA[//X,Y : current coordinate (0..1)
//Pixel : current color (rgb)
//Sample expression: Pixel.R=abs(sin(X*16));
Pixel.R = abs(sin(X*8));]]>
          </Expression>
        </BitmapExpression>
      </Producers>
    </Bitmap>
    <Camera Name="CameraGame"/>
    <Camera Name="CameraPlanet" Position="1000 0 0"/>
    <Mesh Name="ShipMesh">
      <Producers>
        <MeshBox Scale="0.2 0.2 3"/>
        <MeshBox Scale="1 0.2 0.2"/>
        <MeshTransform Position="0 0.1 -2"/>
        <MeshCombine/>
        <MeshBox Scale="2 0.2 0.2"/>
        <MeshTransform Position="0 -0.1 2"/>
        <MeshCombine/>
      </Producers>
    </Mesh>
    <Material Name="ShipMaterial">
      <Textures>
        <MaterialTexture Texture="ShipBitmap" TexCoords="1"/>
      </Textures>
    </Material>
    <Bitmap Name="ShipBitmap">
      <Producers>
        <BitmapNoise Octaves="2" Offset="0.73" Persistence="1" ZHeight="38.57" Color="2"/>
      </Producers>
    </Bitmap>
    <Model Name="ShipModel">
      <OnUpdate>
        <ZExpression>
          <Expression>
<![CDATA[time += App.DeltaTime;
CurrentModel.Position.X = cos(time);
CurrentModel.Position.Y = -1 + sin(time);
CurrentModel.Position.Z = -8 + cos(time * 0.1);]]>
          </Expression>
        </ZExpression>
      </OnUpdate>
      <OnRender>
        <UseMaterial Material="ShipMaterial"/>
        <RenderMesh Mesh="ShipMesh"/>
      </OnRender>
    </Model>
    <Variable Name="time"/>
  </Content>
</ZApplication>
I'm wondering if it would be simpler to display a huge planet at the limit of the main camera, instead of a small one filmed with the planet camera. This way, object shouldn't pass through it...

User avatar
Kjell
Posts: 1787
Joined: Sat Feb 23, 2008 11:15 pm

Re: OMEGANAUT

Post by Kjell » Mon Nov 01, 2021 2:49 pm

Hi Ats,

This is actually very easy to solve .. the only thing you need to do is to clear the depth buffer after rendering your planet. Here's your example with one OpenGL call added to the last ZExpression in PlanetModel.OnRender :wink:

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" Camera="CameraGame" FileVersion="2">
  <OnLoaded>
    <ZExternalLibrary ModuleName="opengl32">
      <Source>
<![CDATA[const int GL_DEPTH_BUFFER_BIT = 0x0100;

void glClear(int mode){}]]>
      </Source>
    </ZExternalLibrary>
    <ZExpression>
      <Expression>
<![CDATA[App.Camera = CameraGame;

CameraPlanet.Position.X = 1000;
CameraPlanet.Position.Y = 0;
CameraPlanet.Position.Z = 0;]]>
      </Expression>
    </ZExpression>
    <SpawnModel Model="PlanetModel" Position="1000 0 -5"/>
    <SpawnModel Model="ShipModel" Position="0 -1 -8"/>
  </OnLoaded>
  <Content>
    <Model Name="PlanetModel" Rotation="0.05 0.05 0">
      <OnRender>
        <ZExpression Expression="App.Camera = CameraPlanet;"/>
        <UseMaterial Material="PlanetMaterial"/>
        <RenderMesh Mesh="SphereMesh"/>
        <UseMaterial Material="RingMaterial"/>
        <RenderMesh Mesh="RingMesh"/>
        <ZExpression>
          <Expression>
<![CDATA[App.Camera = CameraGame;

// Clear the depth buffer!
glClear(GL_DEPTH_BUFFER_BIT);]]>
          </Expression>
        </ZExpression>
      </OnRender>
    </Model>
    <Mesh Name="SphereMesh">
      <Producers>
        <MeshSphere ZSamples="32" RadialSamples="32"/>
      </Producers>
    </Mesh>
    <Material Name="PlanetMaterial">
      <Textures>
        <MaterialTexture Texture="PlanetBitmap"/>
      </Textures>
    </Material>
    <Bitmap Name="PlanetBitmap">
      <Producers>
        <BitmapCells PointsPlacement="2" RandomSeed="39" BorderPixels="0" PointCount="4"/>
      </Producers>
    </Bitmap>
    <Mesh Name="RingMesh">
      <Producers>
        <MeshSphere Scale="2 0.001 2" ZSamples="64" RadialSamples="4"/>
      </Producers>
    </Mesh>
    <Material Name="RingMaterial">
      <Textures>
        <MaterialTexture Texture="RingBitmap"/>
      </Textures>
    </Material>
    <Bitmap Name="RingBitmap">
      <Producers>
        <BitmapExpression>
          <Expression>
<![CDATA[//X,Y : current coordinate (0..1)
//Pixel : current color (rgb)
//Sample expression: Pixel.R=abs(sin(X*16));
Pixel.R = abs(sin(X*8));]]>
          </Expression>
        </BitmapExpression>
      </Producers>
    </Bitmap>
    <Camera Name="CameraGame"/>
    <Camera Name="CameraPlanet" Position="1000 0 0"/>
    <Mesh Name="ShipMesh">
      <Producers>
        <MeshBox Scale="0.2 0.2 3"/>
        <MeshBox Scale="1 0.2 0.2"/>
        <MeshTransform Position="0 0.1 -2"/>
        <MeshCombine/>
        <MeshBox Scale="2 0.2 0.2"/>
        <MeshTransform Position="0 -0.1 2"/>
        <MeshCombine/>
      </Producers>
    </Mesh>
    <Material Name="ShipMaterial">
      <Textures>
        <MaterialTexture Texture="ShipBitmap" TexCoords="1"/>
      </Textures>
    </Material>
    <Bitmap Name="ShipBitmap">
      <Producers>
        <BitmapNoise Octaves="2" Offset="0.73" Persistence="1" ZHeight="38.57" Color="2"/>
      </Producers>
    </Bitmap>
    <Model Name="ShipModel">
      <OnUpdate>
        <ZExpression>
          <Expression>
<![CDATA[time += App.DeltaTime;
CurrentModel.Position.X = cos(time);
CurrentModel.Position.Y = -1 + sin(time);
CurrentModel.Position.Z = -8 + cos(time * 0.1);]]>
          </Expression>
        </ZExpression>
      </OnUpdate>
      <OnRender>
        <UseMaterial Material="ShipMaterial"/>
        <RenderMesh Mesh="ShipMesh"/>
      </OnRender>
    </Model>
    <Variable Name="time"/>
  </Content>
</ZApplication>
K

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

Re: OMEGANAUT

Post by Ats » Mon Nov 01, 2021 4:00 pm

Thanks Kjell. An easy fix when you know about it. That was very helpful.
I'm going to rethink how I can handle the whole background with that new knowledge :wink:

Post Reply