Works only in Preview

All topics about ZGameEditor goes here.

Moderator: Moderators

User avatar
rrTea
Posts: 306
Joined: Sat Feb 15, 2014 9:54 am

Works only in Preview

Postby rrTea » Fri Dec 01, 2017 5:31 am

Any idea why this code only works in preview mode but not when launched (shows only black screen)?

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" ClearColor="0.502 0.502 1 1" FileVersion="2">
  <OnLoaded>
    <Repeat Count="20">
      <OnIteration>
        <SpawnModel Model="Model1"/>
      </OnIteration>
    </Repeat>
  </OnLoaded>
  <OnUpdate>
    <ZExpression>
      <Expression>
<![CDATA[float t;
t = App.Time;

setCol_Tone.Color.R = 0.3 + noise2(t, sin(t));
setCol_Tone.Color.G = 0.7 - noise2(sin(t), cos(t));
setCol_Tone.Color.B = 0.5 + noise2(cos(t), sin(t+0.25));]]>
      </Expression>
    </ZExpression>
  </OnUpdate>
  <OnBeginRenderPass>
    <SetRenderTarget RenderTarget="RenderTarget1"/>
    <UseMaterial Material="mat_Transparent"/>
    <RenderSetColor Name="setCol_Tone" Color="0.2259 0.7823 0.599 0.01"/>
    <RenderTransformGroup Scale="6 4 1">
      <Children>
        <RenderMesh Mesh="Mesh1"/>
      </Children>
    </RenderTransformGroup>
  </OnBeginRenderPass>
  <OnRender>
    <SetRenderTarget/>
    <UseMaterial Material="mat_RT"/>
    <RenderTransformGroup Scale="4 4 1">
      <Children>
        <RenderMesh Mesh="Mesh1"/>
      </Children>
    </RenderTransformGroup>
  </OnRender>
  <Content>
    <RenderTarget Name="RenderTarget1" CustomWidth="160" CustomHeight="120" ClearBeforeUse="0" Filter="1"/>
    <Material Name="mat_RT" Comment="Rendertarget" Light="0">
      <Textures>
        <MaterialTexture RenderTarget="RenderTarget1" TextureWrapMode="2" TexCoords="1"/>
      </Textures>
    </Material>
    <Material Name="mat_Base" Comment="base" Shading="1" Light="0"/>
    <Material Name="mat_Transparent" Comment="Used for masking" Shading="1" Light="0" Blend="1"/>
    <Material Name="mat_Point" Shading="3" Color="0 1 1 1" Light="0"/>
    <Mesh Name="Mesh1">
      <Producers>
        <MeshBox Grid2DOnly="255"/>
      </Producers>
    </Mesh>
    <Model Name="Model1" Scale="0.5 0.5 0.5" Category="1">
      <OnSpawn>
        <ZExpression>
          <Expression>
<![CDATA[CurrentModel.Rotation.Z = CurrentModel.Personality;

CurrentModel.Position.X = sin(CurrentModel.Personality*Pi*2);
CurrentModel.Position.Y = cos(CurrentModel.Personality*Pi*2);]]>
          </Expression>
        </ZExpression>
      </OnSpawn>
      <OnUpdate>
        <SteeringController Mass="0.5" MaxSpeed="0.5" MaxForce="5" AdjustHeading="255">
          <Behaviours>
            <SteeringBehaviour Kind="2"/>
          </Behaviours>
        </SteeringController>
        <Condition>
          <Expression>
<![CDATA[return(
      abs(CurrentModel.Position.X) > 4f*8/6
    ||abs(CurrentModel.Position.Y) > 4f*1
      );]]>
          </Expression>
          <OnTrue>
            <ZExpression Expression="CurrentModel.Position = 0;"/>
          </OnTrue>
        </Condition>
        <ZExpression>
          <Expression>
<![CDATA[float t,p;
t = App.Time*0.1;
p = CurrentModel.Personality;

CurrentModel.Scale = 0.4 + noise2(t*p, sin(t)+p);]]>
          </Expression>
        </ZExpression>
      </OnUpdate>
      <OnRender>
        <UseMaterial Material="mat_Point"/>
        <RenderMesh Mesh="Mesh1"/>
      </OnRender>
    </Model>
    <Mesh Name="Mesh2">
      <Producers>
        <MeshBox/>
      </Producers>
    </Mesh>
  </Content>
</ZApplication>



It should look like this: (captured from the Preview)
https://streamable.com/wzxbc

Update: actually it doesn't work in freshly restarted ZGE Preview either until the RenderTarget1.ClearBeforeUse is ticked on and then ticked off again.

User avatar
VilleK
Site Admin
Posts: 1891
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: Works only in Preview

Postby VilleK » Fri Dec 01, 2017 8:39 am

Are you using the ZGameEditor.exe I provided in the RenderText thread? That will generate incorrect binaries until I've rebuilt the runtime engines to match the changes.

User avatar
rrTea
Posts: 306
Joined: Sat Feb 15, 2014 9:54 am

Re: Works only in Preview

Postby rrTea » Fri Dec 01, 2017 10:02 am

No, I'm using the standard / newest beta build...

User avatar
VilleK
Site Admin
Posts: 1891
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: Works only in Preview

Postby VilleK » Fri Dec 01, 2017 12:40 pm

I could reproduce this problem, and I think I've fixed it here: http://www.zgameeditor.org/files/ZGameEditor_beta.zip

User avatar
rrTea
Posts: 306
Joined: Sat Feb 15, 2014 9:54 am

Re: Works only in Preview

Postby rrTea » Sat Dec 02, 2017 4:09 am

It doesn't want to render on my end, I must be doing something wrong - will investigate a bit more during the week (I think I'm about to catch a cold) and report back.

User avatar
VilleK
Site Admin
Posts: 1891
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: Works only in Preview

Postby VilleK » Sat Dec 02, 2017 10:40 am

The beta is updated with my change that makes it work 100% in preview, but I notice now that it is still black in exe-file. I notice something unusual with your project though, you do some rendering in OnBeginRenderPass. I would try to just set things up in OnBeginRenderPass and then do the actual rendering in App.OnRender, using Condition component and testing App.CurrentRenderPass. That is how it is meant to be used. Also you seem to have App.RenderPasses set to 1 and I'm not sure if that is intentional.

You can ignore OnBeginRenderPass completely and render all in one renderpass, see Projects/RenderTexture demo project.

Let me know if you need more help.

User avatar
rrTea
Posts: 306
Joined: Sat Feb 15, 2014 9:54 am

Re: Works only in Preview

Postby rrTea » Sun Dec 03, 2017 5:09 am

Thanks, fixed now!

User avatar
rrTea
Posts: 306
Joined: Sat Feb 15, 2014 9:54 am

Re: Works only in Preview

Postby rrTea » Fri Jan 19, 2018 5:07 am

Hey Ville, how does RenderPass affect things that are rendered in a model? I see that the example for RenderPass has the rendering part wrapped in "return 1;//App.CurrentRenderPass>=0;", why is that? (Maybe just to hint at possibilities and encourage people like me to experiment.)

If the number of rendering passes is set to 2, is the model actually rendered twice unless the OnRender events are wrapped in a condition? As you can see I'm completely clueless as to how this works :D I tried to test it and it seems this is indeed the case:

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="Render passes demo" RenderPasses="2" ClearColor="0.502 0.502 0.7529 1" FileVersion="2">
  <OnUpdate>
    <Timer Interval="0.31">
      <OnTimer>
        <SpawnModel Model="SpinnerModel"/>
      </OnTimer>
    </Timer>
  </OnUpdate>
  <OnBeginRenderPass>
    <Condition Expression="return App.CurrentRenderPass==0;">
      <OnTrue>
        <SetRenderTarget RenderTarget="RenderTarget1"/>
      </OnTrue>
      <OnFalse>
        <SetRenderTarget/>
      </OnFalse>
    </Condition>
  </OnBeginRenderPass>
  <OnRender>
    <Condition Expression="return App.CurrentRenderPass==0;">
      <OnFalse>
        <UseMaterial Material="RenderTargetSourceMaterial"/>
        <RenderTransformGroup Scale="3 3 2" Translate="4 0 0">
          <Children>
            <RenderSprite/>
          </Children>
        </RenderTransformGroup>
        <RenderTransformGroup Scale="3 3 2" Translate="-4 0 0">
          <Children>
            <RenderSprite/>
          </Children>
        </RenderTransformGroup>
      </OnFalse>
    </Condition>
  </OnRender>
  <Content>
    <Group Comment="Spinner">
      <Children>
        <Model Name="SpinnerModel" Scale="2 2 1" RotationVelocity="0 0.5 0">
          <Definitions>
            <Variable Name="SpinnerTime"/>
          </Definitions>
          <OnUpdate>
            <Condition Expression="return CurrentModel.Position.Y&gt;5.5;">
              <OnTrue>
                <RemoveModel/>
              </OnTrue>
            </Condition>
            <ZExpression>
              <Expression>
<![CDATA[SpinnerTime+=App.DeltaTime*0.75;

Temp1=-4.5 + SpinnerTime;
Temp1+=noise2(CurrentModel.Personality,SpinnerTime*0.5) * 1.0;
Temp1+=noise2((SpinnerTime+App.Time)*0.25,0)*3;
CurrentModel.Position.Y=Temp1;

Temp1=sin(SpinnerTime*2)*2;
//Temp1+=App.MousePosition.X*4*(CurrentModel.Personality*0.1);
//Temp1+=noise2(CurrentModel.Personality,SpinnerTime*1) * 1;
Temp1+=noise2((SpinnerTime*0.25+App.Time)*0.2,0)*18;
CurrentModel.Position.X=Temp1;

Temp1=cos(SpinnerTime*2)*2;
CurrentModel.Position.Z=Temp1;]]>
              </Expression>
            </ZExpression>
          </OnUpdate>
          <OnRender>
            <UseMaterial Material="SpinnerMaterial"/>
            <Condition Expression="return App.CurrentRenderPass&gt;=0;">
              <OnTrue>
                <RenderSetColor Color="1 0.502 0.7529 1"/>
              </OnTrue>
              <OnFalse>
                <RenderSetColor Color="0.502 0.502 1 1"/>
              </OnFalse>
            </Condition>
            <RenderMesh Mesh="SpinnerMesh"/>
          </OnRender>
        </Model>
        <Mesh Name="SpinnerMesh">
          <Producers>
            <MeshSphere Scale="0.25 0.25 0.25" ZSamples="8" RadialSamples="8"/>
          </Producers>
        </Mesh>
        <Material Name="SpinnerMaterial" Shading="1"/>
      </Children>
    </Group>
    <Group Comment="Globals">
      <Children>
        <Variable Name="Temp1"/>
        <Variable Name="Temp2"/>
        <Variable Name="Temp3"/>
      </Children>
    </Group>
    <Group Comment="Render target">
      <Children>
        <RenderTarget Name="RenderTarget1" ClearColor="0.502 0.502 0.502 1"/>
        <Material Name="RenderTargetSourceMaterial">
          <Textures>
            <MaterialTexture RenderTarget="RenderTarget1" TexCoords="1"/>
          </Textures>
        </Material>
      </Children>
    </Group>
  </Content>
</ZApplication>

User avatar
VilleK
Site Admin
Posts: 1891
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: Works only in Preview

Postby VilleK » Fri Jan 19, 2018 3:15 pm

Yes, indeed everything is rendered in every render pass :-). So you need to test CurrentRenderPass everywhere to use it like you want. If you have ideas on how to improve this feature, go ahead. It has not been used much as far as I know (but it is quite powerful feature).

User avatar
rrTea
Posts: 306
Joined: Sat Feb 15, 2014 9:54 am

Re: Works only in Preview

Postby rrTea » Fri Jan 19, 2018 3:28 pm

Hmm in my project I have too many models and AppStates to go back and wrap all of them into a Condition... I guess I should have set it up differently.

The reason I'm asking all this (and why in the previous posts I rendered some stuff in OnBeginRenderPass) is because I'm using the "wallpaper" for everything in a project I'm working on. So first a 2d image is rendered in the back of everything and then all the models and various OnRenders and the rest. To complicate matters I also use RenderTarget etc.

The way I have it set up right now it works perfectly (meaning fast + reliable) but I'm trying to find out whether I can set this "wallpaper system" up a bit better for an eventual future project. Thanks for confirming :)

User avatar
rrTea
Posts: 306
Joined: Sat Feb 15, 2014 9:54 am

Re: Works only in Preview

Postby rrTea » Fri Jan 19, 2018 3:48 pm

Actually one feature that would make it a bit smoother and cut the need for rendering the wallpaper in OnBeginRenderPass in my particular case is if there were an option of "clearing" RenderTarget with a bitmap as opposed to just filling it up with a color... That's what I'm (clumsily :oops: ) doing manually right now.


Return to “General discussion”

Who is online

Users browsing this forum: No registered users and 0 guests