isf

package
v0.0.0-...-28f6ca2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 19, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RadToDeg = 180 / math.Pi
	DegToRad = math.Pi / 180
)

RadToDeg and DegToRad are conversion factors

Variables

View Source
var DebugISF = true

DebugISF xxx

View Source
var DebugShader = false

DebugShader xxx

View Source
var DefaultFragmentShader = `
#version 330

uniform sampler2D tex;
uniform vec2 tjt;

in vec2 fragTexCoord;
in vec4 finalcolor;
in vec2 finaldebug;
in vec2 finaltjt;

out vec4 outputColor;

void main() {
	outputColor = finalcolor;
	// if ( finaldebug.x < 0.5 ) {
	// 	outputColor = texture(tex, fragTexCoord);
	// } else if ( finaldebug.x > 0.5 ) {
		outputColor.r = 0.0;
		outputColor.g = 0.8;
		outputColor.b = 0.0;
	outputColor = texture(tex, fragTexCoord);
	outputColor.r = 1.0;
	// }
}
` + "\x00"

DefaultFragmentShader xxx

View Source
var DefaultVertexShader = `
#version 330

uniform mat4 projection;
uniform vec4 color;
uniform vec4 misc;
uniform vec2 debug;

in vec3 vert;
in vec2 vertTexCoord;

out vec2 fragTexCoord;
out vec4 finalcolor;
out vec4 finalvert;
out int finaltype;
out vec2 finaldebug;

vec3 hsl2rgb( in vec3 c )
{
    vec3 rgb = clamp( abs(mod(c.x*6.0+vec3(0.0,4.0,2.0),6.0)-3.0)-1.0, 0.0, 1.0 );

    return c.z + c.y * (rgb-0.5)*(1.0-abs(2.0*c.z-1.0));
}

vec3 HueShift (in vec3 Color, in float Shift)
{
    vec3 P = vec3(0.55735)*dot(vec3(0.55735),Color);
    
    vec3 U = Color-P;
    
    vec3 V = cross(vec3(0.55735),U);    

    Color = U*cos(Shift*6.2832) + V*sin(Shift*6.2832) + P;
    
    return vec3(Color);
}

vec3 rgb2hsl( in vec3 c ){
  float h = 0.0;
	float s = 0.0;
	float l = 0.0;
	float r = c.r;
	float g = c.g;
	float b = c.b;
	float cMin = min( r, min( g, b ) );
	float cMax = max( r, max( g, b ) );

	l = ( cMax + cMin ) / 2.0;
	if ( cMax > cMin ) {
		float cDelta = cMax - cMin;
        
        //s = l < .05 ? cDelta / ( cMax + cMin ) : cDelta / ( 2.0 - ( cMax + cMin ) ); Original
		s = l < .0 ? cDelta / ( cMax + cMin ) : cDelta / ( 2.0 - ( cMax + cMin ) );
        
		if ( r == cMax ) {
			h = ( g - b ) / cDelta;
		} else if ( g == cMax ) {
			h = 2.0 + ( b - r ) / cDelta;
		} else {
			h = 4.0 + ( r - g ) / cDelta;
		}

		if ( h < 0.0) {
			h += 6.0;
		}
		h = h / 6.0;
	}
	return vec3( h, s, l );
}

vec3 rgb2hsv(vec3 c)
{
    vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
    vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
    vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));

    float d = q.x - min(q.w, q.y);
    float e = 1.0e-10;
    return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
}

vec3 hsv2rgb(vec3 c)
{
    vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
    vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
    return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}

void main() {

	float angle = misc.x;
	float invsize = 1.0 / misc.y;
	float size = misc.y;
	float x = misc.z;
	float y = misc.w;

	fragTexCoord = vertTexCoord;
	finalvert = vec4(size*vert.x,size*vert.y,vert.z,1);
	if (angle != 0.0) {
		mat4 rotation = mat4(mat2(
			cos(angle), -sin(angle),
			sin(angle), cos(angle)));
		finalvert = finalvert * rotation;
	}
	finalvert.x += x;
	finalvert.y += y;

	gl_Position = projection * finalvert;

	vec4 mycolor = vec4(hsl2rgb(vec3(color.x,color.y,color.z)), color.a);
	finalcolor = mycolor;
	finaltype = 1;
	finaldebug = debug;
}
` + "\x00"

DefaultVertexShader xxx

View Source
var FragmentShader2 = `
#version 330

uniform sampler2D tex;
uniform vec2 tjt;

in vec2 fragTexCoord;
in vec4 finalcolor;
in vec2 finaldebug;
in vec2 finaltjt;

out vec4 outputColor;

void main() {
	outputColor = finalcolor;
	// if ( finaldebug.x < 0.5 ) {
	// 	outputColor = texture(tex, fragTexCoord);
	// } else if ( finaldebug.x > 0.5 ) {
		outputColor.r = 0.0;
		outputColor.g = 0.0;
		outputColor.b = 0.8;
	outputColor = texture(tex, fragTexCoord);
	outputColor.g = 1.0;
	// }
}
` + "\x00"

FragmentShader2 xxx

View Source
var LineVerticesForLines = []float32{

	0.0, 0.0, 1.0, 0.0, 0.0,
	1.0, 0.0, 1.0, 1.0, 0.0,
}

LineVerticesForLines xxx

View Source
var LineVerticesForLines2 = []float32{

	0.0, 0.0, 1.0, 0.0, 0.0,
	1.0, 0.0, 1.0, 1.0, 0.0,
}

LineVerticesForLines2 xxx

View Source
var SquareVerticesForLines = []float32{

	-1.0, -1.0, 1.0, 0.0, 0.0,
	1.0, -1.0, 1.0, 1.0, 0.0,

	1.0, -1.0, 1.0, 1.0, 0.0,
	1.0, 1.0, 1.0, 1.0, 1.0,

	1.0, 1.0, 1.0, 1.0, 1.0,
	-1.0, 1.0, 1.0, 0.0, 1.0,

	-1.0, 1.0, 1.0, 0.0, 1.0,
	-1.0, -1.0, 1.0, 0.0, 0.0,
}

SquareVerticesForLines xxx

View Source
var SquareVerticesForLines2 = []float32{

	-1.0, -1.0, 1.0, 0.0, 0.0,
	1.0, -1.0, 1.0, 1.0, 0.0,

	1.0, -1.0, 1.0, 1.0, 0.0,
	1.0, 1.0, 1.0, 1.0, 1.0,

	1.0, 1.0, 1.0, 1.0, 1.0,
	-1.0, 1.0, 1.0, 0.0, 1.0,

	-1.0, 1.0, 1.0, 0.0, 1.0,
	-1.0, -1.0, 1.0, 0.0, 0.0,
}

SquareVerticesForLines2 xxx

View Source
var SquareVerticiesForTriangles = []float32{

	-1.0, -1.0, 1.0, 1.0, 0.0,
	1.0, -1.0, 1.0, 0.0, 0.0,
	-1.0, 1.0, 1.0, 1.0, 1.0,
	1.0, -1.0, 1.0, 0.0, 0.0,
	1.0, 1.0, 1.0, 0.0, 1.0,
	-1.0, 1.0, 1.0, 1.0, 1.0,
}

SquareVerticiesForTriangles xxx

View Source
var SquareVerticiesForTriangles2 = []float32{

	-1.0, -1.0, 1.0, 1.0, 0.0,
	1.0, -1.0, 1.0, 0.0, 0.0,
	-1.0, 1.0, 1.0, 1.0, 1.0,
	1.0, -1.0, 1.0, 0.0, 0.0,
	1.0, 1.0, 1.0, 0.0, 1.0,
	-1.0, 1.0, 1.0, 1.0, 1.0,
}

SquareVerticiesForTriangles2 xxx

View Source
var VertexShader2 = `
#version 330

uniform mat4 projection;
uniform vec4 color;
uniform vec4 misc;
uniform vec2 debug;

in vec3 vert;
in vec2 vertTexCoord;

out vec2 fragTexCoord;
out vec4 finalcolor;
out vec4 finalvert;
out int finaltype;
out vec2 finaldebug;

vec3 hsl2rgb( in vec3 c )
{
    vec3 rgb = clamp( abs(mod(c.x*6.0+vec3(0.0,4.0,2.0),6.0)-3.0)-1.0, 0.0, 1.0 );

    return c.z + c.y * (rgb-0.5)*(1.0-abs(2.0*c.z-1.0));
}

vec3 HueShift (in vec3 Color, in float Shift)
{
    vec3 P = vec3(0.55735)*dot(vec3(0.55735),Color);
    
    vec3 U = Color-P;
    
    vec3 V = cross(vec3(0.55735),U);    

    Color = U*cos(Shift*6.2832) + V*sin(Shift*6.2832) + P;
    
    return vec3(Color);
}

vec3 rgb2hsl( in vec3 c ){
  float h = 0.0;
	float s = 0.0;
	float l = 0.0;
	float r = c.r;
	float g = c.g;
	float b = c.b;
	float cMin = min( r, min( g, b ) );
	float cMax = max( r, max( g, b ) );

	l = ( cMax + cMin ) / 2.0;
	if ( cMax > cMin ) {
		float cDelta = cMax - cMin;
        
        //s = l < .05 ? cDelta / ( cMax + cMin ) : cDelta / ( 2.0 - ( cMax + cMin ) ); Original
		s = l < .0 ? cDelta / ( cMax + cMin ) : cDelta / ( 2.0 - ( cMax + cMin ) );
        
		if ( r == cMax ) {
			h = ( g - b ) / cDelta;
		} else if ( g == cMax ) {
			h = 2.0 + ( b - r ) / cDelta;
		} else {
			h = 4.0 + ( r - g ) / cDelta;
		}

		if ( h < 0.0) {
			h += 6.0;
		}
		h = h / 6.0;
	}
	return vec3( h, s, l );
}

vec3 rgb2hsv(vec3 c)
{
    vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
    vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
    vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));

    float d = q.x - min(q.w, q.y);
    float e = 1.0e-10;
    return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
}

vec3 hsv2rgb(vec3 c)
{
    vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
    vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
    return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}

void main() {

	float angle = misc.x;
	float invsize = 1.0 / misc.y;
	float size = misc.y;
	float x = misc.z;
	float y = misc.w;

	fragTexCoord = vertTexCoord;
	finalvert = vec4(size*vert.x,size*vert.y,vert.z,1);
	if (angle != 0.0) {
		mat4 rotation = mat4(mat2(
			cos(angle), -sin(angle),
			sin(angle), cos(angle)));
		finalvert = finalvert * rotation;
	}
	finalvert.x += x;
	finalvert.y += y;

	gl_Position = projection * finalvert;

	vec4 mycolor = vec4(hsl2rgb(vec3(color.x,color.y,color.z)), color.a);
	finalcolor = mycolor;
	finaltype = 1;
	finaldebug = debug;
}
` + "\x00"

VertexShader2 xxx

Functions

func FilePath

func FilePath(nm string) string

FilePath xxx

func FilePaths

func FilePaths(nm string) (string, string)

FilePaths returns the 2 ISF file paths for a given name

func RotdirValue

func RotdirValue(s string) int

RotdirValue xxx

func SpriteAdjustForAge

func SpriteAdjustForAge(s Sprite, age float32)

SpriteAdjustForAge updates a SpriteState's values to reflect a given age

Types

type Pipeline

type Pipeline struct {
	Name   string
	Width  int
	Height int
	// contains filtered or unexported fields
}

Pipeline xxx

func NewPipeline

func NewPipeline(name string, windowWidth int, windowHeight int, visible bool) (*Pipeline, error)

NewPipeline xxx

func (*Pipeline) AddVizlet

func (pl *Pipeline) AddVizlet(viz Vizlet)

AddVizlet xxx

func (*Pipeline) Do

func (pl *Pipeline) Do()

Do runs the pipeline once

func (*Pipeline) FirstVizlet

func (pl *Pipeline) FirstVizlet() Vizlet

FirstVizlet xxx

func (*Pipeline) GetVizlet

func (pl *Pipeline) GetVizlet(name string) Vizlet

GetVizlet xxx

func (*Pipeline) LastVizlet

func (pl *Pipeline) LastVizlet() Vizlet

LastVizlet xxx

type PlaybackEvent

type PlaybackEvent struct {
	// contains filtered or unexported fields
}

PlaybackEvent is a time-tagged cursor or API event

type Realtime

type Realtime struct {
	// contains filtered or unexported fields
}

Realtime takes events and routes them

func NewRealtime

func NewRealtime() (*Realtime, error)

NewRealtime xxx

func (*Realtime) Start

func (e *Realtime) Start()

Start starts any extra executable/cmdline that's needed, and then runs the looper and never returns

func (*Realtime) Time

func (e *Realtime) Time() time.Time

Time returns the current time

type Sprite

type Sprite interface {
	Draw(*glhf.Shader)
	ID() string
	SpriteState() *SpriteState
	SpriteParams() *SpriteParams
	AdjustForAge(age float32)
}

Sprite xxx

type SpriteLine

type SpriteLine struct {
	Sprite
	State  *SpriteState
	Params *SpriteParams
}

SpriteLine xxx

func NewSpriteLine

func NewSpriteLine(x, y, z float32, params *engine.ParamValues) *SpriteLine

NewSpriteLine xxx

func (*SpriteLine) Draw

func (s *SpriteLine) Draw(viz *VizletISF)

Draw xxx

func (*SpriteLine) SpriteParams

func (s *SpriteLine) SpriteParams() *SpriteParams

SpriteParams xxx

func (*SpriteLine) SpriteState

func (s *SpriteLine) SpriteState() *SpriteState

SpriteState xxx

type SpriteParams

type SpriteParams struct {
	// contains filtered or unexported fields
}

SpriteParams xxx

func NewSpriteParams

func NewSpriteParams(params *engine.ParamValues) *SpriteParams

NewSpriteParams xxx

type SpriteSquare

type SpriteSquare struct {
	Sprite
	State  *SpriteState
	Params *SpriteParams
}

SpriteSquare xxx

func NewSpriteSquare

func NewSpriteSquare(x, y, z float32, params *engine.ParamValues) *SpriteSquare

NewSpriteSquare xxx

func (*SpriteSquare) Draw

func (s *SpriteSquare) Draw(shader *glhf.Shader)

Draw xxx

func (*SpriteSquare) SpriteParams

func (s *SpriteSquare) SpriteParams() *SpriteParams

SpriteParams xxx

func (*SpriteSquare) SpriteState

func (s *SpriteSquare) SpriteState() *SpriteState

SpriteState xxx

type SpriteState

type SpriteState struct {
	NoAging bool // if true, the Sprite doesn't age
	// contains filtered or unexported fields
}

SpriteState xxx

type SpriteVector

type SpriteVector struct {
	// contains filtered or unexported fields
}

SpriteVector xxx

type Vizlet

type Vizlet interface {
	Name() string
	DoVizlet() error
	OutputTexture() *glhf.Texture
	SetSpoutIn(string)
	SetSpoutOut(string)
	SetInputFromVizlet(Vizlet)
	AddSprite(Sprite) // Eventually this should go elsewhere, when cursor handling gets put into Vizlet interface
	AgeSprites()      // Ditto, when Vizlet interface starts handling click advance
}

Vizlet xxx

func NewVizletDrawer

func NewVizletDrawer(name string, isfname string, frame *glhf.Frame) (Vizlet, error)

NewVizletDrawer xxx

func NewVizletISF

func NewVizletISF(name string, isfname string, frame *glhf.Frame) (Vizlet, error)

NewVizletISF xxx

type VizletDrawer

type VizletDrawer struct {
	Vizlet
	// contains filtered or unexported fields
}

VizletDrawer is one Drawer shader within a Pipeline

func (*VizletDrawer) AddSprite

func (viz *VizletDrawer) AddSprite(s Sprite)

AddSprite xxx

func (*VizletDrawer) AgeSprites

func (viz *VizletDrawer) AgeSprites()

AgeSprites xxx

func (*VizletDrawer) DoVizlet

func (viz *VizletDrawer) DoVizlet() error

DoVizlet xxx

func (*VizletDrawer) DrawSprites

func (viz *VizletDrawer) DrawSprites()

DrawSprites xxx

func (*VizletDrawer) Height

func (viz *VizletDrawer) Height() int

Height xxx

func (*VizletDrawer) Name

func (viz *VizletDrawer) Name() string

Name xxx

func (*VizletDrawer) OutputTexture

func (viz *VizletDrawer) OutputTexture() *glhf.Texture

OutputTexture xxx

func (*VizletDrawer) SetInputFromVizlet

func (viz *VizletDrawer) SetInputFromVizlet(from Vizlet)

SetInputFromVizlet xxx

func (*VizletDrawer) SetSpoutIn

func (viz *VizletDrawer) SetSpoutIn(spoutin string)

SetSpoutIn xxx

func (*VizletDrawer) SetSpoutOut

func (viz *VizletDrawer) SetSpoutOut(spoutout string)

SetSpoutOut xxx

func (*VizletDrawer) Shader

func (viz *VizletDrawer) Shader() *glhf.Shader

Shader xxx

func (*VizletDrawer) Sprites

func (viz *VizletDrawer) Sprites() []Sprite

Sprites xxx

func (*VizletDrawer) Width

func (viz *VizletDrawer) Width() int

Width xxx

type VizletISF

type VizletISF struct {
	Vizlet
	// contains filtered or unexported fields
}

VizletISF is one ISF shader within a Pipeline

func (*VizletISF) DoVizlet

func (viz *VizletISF) DoVizlet() error

DoVizlet xxx

func (*VizletISF) Height

func (viz *VizletISF) Height() int

Height xxx

func (*VizletISF) Name

func (viz *VizletISF) Name() string

Name xxx

func (*VizletISF) OutputTexture

func (viz *VizletISF) OutputTexture() *glhf.Texture

OutputTexture xxx

func (*VizletISF) SetInputFromVizlet

func (viz *VizletISF) SetInputFromVizlet(from Vizlet)

SetInputFromVizlet xxx

func (*VizletISF) SetSpoutIn

func (viz *VizletISF) SetSpoutIn(spoutin string)

SetSpoutIn xxx

func (*VizletISF) SetSpoutOut

func (viz *VizletISF) SetSpoutOut(spoutout string)

SetSpoutOut xxx

func (*VizletISF) Shader

func (viz *VizletISF) Shader() *glhf.Shader

Shader xxx

func (*VizletISF) Width

func (viz *VizletISF) Width() int

Width xxx

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL