Need some help with this script

Return to “ZGameEditor Visualizer Script Reference”

[You can only see part of this thread as you are not logged in to the forums]
Zephyrean
Mon Feb 06, 2023 9:06 am

x

Need some help with this script

I'm trying to alter the 'Rhodium Liquid Carbon' script, which is located under the path *\Image-Line\FL Studio 21\Plugins\Fruity\Effects\ZGameEditor Visualizer\Effects\Scenes. I discovered that editing and saving these files takes effect immediately in ZGameEditor, which is very helpful. However, with practically zero knowledge of programming or advanced maths, I have not been able to achieve the desired result.
 
Rhodium Liquid Carbon.png
 
Specifically, I want the band to rotate in one direction indefinitely, whereas by default it will reverse the rotation within a minute or so.
 

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" RenderPasses="2" FileVersion="2">
  <OnLoaded>
    <ZLibrary Comment="HSV Library">
      <Source>
<![CDATA[vec3 hsv(float h, float s, float v)
{
  s = clamp(s/100, 0, 1);
  v = clamp(v/100, 0, 1);

  if(!s)return vector3(v, v, v);

  h = h < 0 ? frac(1-abs(frac(h/360)))*6 : frac(h/360)*6;

  float c, f, p, q, t;

  c = floor(h);
  f = h-c;

  p = v*(1-s);
  q = v*(1-s*f);
  t = v*(1-s*(1-f));

  switch(c)
  {
    case 0: return vector3(v, t, p);
    case 1: return vector3(q, v, p);
    case 2: return vector3(p, v, t);
    case 3: return vector3(p, q, v);
    case 4: return vector3(t, p, v);
    case 5: return vector3(v, p, q);
  }
}]]>
      </Source>
    </ZLibrary>
  </OnLoaded>
  <OnUpdate>
    <ZExpression>
      <Expression>
<![CDATA[const int
  ALPHA = 0,
  HUE = 1,
  SATURATION = 2,
  LIGHTNESS = 3;

vec3 c=hsv(Parameters[HUE]*360,Parameters[SATURATION]*100,(1-Parameters[LIGHTNESS])*100);

ShaderColor.r=c.r;
ShaderColor.g=c.g;
ShaderColor.b=c.b;]]>
      </Expression>
    </ZExpression>
  </OnUpdate>
  <OnRender>
    <ZExpression>
      <Expression>
<![CDATA[if(App.CurrentRenderPass==0) {
  @SetRenderTarget(RenderTarget:FirstPassTarget);
  @UseMaterial(Material:ScreenMaterial);
} else {
  @SetRenderTarget(RenderTarget:null);
  @UseMaterial(Material:PostMaterial);
}
@RenderSprite();]]>
      </Expression>
    </ZExpression>
  </OnRender>
  <Content>
    <Group>
      <Children>
        <Array Name="Parameters" SizeDim1="10" Persistent="255">
          <Values>
<![CDATA[78DA6360606098F75EDD9681A1C19E0102EC91B1B1B1B13D480E006FA80544]]>
          </Values>
        </Array>
        <Constant Name="ParamHelpConst" Type="2">
          <StringValue>
<![CDATA[Alpha
Hue
Saturation
Lightness
Focus
Background
Flameinten
Refract
Twirl
Noise]]>
          </StringValue>
        </Constant>
        <Constant Name="AuthorInfo" Type="2">
          <StringValue>
<![CDATA[Jochen Feldkoetter
http://www.soundcloud.com/virgill
Adapted from https://www.shadertoy.com/view/llK3Dy]]>
          </StringValue>
        </Constant>
      </Children>
    </Group>
    <Material Name="ScreenMaterial" Shading="1" Light="0" ZBuffer="0" Shader="ScreenShader"/>
    <Shader Name="ScreenShader">
      <VertexShaderSource>
<![CDATA[varying vec2 position;

void main(){
  vec4 vertex = gl_Vertex;
  vertex.xy *= 2.0;
  gl_Position = vertex;
  position=vec2(vertex.x,vertex.y);
}]]>
      </VertexShaderSource>
      <FragmentShaderSource>
<![CDATA[uniform float iGlobalTime;
uniform float resX;
uniform float resY;
uniform float viewportX;
uniform float viewportY;
uniform vec3 pColor;

uniform float pFocus;
uniform float pBackground;
uniform float pFlameinten;
uniform float pRefract;
uniform float pTwirl;
uniform float pNoise;

uniform sampler2D tex1;
#define iChannel0 tex1

vec2 iResolution = vec2(resX,resY);

// ***********************************************************
// Alcatraz / Rhodium 4k Intro liquid carbon
// by Jochen "Virgill" Feldkötter
//
// 4kb executable: http://www.pouet.net/prod.php?which=68239
// Youtube: https://www.youtube.com/watch?v=YK7fbtQw3ZU
// ***********************************************************

// Params (Looking good with values from 0.00 - 1.00)

// Colors
#define p_col_r 		pColor.r //1.00
#define p_col_g 		pColor.g //0.25
#define p_col_b 		pColor.b //0.00

// Rendering
#define p_focus 		pFocus //0.50
#define p_background pBackground //0.50
#define p_flameinten pFlameinten //0.50
#define p_refract   pRefract //0.50

// Object
#define p_twirl 		pTwirl //0.70
#define p_noise 		pNoise //1.00

float time=iGlobalTime;
vec3 res=vec3(iResolution.xy,0);

float bounce=abs(fract(0.05*time)-.5)*20.; // triangle function

// signed box
float sdBox(vec3 p,vec3 b)
{
  vec3 d=abs(p)-b;
  return min(max(d.x,max(d.y,d.z)),0.)+length(max(d,0.));
}

// rotation
void pR(inout vec2 p,float a)
{
	p=cos(a)*p+sin(a)*vec2(p.y,-p.x);
}

// 3D noise function (IQ)
float noise(vec3 p)
{
	vec3 ip=floor(p);
    p-=ip;
    vec3 s=vec3(7,157,113);
    vec4 h=vec4(0.,s.yz,s.y+s.z)+dot(ip,s);
    p=p*p*(3.-2.*p);
    h=mix(fract(sin(h)*43758.5),fract(sin(h+s.x)*43758.5),p.x);
    h.xy=mix(h.xz,h.yw,p.y);
    return mix(h.x,h.y,p.z);
}

float map(vec3 p)
{
	p.z-=1.0;
    p*=0.9;
    pR(p.yz,bounce*1.+0.4*p.x*(p_twirl+0.3));
    return sdBox(p+vec3(0,sin(1.6*time),0),vec3(20.0, 0.05, 1.2))-.4*noise(8.*p+3.*bounce)*p_noise;
}

//	normal calculation
vec3 calcNormal(vec3 pos)
{
    float eps=0.0001;
	float d=map(pos);
	return normalize(vec3(map(pos+vec3(eps,0,0))-d,map(pos+vec3(0,eps,0))-d,map(pos+vec3(0,0,eps))-d));
}


// 	standard sphere tracing inside and outside
float castRayx(vec3 ro,vec3 rd)
{
    float function_sign=(map(ro)<0.)?-1.:1.;
    float precis=.0001;
    float h=precis*2.;
    float t=0.;
	for(int i=0;i<120;i++)
	{
        if(abs(h)<precis||t>12.)break;
		h=function_sign*map(ro+rd*t);
        t+=h;
	}
    return t;
}

// 	refraction
float refr(vec3 pos,vec3 lig,vec3 dir,vec3 nor,float angle,out float t2, out vec3 nor2)
{
    float h=0.;
    t2=2.;
	vec3 dir2=refract(dir,nor,angle);
 	for(int i=0;i<50;i++)
	{
		if(abs(h)>3.) break;
		h=map(pos+dir2*t2);
		t2-=h;
	}
    nor2=calcNormal(pos+dir2*t2);
    return(.5*clamp(dot(-lig,nor2),0.,1.)+pow(max(dot(reflect(dir2,nor2),lig),0.),8.));
}

//	softshadow
float softshadow(vec3 ro,vec3 rd)
{
    float sh=1.;
    float t=.02;
    float h=.0;
    for(int i=0;i<22;i++)
	{
        if(t>20.)continue;
        h=map(ro+rd*t);
        sh=min(sh,4.*h/t);
        t+=h;
    }
    return sh;
}

//	main function
void main()
{
	vec2 uv=(gl_FragCoord.xy-vec2(viewportX,viewportY))/res.xy;
    vec2 p=uv*2.-1.;

// 	bouncy cam every 10 seconds
    //float wobble=(fract(.1*(time-1.))>=0.9)?fract(-time)*0.1*sin(30.*time):0.;
    float wobble =0.;

//  camera
    vec3 dir = normalize(vec3(2.*(gl_FragCoord.xy-vec2(viewportX,viewportY)) -res.xy, res.y));
    vec3 org = vec3(0,2.*wobble,-3.);


// 	standard sphere tracing:
    vec3 color = vec3(0.);
    vec3 color2 =vec3(0.);
    float t=castRayx(org,dir);
	vec3 pos=org+dir*t;
	vec3 nor=calcNormal(pos);

// 	lighting:
    vec3 lig=normalize(vec3(.2,6.,.5));
//	scene depth
    float depth=clamp((1.-0.09*t),0.,1.);

    vec3 pos2 = vec3(0.);
    vec3 nor2 = vec3(0.);
    if(t<12.0)
    {
    	color2 = vec3(max(dot(lig,nor),0.)  +  pow(max(dot(reflect(dir,nor),lig),0.),16.));
    	color2 *=clamp(softshadow(pos,lig),0.,1.);  // shadow
       	float t2;
		color2.rgb +=refr(pos,lig,dir,nor,0.9, t2, nor2)*depth;
        color2-=clamp(.1*t2,0.,1.);				// inner intensity loss

	}


    float tmp = 0.;
    float T = 1.;

//	animation of glow intensity
    float intensity = (0.1*-sin(.209*time+1.)+0.05)+0.1*(p_flameinten-0.5);
	for(int i=0; i<128; i++)
	{
        float density = 0.; float nebula = noise(org);
        density=intensity-map(org+nor2*p_refract)*nebula;
		if(density>0.)
		{
			tmp = density / 128.;
            T *= 1. -tmp * 100.;
			if( T <= 0.) break;
		}
		org += dir*0.078;
    }
	vec3 basecol=vec3(p_col_r ,  p_col_g , p_col_b);
    T=clamp(T,0.,1.5);
    color += basecol* exp(4.*(0.5-T) - 0.8);
    color2*=depth;
    color2+= (1.-depth)*noise(6.*dir+0.3*time)*.2*p_background;	// subtle mist


//	scene depth included in alpha channel
    gl_FragColor = vec4(vec3(1.*color+0.8*color2)*1.3,abs(0.67-depth)*4.*p_focus);
}]]>
      </FragmentShaderSource>
      <UniformVariables>
        <ShaderVariable VariableName="iGlobalTime" ValuePropRef="App.Time"/>
        <ShaderVariable VariableName="resX" Value="1163" ValuePropRef="App.ViewportWidth"/>
        <ShaderVariable VariableName="resY" Value="432" ValuePropRef="App.ViewportHeight"/>
        <ShaderVariable VariableName="viewportX" Value="262" ValuePropRef="App.ViewportX"/>
        <ShaderVariable VariableName="viewportY" Value="262" ValuePropRef="App.ViewportY"/>
        <ShaderVariable VariableName="pColor" VariableRef="ShaderColor"/>
        <ShaderVariable VariableName="pFocus" ValuePropRef="Parameters[4];"/>
        <ShaderVariable VariableName="pBackground" ValuePropRef="Parameters[5];"/>
        <ShaderVariable VariableName="pFlameinten" ValuePropRef="Parameters[6];"/>
        <ShaderVariable VariableName="pRefract" ValuePropRef="Parameters[7];"/>
        <ShaderVariable VariableName="pTwirl" ValuePropRef="Parameters[8];"/>
        <ShaderVariable VariableName="pNoise" ValuePropRef="Parameters[9];"/>
      </UniformVariables>
    </Shader>
    <Variable Name="ShaderColor" Type="7"/>
    <Shader Name="PostShader">
      <VertexShaderSource>
<![CDATA[varying vec2 position;

void main(){
  vec4 vertex = gl_Vertex;
  vertex.xy *= 2.0;
  gl_Position = vertex;
  position=vec2(vertex.x,vertex.y);
}]]>
      </VertexShaderSource>
      <FragmentShaderSource>
<![CDATA[// ***********************************************************
// Alcatraz / Rhodium 4k Intro liquid carbon
// by Jochen "Virgill" Feldkötter
//
// 4kb executable: http://www.pouet.net/prod.php?which=68239
// Youtube: https://www.youtube.com/watch?v=YK7fbtQw3ZU
// ***********************************************************
uniform float resX;
uniform float resY;
uniform float viewportX;
uniform float viewportY;
uniform float size;
uniform vec2 pos;
uniform float Alpha;

uniform sampler2D tex1;
#define iChannel0 tex1

vec2 iResolution = vec2(resX,resY);

vec3 res = vec3(iResolution.xy,0);

float GA =2.399;
mat2 rot = mat2(cos(GA),sin(GA),-sin(GA),cos(GA));

// 	simplyfied version of Dave Hoskins blur
vec3 dof(sampler2D tex,vec2 uv,float rad)
{
	vec3 acc=vec3(0);
    vec2 pixel=vec2(.002*res.y/res.x,.002),angle=vec2(0,rad);;
    rad=1.;
	for (int j=0;j<80;j++)
    {
        rad += 1./rad;
	    angle*=rot;
        vec4 col=texture2D(tex,uv+pixel*(rad-1.)*angle);
		acc+=col.xyz;
	}
	return acc/80.;
}

//-------------------------------------------------------------------------------------------
void main()
{
	vec2 uv = (gl_FragCoord.xy-vec2(viewportX,viewportY)) / res.xy;
	gl_FragColor=vec4(dof(iChannel0,uv,texture2D(iChannel0,uv).w),Alpha);
}]]>
      </FragmentShaderSource>
      <UniformVariables>
        <ShaderVariable VariableName="resX" Value="1163" ValuePropRef="App.ViewportWidth"/>
        <ShaderVariable VariableName="resY" Value="432" ValuePropRef="App.ViewportHeight"/>
        <ShaderVariable VariableName="viewportX" Value="262" ValuePropRef="App.ViewportX"/>
        <ShaderVariable VariableName="viewportY" Value="262" ValuePropRef="App.ViewportY"/>
        <ShaderVariable VariableName="Alpha" ValuePropRef="1-Parameters[0];"/>
      </UniformVariables>
    </Shader>
    <Material Name="PostMaterial" Shading="1" Light="0" Blend="1" ZBuffer="0" Shader="PostShader">
      <Textures>
        <MaterialTexture RenderTarget="FirstPassTarget" TexCoords="1"/>
      </Textures>
    </Material>
    <RenderTarget Name="FirstPassTarget" Width="0" Height="0"/>
  </Content>
</ZApplication>
 
Any ideas?
You do not have the required permissions to view the files attached to this post.
Last edited by Zephyrean on Wed Feb 08, 2023 5:18 am, edited 2 times in total.

Kjell
Tue Feb 07, 2023 6:11 pm

x

Re: Need some help with this script

Zephyrean wrote:
Mon Feb 06, 2023 9:06 am
Any ideas?
Not entirely sure what you mean with "I want the rotating band to cycle in one direction indefinitely" but i suspect you want to get rid of what "bounce" does in the shader. You can use any text editor to do this ( especially when it's a small change ), but in most cases i recommend using ZGameEditor.

Take the following steps:

- Install ZGameEditor ( which is only a 4MB download ).
- In "Tools > Settings" make sure .zgeproj file association is enabled.

Image

- In FL Studio right-click on the effect that you want to edit and select "Edit effect with ZGameEditor".

Image

- Select the "ScreenShader" component in the Project Tree and click on the FragmentShaderSource edit box in Properties to edit the code.
- Replace line 48 with "float bounce=time;".

Image

- Press the Compile button to recompile the shader.
- Once you're happy with your changes save the current file and the effect will automatically reload in FL Studio.

Zephyrean
Wed Feb 08, 2023 5:33 am

x

Re: Need some help with this script

Kjell wrote:
Tue Feb 07, 2023 6:11 pm
- Replace line 48 with "float bounce=time;".
This seemed to do the trick. But it broke something else in the code, which causes the noise pattern to become uniform after 2 minutes... :?
 
after2minutes.png
You do not have the required permissions to view the files attached to this post.

Kjell
Wed Feb 08, 2023 9:55 pm

x

Re: Need some help with this script

Zephyrean wrote:
Wed Feb 08, 2023 5:33 am
This seemed to do the trick. But it broke something else in the code, which causes the noise pattern to become uniform after 2 minutes.
Strange .. i haven't been able to reproduce this issue on my computer. You could try changing line 48 to "float bounce=mod(time, 6.2831853);" to see if that solves it for you.

Zephyrean
Thu Feb 09, 2023 7:47 am

x

Re: Need some help with this script

Kjell wrote:
Wed Feb 08, 2023 9:55 pm
You could try changing line 48 to "float bounce=mod(time, 6.2831853);" to see if that solves it for you.
This did resolve the issue of the noise pattern becoming uniform, and the band is rotating indefinitely in one direction, as desired. But now there is a skip in the animation every 14 seconds or so, which kind of looks like a frame-drop. I rendered out a video to verify that it was not my computer, and the skip in the animation is indeed evident at the specific intervals.

Kjell
Thu Feb 09, 2023 12:28 pm

x

Re: Need some help with this script

Zephyrean wrote:
Thu Feb 09, 2023 7:47 am
I rendered out a video to verify that it was not my computer, and the skip in the animation is indeed evident at the specific intervals.
I rendered out a video myself and i don't see the problem you're describing. Another thing you could try is reverting back to "float bounce=time;" and adding the following two lines at the very top of the fragment shader.

Code: Select all

#version 130
precision highp float;

Zephyrean
Thu Feb 09, 2023 5:02 pm

x

Re: Need some help with this script

Kjell wrote:
Thu Feb 09, 2023 12:28 pm
Another thing you could try is reverting back to "float bounce=time;" and adding the following two lines at the very top of the fragment shader.

Code: Select all

#version 130
precision highp float;
Followed these steps, and this time in ZGameEditor, but the result is still the same. :?

Image
Image


Return to “ZGameEditor Visualizer Script Reference”