Author Topic: Phosphor retention effect  (Read 328 times)

Oomek

  • Sr. Member
  • ****
  • Posts: 239
    • View Profile
Phosphor retention effect
« on: October 07, 2018, 05:24:26 AM »
I've just come up with an idea of how to make a phosphor retention effect in Attract Mode by accident during my experiments.
It's possible by exploiting the one frame delay of surfaces and making a feedback loop between 2 surfaces.
Maybe someone will find a use for it.

layout.nut
Code: [Select]
local flw = fe.layout.width
local flh = fe.layout.height

local su = []
local sh = []
local width = flw /2.0
local height = flh /1.0
local retention = 0.95

su.push( fe.add_surface( width, height ))
su.push( fe.add_surface( width, height ))

local snap = su[0].add_artwork("snap", 0, 0, width, height )

sh.push( fe.add_shader( Shader.Fragment, "shader.frag" ))
sh.push( fe.add_shader( Shader.Fragment, "shader.frag" ))

snap = su[1].add_clone( snap )
sh[0].set_texture_param( "texold", su[0] )
sh[0].set_param( "retention", retention )
snap.shader = sh[0]

snap = su[0].add_clone( snap )
sh[1].set_texture_param( "texold", su[1] )
sh[1].set_param( "retention", retention )
snap.shader = sh[1]

su[0].set_pos( flw / 2.0, flh / 2.0 )
su[0].origin_x = su[0].width / 2.0
su[0].origin_y = su[0].height / 2.0
su[1].visible = false

shader.frag
Code: [Select]
uniform sampler2D texture;
uniform sampler2D texold;
uniform float retention;

void main()
{
    vec4 pixel;
    vec4 pixelold;
vec2 uv = gl_TexCoord[0];
vec2 uvo = gl_TexCoord[0];
uvo.y = 1.0 - uvo.y;
pixel = texture2D( texture, uv );
pixelold = texture2D( texold, uvo );
pixel = max( pixel, pixelold * retention );
    gl_FragColor = gl_Color * pixel;
}

Oomek

  • Sr. Member
  • ****
  • Posts: 239
    • View Profile
Re: Phosphor retention effect
« Reply #1 on: October 07, 2018, 05:53:12 AM »
Here's a sample video:
https://youtu.be/prWnEQ0Da9s

jedione

  • Hero Member
  • *****
  • Posts: 565
  • punktoe
    • View Profile
Re: Phosphor retention effect
« Reply #2 on: October 07, 2018, 06:45:23 AM »
looks like acid trails cool
help a friend....

Luke_Nukem

  • Sr. Member
  • ****
  • Posts: 137
    • View Profile
    • LukeNukem
Re: Phosphor retention effect
« Reply #3 on: October 07, 2018, 09:09:56 PM »
I had a play with the technique. Results are interesting but not pretty... Easy to see intended effect with Asteroids or Pacman videos.
« Last Edit: October 07, 2018, 09:11:27 PM by Luke_Nukem »
Twitter: @RustDevLuke

Oomek

  • Sr. Member
  • ****
  • Posts: 239
    • View Profile
Re: Phosphor retention effect
« Reply #4 on: October 08, 2018, 01:18:43 AM »
My intention was to only show how can you get a previous frame and use it in the shader. What you will build on top of that is up to you.

zpaolo11x

  • Sr. Member
  • ****
  • Posts: 224
    • View Profile
Re: Phosphor retention effect
« Reply #5 on: October 08, 2018, 01:30:17 AM »
My intention was to only show how can you get a previous frame and use it in the shader. What you will build on top of that is up to you.

This is very interesting... I'm thinking of a way to use it to do double pass shaders (without using nested surfaces that is), do you think it's possible? The stuff you can do with surfaces is amaznig :)