~npisanti/rsk_tools

2764c64a8c13dfbee83a70b5f45772b5a0392911 — Nicola Pisanti 4 months ago
ported to raylyeh
A  => .gitignore +7 -0
@@ 1,7 @@

/framescan/output/*
/cereal/input/*
/cereal/output/*
/*/*.png
/tilecutter/output/*.png
	
\ No newline at end of file

A  => cereal/main.lua +51 -0
@@ 1,51 @@

require "strict"

local index = 0 

----------------------------------------------------

window.title( "cereal" )

print( "loading folders..." )
png.load( "input" )
png.select( "input" )
index = png.size()

frag.load( "process.frag" ) 

window.size( png.width(), png.height() )
layer.create( "def" );

local clock = 0

----------------------------------------------------
function loop()
	png.select( "input" )
	--png.align_corner()
	
    layer.open()
    	rl.clear( 0, 0, 0, 0 )
    	rl.color( 255, 255, 255, 255 )
		png.draw( 0, 0 )
    layer.close() 

   	frag.apply( "process" )

	if index == png.size() then
		if clock == 0 then 
			png.next()
			clock = 10
		end
		clock = clock - 1 
	else
		local filename = "output/frame_"..tostring(index)..".png"
		layer.save( filename )	
		index = index+1 
		png.frame( index )
	end 

	if key.pressed( key.space ) then 
		index = 0
	end 
end

A  => cereal/process.frag +27 -0
@@ 1,27 @@
#version 100

#ifdef GL_ES
precision highp float;
#endif

varying vec2 st;
uniform sampler2D texture0;
uniform float time;

void main(){

	vec2 stl = st;
	stl.x += 0.4;
	
    vec4 source = texture2D( texture0, stl ); // for texture access
    vec3 color = source.rgb;
    float luminance = color.r*0.299 + color.g*0.587 + color.b*0.114;	

    float low = 0.15;
    float high = 0.45;
    
    float alpha = smoothstep( low, high, luminance );
    
    gl_FragColor = vec4( vec3(alpha), 1.0 );
    // gl_FragColor = vec4( 1.0, 1.0, 1.0, alpha );
}

A  => eye/main.lua +48 -0
@@ 1,48 @@

require "strict"

----------------------------------------------------
---- settings ---- 
local camw = 640
local camh = 480 

---- variables ----
local numsaved = 0
local freeze = 0

window.title( "eye" )
window.size( camw, camh)
layer.create("def")

local device = "/dev/video0"

if args.count() > 0 then 
	device = args.get(0)
end

cam.open(device, camw, camh )

frag.load( "process.frag" ) 

----------------------------------------------------
function loop()
	freeze = freeze + 1
	if freeze > 0 then 
	
	    layer.open()
	    	rl.clear(0,0,0,0)
			cam.draw( 0, 0 )
	    layer.close() 
	
	   	frag.apply( "process" )
	end

	if key.pressed( key.space ) then
		local filename = "output_"..tostring(numsaved)..".png"
		layer.select("default")
		layer.save( filename )
		freeze = -40
		numsaved = numsaved + 1
		print( filename )
	end
end

A  => eye/process.frag +26 -0
@@ 1,26 @@
#version 100

#ifdef GL_ES
precision highp float;
#endif

varying vec2 st;
uniform sampler2D texture0;

void main(){
    
    //st.x = 1.0-st.x; // flip horizontally 
    //st.y = 1.0-st.y;  // flip vertically 

    vec4 source = texture2D( texture0, st ); // for texture access
    vec3 color = source.rgb;
    float luminance = color.r*0.299 + color.g*0.587 + color.b*0.114;	

    float low = 0.15;
    float high = 0.45;
    
    float alpha = smoothstep( low, high, luminance );
    
    gl_FragColor = vec4( vec3(alpha), 1.0 );
    // gl_FragColor = vec4( 1.0, 1.0, 1.0, alpha );
}

A  => framescan/main.lua +211 -0
@@ 1,211 @@

require "strict"

--[[
	KEYS:
		wasd/arrows = move tile
		q/l = lock webcam 
		\1234 = preview modes 
		e/spacebar = acquire 
--]]

local tilew = 200
local tileh = 200

local scale = 0.75

local threshold = 0.5
local smooth = 0.1

local camw = 1280 
local camh = 720
local camdev = "/dev/video0"

-- variables --------
local numsaved = 0
local cx = 0
local cy = 0
local lock_cam = false
local preview = 0
local framemem = 0
local clock = 0

----------------------------------------------------
window.title( "framescan" )

cam.open( camdev, camw, camh)
cx = (camw-tilew) / 2
cy = (camh-tileh) / 2

frag.load( "process.frag" ) 

png.load( "output/", "output" )
png.select("output")
numsaved = png.size()

local canvash = camh*scale 
local tile2 = tileh*2 + 40 
if tile2>canvash then 
	canvash = tile2
end

window.size( camw*scale + 40 + tilew, camh*scale + 20 )
layer.create( "default", camw*scale + 20 + tilew, canvash ) 
layer.create( "cam", camw, camh ) 
	layer.hide()
layer.create( "cut", tilew, tileh )
	layer.hide()

----------------------------------------------------
function loop()
	png.align_corner() 
	png.select( "output" )	

	if not lock_cam then 
		layer.select("cam")
		layer.open()
			rl.color( 255, 255, 255, 255 )
			cam.draw( 0, 0 )
		layer.close()
	end

    frag.select( "process" )
        frag.uniform( "u_low", threshold )
        frag.uniform( "u_high", threshold + smooth )
    frag.apply( "process") 

	layer.select("cut")
	layer.open()
		rl.push()
			rl.clear( 0, 0, 0, 0 )
			rl.translate( -cx, -cy ) 
			rl.color( 255, 255, 255, 255 )
			layer.pipe( "cam" )	
		rl.pop()
	layer.close()

	layer.select("default")
	layer.open()
		rl.clear( 0, 0, 0, 0 )
		rl.push()
		rl.scale( scale, scale ) 
			layer.pipe( "cam" )
			--cam.draw( 0, 0 )
			overlay( cx, cy, tilew, tileh )
		rl.pop()

		rl.push()
			rl.translate( camw*scale + 20, 20 )

			rl.color(255,255,255, 255)

			if png.size() ~= 0 then
				if preview == 0 then 
					layer.pipe( "cut" )
				elseif preview == 1 then 
					png.frame( 0 )
					png.draw( 0, 0 )
				elseif preview == 2 then 
					png.frame( png.size()-1 )
					png.draw( 0, 0 )	
				elseif preview == 3 then 
					layer.pipe( "cut" )
					rl.blend_additive()
					rl.color(255,0,0, 255)
					png.frame( 0 )
					png.draw( 0, 0 )
				elseif preview == 4 then
					layer.pipe( "cut" )
					png.frame( png.size()-1 )
					rl.blend_additive()
					rl.color(255,0,0, 255)
					png.draw( 0, 0 )
				end
				png.frame( framemem )
			end
			
			overlay( 0, 0, tilew, tileh )

			rl.blend_alpha()

			rl.push()
				rl.translate( 0, tileh+20 )
				rl.color(255,255,255, 255)

				if clock == 0 then 
					framemem = png.next()				
					clock = 10
				end
				clock = clock - 1
				png.draw( 0, 0 )
			rl.pop()		
		rl.pop()
	layer.close()	

	key_pressed()
end

----------------------------------------------------
function overlay( x, y, w, h )
	rl.push()
		rl.color( 255,0,0, 255 )
		rl.translate(x,y) 
		rl.rect( 1, 1, w-1, h-1 )
		rl.line( w/2, 0, w/2, h ) 
		rl.line( 0, h/2, w, h/2 ) 
	rl.pop()
end

function key_pressed()

	if key.pressed( key.q ) or key.pressed( key.l ) then
		lock_cam = not lock_cam
	end

	if key.pressed( key.e ) 
	or key.pressed( key.space )
	or key.pressed( key.c ) then
		local filename = "output/frame_"
		if numsaved<10 then 
			filename = filename.."00"
		elseif numsaved<100 then 
			filename = filename.."0"
		end
		filename = filename..tostring(numsaved)..".png"
		layer.select("cut")
		layer.save( filename )
		png.load( "output/", "output" )
		numsaved = numsaved + 1 
	end

	if key.is_down( key.n1 ) then
		preview = 1
	elseif key.is_down( key.n2 ) then
		preview = 2
	elseif key.is_down( key.n3 ) then
		preview = 3
	elseif key.is_down( key.n4 ) then
		preview = 4
	else 
		preview = 0
	end

	local faststep = 4
	if key.is_down( key.a ) then
		cx = cx-faststep
	elseif key.is_down( key.d ) then
		cx = cx+faststep
	elseif key.is_down( key.s ) then
		cy = cy+faststep
	elseif key.is_down( key.w ) then
		cy = cy-faststep
	elseif key.pressed( key.left ) then
		cx = cx-1
	elseif key.pressed( key.right ) then
		cx = cx+1
	elseif key.pressed( key.up ) then
		cy = cy-1
	elseif key.pressed( key.down ) then
		cy = cy+1
	end
end

A  => framescan/process.frag +27 -0
@@ 1,27 @@
#version 100

#ifdef GL_ES
precision highp float;
#endif

varying vec2 st;
uniform sampler2D texture0;
uniform float time;

uniform float u_low;
uniform float u_high;

void main(){
    vec2 stl = st;

	stl.x = 1.0 - st.x;
	stl.y = 1.0 - st.y;

    vec4 source = texture2D( texture0, stl ); 
    vec3 color = source.rgb;
    float luminance = color.r*0.299 + color.g*0.587 + color.b*0.114;	

    float alpha =  1.0 - smoothstep( u_low, u_high, luminance );

    gl_FragColor = vec4( vec3(1.0), alpha  );
}

A  => shader/main.lua +22 -0
@@ 1,22 @@

require "strict"

----------------------------------------------------

window.title( " " )

if args.count() > 0 then 
    frag.load( args.get(0), "glsl" ) 
end    

window.size( 480, 480 )
layer.create( "def" )

----------------------------------------------------
function loop()
    layer.open()
        rl.clear(0,0,0,0)
    layer.close() 

    frag.apply( "glsl" )
end

A  => shadercam/main.lua +43 -0
@@ 1,43 @@

require "strict"

-- settings ---------
local camw = 640
local camh = 480 

-- variables --------
local numsaved = 0
local freeze = 0

----------------------------------------------------

window.title( "" )
window.size( camw, camh )
layer.create( "def") 

frag.load( args.get(0), "glsl" )      

cam.open(args.get(1), camw, camh )

----------------------------------------------------
function loop()
	freeze = freeze + 1
	if freeze > 0 then 
	
	    layer.open()
	    	rl.clear(0,0,0,0)
			cam.draw( 0, 0 )
	    layer.close() 
	
	   	frag.apply( "glsl" )
	end

	if key.pressed( key.space ) then 
		local filename = "shadercam_output_"..tostring(numsaved)..".png"
		layer.select("def")
		layer.save( filename )
		freeze = -40
		numsaved = numsaved + 1
		print( filename )
	end 
end

A  => shaderdrop/main.lua +48 -0
@@ 1,48 @@

require "strict"

----------------------------------------------------
window.title( "" )
window.size( 480, 480 )
layer.create( "def" )

frag.load( args.get(0), "glsl" ) 

png.align_center()
png.load( "tests" )

local blackground = true
local clock = 60

----------------------------------------------------
function loop()
    frag.apply( "glsl" )

	png.select( "tests" );

	if clock == 60 then 
		if blackground then 
	    	layer.open()
		        rl.clear( 0, 0, 0, 0 )
		        rl.color( 255, 255, 255, 255 ) 
		        png.draw( window.width()*0.5, window.height()*0.5 )
		        png.next()
		  	layer.close()	
		else 
	    	layer.open()
		        rl.clear( 255, 255, 255, 255 )
		        rl.color( 0 ) 
		        png.draw( window.width()*0.5, window.height()*0.5 )
		        png.next()
		    layer.close()	
		end 
		clock = 0
	end 

	clock = clock + 1 

	if( key.pressed( key.space ) )then 
		blackground = not blackground;
	end
end


A  => shaderdrop/tests/.gitkeep +0 -0

A  => shaderdrop/tests/frame_002.png +0 -0

A  => shaderdrop/tests/frame_003.png +0 -0

A  => shaderdrop/tests/frame_004.png +0 -0

A  => tilecutter/main.lua +103 -0
@@ 1,103 @@

require "strict"

local tilew = 150
local tileh = 150

local scale = 0.5

local threshold = 0.4
local smooth = 0.05

-- variables --------
local numsaved = 0
local cx = 0
local cy = 0

----------------------------------------------------
png.load( "input.png" ) 
png.select( "input" )

frag.load( "process.frag" ) 

window.title( "tilecutter" )
window.size( png.width()*scale + 40 + tilew, png.height()*scale + 20 )
layer.create( "image", png.width()*scale + 20 + tilew, png.height()*scale ) 
layer.create( "cut", tilew, tileh )
	layer.hide()

----------------------------------------------------
function loop()
	png.select( "input" )
	png.align_corner() 

	layer.select("cut")
	layer.open()
		rl.color( 255, 255, 255, 255 )
		--px.clear( 255, 0, 0, 255 )
		png.draw( -cx, -cy ) 
	layer.close()

    frag.select( "process" )
        frag.uniform( "u_low", threshold )
        frag.uniform( "u_high", threshold + smooth )
    frag.apply()

	layer.select("image")
	layer.open()
		rl.clear( 0, 0, 0, 0 )
		rl.push()
			rl.scale( scale, scale ) 
			png.draw( 0, 0 ) 
			overlay( cx, cy, tilew, tileh )
		rl.pop()

		rl.push()
			rl.translate( png.width()*scale + 20, 20 )
			rl.color(255, 255, 255, 255)
			layer.pipe( "cut" )
			overlay( 0, 0, tilew, tileh )
		rl.pop()
	layer.close()	

	key_pressed()
end

----------------------------------------------------
function overlay( x, y, w, h )
	rl.push()
		rl.color( 255, 0, 0, 255 )
		rl.translate( x, y ) 
		rl.rect( 1, 1, w-1, h-1 )
		rl.line( w/2, 0, w/2, h ) 
		rl.line( 0, h/2, w, h/2 ) 
	rl.pop()
end

function key_pressed()
	local faststep = 4
	
	if key.is_down( key.a ) then
		cx = cx-faststep
	elseif key.is_down( key.d ) then
		cx = cx+faststep
	elseif key.is_down( key.s ) then
		cy = cy+faststep
	elseif key.is_down( key.w ) then
		cy = cy-faststep
	elseif key.pressed( key.left ) then
		cx = cx-1
	elseif key.pressed( key.right ) then
		cx = cx+1
	elseif key.pressed( key.up ) then
		cy = cy-1
	elseif key.pressed( key.down ) then
		cy = cy+1
	elseif key.pressed( key.c ) or key.pressed( key.space ) then
		local filename = "output/frame_"..tostring(numsaved)..".png"
		layer.select("cut")
		layer.save( filename )
		numsaved = numsaved + 1
		print( filename )
	end
end

A  => tilecutter/output/.gitkeep +0 -0

A  => tilecutter/process.frag +26 -0
@@ 1,26 @@
#version 100

#ifdef GL_ES
precision highp float;
#endif

varying vec2 st;
uniform sampler2D texture0;
uniform float time;

uniform float u_low;
uniform float u_high;

void main(){

    vec4 source = texture2D( texture0, st ); // for texture access
    vec3 color = source.rgb;
    float luminance = color.r*0.299 + color.g*0.587 + color.b*0.114;	

//    float alpha = 1.0 - smoothstep( u_low, u_high, luminance );

    float alpha = step( luminance, 0.2 );
    
    //gl_FragColor = vec4( vec3(alpha), 1.0  );
    gl_FragColor = vec4( vec3(1.0), alpha  );
}