lux

package module
v0.0.0-...-542943e Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2016 License: MIT Imports: 17 Imported by: 0

README

#Install go get github.com/luxengine/lux

#development Currently on hold waiting to for algorithms in the physics engine. HOWEVER, if you want to use this lib but you're missing something. TELL ME!!, ill bring it up my priority list.

#Lux
Lux is a 3D game engine written almost entirely in Go. We aim to provide our users with powerfull and flexible tools to make games (and other 3D application too!). Every lines of code in Lux is coded with the following goal in mind:

  • Performance: Our code should be the fastest.!
  • Cross platform across all desktop operating systems: Sorry mobile :(
  • Support for the vast majority (95%+) of PC gamers: We are currently using OpenGL version 3.3 as default, in the future we would like to be able to switch between version and enable/disable features. Also support Vulkan eventually.
  • Flexibility: You the programmer should be able to change ANY part of the pipeline if you wanted to.
  • Usability: If our library feel like crap to use. It probably is. We're trying to make you have as much fun as possible when using our tools. If we write something and we feel it doesn't meet a certain standard. We won't release it.

Features:

  • Basic asset loading. (Who doesn't have that :P)
  • OpenGL abstraction layer Lux GL! Make your OpenGL code go-idiomatic :D
  • Wrapper for Bullet physics engine. Make giant towers of block then throw massive, heavy balls at it and watch it fall.
  • native float32 math library. Because vec[0], vec[1], vec[2] is prettier than float64(vec[0]), float64(vec[1]), float64(vec[2])
  • Faster and memory friendly matrix library! go-gl mgl32 is good but sloooooooowwww, also it allocates a lot of memory.
  • OpenCL wrapper and abstraction layer. Because sometimes we need to calculate stuff REALLY FREACKING FAST!
  • Image postprocessing pipeline. We have some predefined shaders. eg: cel-shading, fxaa, color manipulation, etc
  • Forward or Defered shading. Pick whichever you like best.
  • Basic shadow mapping.
  • Custom tailored worker pool for 3d application. <- seriously this is pretty cool.
  • Awesomium wrapper. FYI we HATE this. The license on Awesomium is HORRIBLE and the latest Awesomium that has a C-api (something that is needed in order to make a wrapper) doesn't support css3! But if you need a quick and dirty html ui. I'ts pretty usefull.

WIP:

  • Bullet port. Because 1: I'm a bit crazy and 2: pure go stuff has so so many advantages.
  • Particle systems. I've used some but never implemented any, it's actually a lot of fun.
  • Stabilisation, documentation and testing of the rendering pipelines. Both defered and Forward. You shouldn't have to care or know how shadows are calculated. You just want them to look good. (But again if you wanted to switch technique or use your own. We want you to be able to).
  • Steam wrapper. I'm REALLY hyped for the steam controllers.
  • Open source solution for UI (preferably html).
  • Solution for testing using go framework. Those who tried will quickly realise that every test run in it's own goroutine and that runtime.LockOsThread and TestMain don't help.
  • Scene manager solution. This will most likely be integrated/based on the same stuff Bullet is.

Future work:

  • Support for Vulkan
  • More variety of model loading.
  • More common CG techniques preimplemented, ready to use for developpers.
  • Framework for mods. (dynamic library loading/initialising)
  • Network game solution.

Documentation

Overview

Package lux is the core of the engine. It provides many abstraction to OpenGL techniques.

Index

Constants

View Source
const (
	Launcher int32 = 0
)

the types of particle there are

Variables

View Source
var Extensions map[string]bool

On load will contain all available OpenGL extension.

View Source
var PostProcessFragmentShaderToneMapping = `#version 330
uniform sampler2D tex;
uniform vec2 resolution;
uniform float time;
in vec2 uv;
layout (location=0) out vec4 outputColor;

float luminance(vec3 color) {
	return 0.2126 * color.r + 0.7152 * color.g + 0.0722 * color.b;
}

vec3 tone(vec3 x) {
	float A = 0.15;
	float B = 0.50;
	float C = 0.10;
	float D = 0.20;
	float E = 0.02;
	float F = 0.30;

	return ((x*(A*x+C*B)+D*E)/(x*(A*x+B)+D*F))-E/F;
}

void main(){
	vec3 x = vec3(texture(tex,uv));
	outputColor = vec4(tone(x), 1);
}
` + "\x00"

PostProcessFragmentShaderToneMapping is a tone mapping shader, needs to be used right after the GBuffer.

View Source
var PostprocessfragmentshaderFlip = `#version 330
uniform sampler2D tex;
uniform vec2 resolution;
uniform float time;
in vec2 uv;
layout (location=0) out vec4 outputColor;

void main(){
	outputColor=texture(tex,vec2(uv.x,1-uv.y));
}
` + "\x00"

Sample post process shader to flip texture top-botom (usefull for awesomium)

View Source
var PostprocessfragmentshaderFxaa = `#version 330
#define FXAA_REDUCE_MIN (1.0/128.0)
#define FXAA_REDUCE_MUL (1.0/8.0)
#define FXAA_SPAN_MAX 8.0
uniform sampler2D tex;
uniform vec2 resolution;
uniform float time;
in vec2 uv;

layout (location=0) out vec4 outputColor;

void main(){
	vec2 inverse_resolution=vec2(1.0/resolution.x,1.0/resolution.y);
	vec3 rgbNW = texture(tex, (gl_FragCoord.xy + vec2(-1.0,-1.0)) * inverse_resolution).xyz;
	vec3 rgbNE = texture(tex, (gl_FragCoord.xy + vec2(1.0,-1.0)) * inverse_resolution).xyz;
	vec3 rgbSW = texture(tex, (gl_FragCoord.xy + vec2(-1.0,1.0)) * inverse_resolution).xyz;
	vec3 rgbSE = texture(tex, (gl_FragCoord.xy + vec2(1.0,1.0)) * inverse_resolution).xyz;
	vec3 rgbM  = texture(tex,  gl_FragCoord.xy  * inverse_resolution).xyz;
	vec3 luma = vec3(0.299, 0.587, 0.114);
	float lumaNW = dot(rgbNW, luma);
	float lumaNE = dot(rgbNE, luma);
	float lumaSW = dot(rgbSW, luma);
	float lumaSE = dot(rgbSE, luma);
	float lumaM  = dot(rgbM,  luma);
	float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));
	float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE))); 
	vec2 dir;
	dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));
	dir.y =  ((lumaNW + lumaSW) - (lumaNE + lumaSE));
	float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAA_REDUCE_MUL),FXAA_REDUCE_MIN);
	float rcpDirMin = 1.0/(min(abs(dir.x), abs(dir.y)) + dirReduce);
	dir = min(vec2( FXAA_SPAN_MAX,  FXAA_SPAN_MAX),max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),dir * rcpDirMin)) * inverse_resolution;
	vec3 rgbA = 0.5 * (texture(tex,   gl_FragCoord.xy  * inverse_resolution + dir * (1.0/3.0 - 0.5)).xyz + texture(tex,   gl_FragCoord.xy  * inverse_resolution + dir * (2.0/3.0 - 0.5)).xyz);
	vec3 rgbB = rgbA * 0.5 + 0.25 * (texture(tex,  gl_FragCoord.xy  * inverse_resolution + dir *  - 0.5).xyz + texture(tex,  gl_FragCoord.xy  * inverse_resolution + dir * 0.5).xyz);
	float lumaB = dot(rgbB, luma);
	if((lumaB < lumaMin) || (lumaB > lumaMax)) {
		outputColor = vec4(rgbA,1.0);
	} else {
		outputColor = vec4(rgbB,1.0);
	}
}` + "\x00"

Sample post process shader to apply FXAA

View Source
var PostprocessfragmentshaderInverse = `#version 330
uniform sampler2D tex;
uniform vec2 resolution;
uniform float time;
in vec2 uv;
layout (location=0) out vec4 outputColor;
void main(){
	outputColor=1-texture(tex,uv);
}
` + "\x00"

Sample post process shader to inverse colors

View Source
var PostprocessfragmentshaderNormalvisual = `#version 330
uniform sampler2D tex;
uniform vec2 resolution;
uniform float time;
in vec2 uv;
layout (location=0) out vec4 outputColor;
void main(){
	outputColor=texture(tex,uv);
}
` + "\x00"

Sample post process shader to visualise normals

View Source
var PostprocessfragmentshaderNothing = `#version 330
uniform sampler2D tex;
uniform vec2 resolution;
uniform float time;
in vec2 uv;
layout (location=0) out vec4 outputColor;

void main(){
	outputColor=texture(tex,uv);
}
` + "\x00"

Sample post process shader to just blit the texture (could use texture blit as well)

View Source
var PostprocessfragmentshaderViewdepth = `#version 330
uniform sampler2D tex;
uniform vec2 resolution;
uniform float time;
in vec2 uv;
layout (location=0) out vec4 outputColor;

float LinearizeDepth(float z){
	float n = 0.1;
	float f = 5;
	return (2.0 * n) / (f + n-z*(f-n));
}

void main(){
	float depth = texture(tex,uv).r;
	outputColor=vec4(vec3(depth),1);
}
` + "\x00"

Sample post process shader to visualise depth (works differently on my mac and gnu+linux, weird)

View Source
var PostprocessfragmentshaderWobbly = `#version 330
uniform sampler2D tex;
uniform vec2 resolution;
uniform float time;
in vec2 uv;

layout (location=0) out vec4 outputColor;

void main() {
	vec2 coord = uv;
	coord.y = coord.y+sin(coord.y*100)/200;
	coord.x = coord.x+cos(coord.x*100)/200;
	outputColor = texture(tex, coord);
}
` + "\x00"

Sample post process shader to make the texture all wavy

Functions

func CreateWindow

func CreateWindow(width, height int, title string, fullscreen bool) (window *glfw.Window)

CreateWindow creates a new glfw window. If fullscreen will place the screen on primary monitor.

func D

func D(x ...interface{})

D is simply a alias to log.Println(... interface{}). Helps to debug without having to import "log" all the time.

func Fstri

func Fstri()

Fstri draws a fullscreen triangle such that it covers the entire screen with uv coordinates from [0,0]-[1,1]

func GenDepthTexture

func GenDepthTexture(width, height int32) gl.Texture2D

GenDepthTexture is a utility function to generate a depth Texture2D

func GenRGBTexture2D

func GenRGBTexture2D(width, height int32) gl.Texture2D

GenRGBTexture2D is a utility function to generate an empty 2D textures of size (width,height), internal format RGB adn data type UNSIGNED_BYTE

func GetOpenglVersion

func GetOpenglVersion() string

GetOpenglVersion will return the current OpenGL version.

func InitGLFW

func InitGLFW()

InitGLFW will call glfw.Init and panic if it fails

func InitPostProcessSystem

func InitPostProcessSystem()

InitPostProcessSystem will allocate all the resources required to make the Image Post Processing system work.

func LoadPng

func LoadPng(file string) (gl2.Texture2D, error)

LoadPng tries to load a png file from hard drive and upload it to the GPU.

func MustNotGLError

func MustNotGLError()

MustNotGLError will check opengl for error and panic if one was generated

func NewProgram

func NewProgram(shaders ...Shader) (gl.Program, error)

NewProgram will create an OpenGL program from the given shaders, any combinations can be used.

func QueryExtentions

func QueryExtentions()

QueryExtentions will grab every extension currently loaded and populate lux.Extensions.

func SaveTexture2D

func SaveTexture2D(t gl.Texture2D, filename string) error

SaveTexture2D take a Texture2D and a filename and saves it as a png image.

func SetContext

func SetContext()

SetContext will set a OpenGL core 3.3 context with foward compatibility and debug context

func StartHeadless

func StartHeadless() (window *glfw.Window)

StartHeadless will initialize everything but wont actually create a window, so you can test your application.

func TerminateGLFW

func TerminateGLFW()

TerminateGLFW is an alias for glfw.Terminate

func Traverse

func Traverse(*Camera, func(*Node))

Traverse traverses the scene and culls object that don't intersect with the camera.

func Update

func Update(float32)

Update updates the matrix of the entire tree.

func ViewportChange

func ViewportChange(width, height int32)

ViewportChange is an alias to glViewport(0, 0, width, height)

Types

type Agent

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

Agent is the handle to control a tickable agent.

func (*Agent) Seppuku

func (a *Agent) Seppuku()

Seppuku kills this agent.

type AgentManager

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

AgentManager is a struct to manage and synchronize all the Agents.

func NewAgentManager

func NewAgentManager() *AgentManager

NewAgentManager create an AgentManager and initialize all required values.

func (*AgentManager) AgentCount

func (am *AgentManager) AgentCount() int

AgentCount return the number of active agent.

func (*AgentManager) NewAgent

func (am *AgentManager) NewAgent(callback func() bool) *Agent

NewAgent starts a goroutine that will run callback every frame until it returns false, it will then die.

func (*AgentManager) Tick

func (am *AgentManager) Tick()

Tick will notify every agent that they need to execute their callback.

type AggregateFB

type AggregateFB struct {
	DiffUni, NormalUni, PosUni, DepthUni gl2.UniformLocation
	Out                                  gl2.Texture2D
	// contains filtered or unexported fields
}

AggregateFB is the FBO used to aggregate all the textures that the geometry shader built.

type AssetManager

type AssetManager struct {
	Models   map[string]Mesh
	Textures map[string]gl.Texture2D
	Programs map[string]gl.Program
	// contains filtered or unexported fields
}

AssetManager keeps track of loaded textures, models and programs

func NewAssetManager

func NewAssetManager(root, models, shaders, textures string) (out AssetManager)

NewAssetManager makes a new asset manager

-root: the root of all the other folders. eg. "assets"
-models: location of models. eg. "models", located at "assets/models"
-shaders: location of shaders. Not really used right now becasue everything is hard coded :\. eg. "shaders", located at "assets/shaders"
-textures: location of texture. eg. "textures", located at "assets/textures"

func (*AssetManager) Clean

func (am *AssetManager) Clean()

Clean delete/release everything loaded

func (*AssetManager) LoadModel

func (am *AssetManager) LoadModel(name, iname string)

LoadModel loads a single model. Only wavefront available for now. iname is the internal name to be set in the map.

func (*AssetManager) LoadRenderProgram

func (am *AssetManager) LoadRenderProgram(vertexShader, fragmentShader, iname string)

LoadRenderProgram is supose to load a render program, althouhg with the geometry buffer takes care of most of it. Do not use.

func (*AssetManager) LoadTexture

func (am *AssetManager) LoadTexture(name, iname string)

LoadTexture Load an image as a texture2D. iname is the internal name to be set in the map.

type Camera

type Camera struct {
	View       glm.Mat4
	Projection glm.Mat4
	Pos        glm.Vec3
}

Camera contains a view and projection matrix.

func (*Camera) LookAtVec

func (c *Camera) LookAtVec(eye, center, up *glm.Vec3)

LookAtVec sets the camera view direction by vectors.

func (*Camera) LookAtval

func (c *Camera) LookAtval(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ float32)

LookAtval sets the camera view direction by value.

func (*Camera) SetOrtho

func (c *Camera) SetOrtho(left, right, bottom, top, near, far float32)

SetOrtho sets the projection of this camera to an orthographic projection.

func (*Camera) SetPerspective

func (c *Camera) SetPerspective(angle, ratio, zNear, zFar float32)

SetPerspective sets the projection of this camera to a perspective projection.

type DirectionalLight

type DirectionalLight struct {
	Dx, Dy, Dz, R, G, B float32
}

DirectionalLight represent sources like the sun. Actually pretty much only the sun.

func (*DirectionalLight) CastsShadow

func (dl *DirectionalLight) CastsShadow(cast bool)

CastsShadow is a placeholder, dont call it will panic.

func (*DirectionalLight) SetColor

func (dl *DirectionalLight) SetColor(r, g, b float32)

SetColor sets this spotlight color.

func (*DirectionalLight) Upload

func (dl *DirectionalLight) Upload(u gl.UniformLocation)

Upload is a placeholder, dont call it will panic.

type GBuffer

type GBuffer struct {
	PUni, VUni, MUni, NUni, MVPUni, DiffuseUni  gl2.UniformLocation
	AlbedoTex, NormalTex, PositionTex, DepthTex gl2.Texture2D
	AggregateFramebuffer                        AggregateFB
	LightAcc                                    LightAccumulator
	// contains filtered or unexported fields
}

GBuffer is lux implementation of a geometry buffer for defered rendering

func NewGBuffer

func NewGBuffer(width, height int32) (gbuffer GBuffer, err error)

NewGBuffer will create a new geometry buffer and allocate all the resources required

func (*GBuffer) Aggregate

func (gb *GBuffer) Aggregate()

Aggregate performs the lighting calculation per pixel. This is essentially a special post process pass.

func (*GBuffer) Bind

func (gb *GBuffer) Bind(cam *Camera)

Bind binds the FBO and calcualte view-projection.

func (*GBuffer) Render

func (gb *GBuffer) Render(cam *Camera, mesh Mesh, tex gl2.Texture2D, t *Transform)

Render will render the mesh in the different textures. No lighting calculation is performed here.

func (*GBuffer) RenderLight

func (gb *GBuffer) RenderLight(cam *Camera, light *PointLight, shadowmat glm.Mat4, tex gl2.Texture2D, roughness, F0, Kd float32)

RenderLight calculates the cook-torrance shader and accumulates its intensity in the geometry buffer.

type Light

type Light interface {
	SetColor(float32, float32, float32)
	Upload(gl.UniformLocation)
	CastsShadow(bool)
}

Light is the interface that group all the common light operations.

type LightAccumulator

type LightAccumulator struct {
	AlbedoUni, NormalUni, PosUni, DepthUni gl2.UniformLocation
	Out                                    gl2.Texture2D
	CookRoughnessValue, CookF0, CookK      gl2.UniformLocation
	PointLightPosUni                       gl2.UniformLocation
	CamPosUni                              gl2.UniformLocation
	ShadowMapUni, ShadowMatUni             gl2.UniformLocation
	// contains filtered or unexported fields
}

LightAccumulator takes all the lights and accumulates their effect in a gbuffer

type Mesh

type Mesh interface {
	Bind()
	Delete()
	Size() int32
	DrawCall()
}

Mesh is an interface to represent any renderable mesh

func NewVUNModel

func NewVUNModel(indices []uint16, indexedVertices []glm.Vec3, indexedUvs []glm.Vec2, indexedNormals []glm.Vec3) Mesh

NewVUNModel process and uploads the data to the GPU.

func NewVUNModelGlm

func NewVUNModelGlm(indices []uint16, indexedVertices []glm.Vec3, indexedUvs []glm.Vec2, indexedNormals []glm.Vec3) Mesh

NewVUNModelGlm process and uploads the data to the GPU.

func NewWavefrontModelFromFile

func NewWavefrontModelFromFile(file string) Mesh

NewWavefrontModelFromFile loads a wavefront from the given file. Can only load files that are triangulated and with UV. Does not do anythign with material property.

type Node

type Node struct {
	Transform
	// contains filtered or unexported fields
}

Node is a single item in a scene tree. It may just contain more children or it may be a model.

func (*Node) AttachChildren

func (n *Node) AttachChildren()

AttachChildren attaches a children to this node

func (*Node) Iden

func (n *Node) Iden()

Iden set this transform to the identity 4x4 matrix

func (*Node) QuatRotate

func (n *Node) QuatRotate(angle float32, axis *glm.Vec3)

QuatRotate add the rotation represented by this (angle,quat) to the current transform.

func (*Node) Scale

func (n *Node) Scale(amount float32)

Scale add a scaling operation to the currently stored transform. I do not allow non-uniform scaling to prevent ending up with matrices without an inverse.

func (*Node) SetQuatRotate

func (n *Node) SetQuatRotate(angle float32, axis *glm.Vec3)

SetQuatRotate will reset this transform to represent the rotation represented by this (angle,quat).

func (*Node) SetScale

func (n *Node) SetScale(amount float32)

SetScale reset this transform to represent only the scaling transform of `amount` I do not allow non-uniform scaling to prevent ending up with matrices without an inverse.

func (*Node) SetTranslate

func (n *Node) SetTranslate(x, y, z float32)

SetTranslate reset this transform to represent only the translation transform given by (x,y,z).

func (*Node) Translate

func (n *Node) Translate(x, y, z float32)

Translate add the translation (x,y,z) to the current transform.

type Particle

type Particle struct {
	Type               int32
	Position, Velocity glm.Vec3
	Lifetime           float32
}

Particle is a single particle.

type ParticleSystem

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

ParticleSystem is a particle system, it generates tiny points in space and renders them

func NewParticleSystem

func NewParticleSystem(position, direction glm.Vec3, size int) *ParticleSystem

NewParticleSystem builds a particle system

func (*ParticleSystem) Render

func (ps *ParticleSystem) Render(delta float64, VP glm.Mat4, camera glm.Vec3)

Render renders this particle system

type PointLight

type PointLight struct {
	X, Y, Z, R, G, B float32
}

PointLight is a simple point light with colors.

func (*PointLight) CastsShadow

func (pl *PointLight) CastsShadow(cast bool)

CastsShadow is a placeholder, dont call it will panic.

func (*PointLight) Move

func (pl *PointLight) Move(x, y, z float32)

Move sets the point light position to (x,y,z).

func (*PointLight) SetColor

func (pl *PointLight) SetColor(r, g, b float32)

SetColor sets this point light color.

func (*PointLight) Upload

func (pl *PointLight) Upload(u gl.UniformLocation)

Upload is a placeholder, dont call it will panic.

type PostProcessFramebuffer

type PostProcessFramebuffer struct {
	Fb   gl2.Framebuffer
	Tex  gl2.Texture2D
	Prog gl2.Program
	// contains filtered or unexported fields
}

PostProcessFramebuffer is the generic post process framebuffer

func NewPostProcessFramebuffer

func NewPostProcessFramebuffer(width, height int32, fragmentSource string) (*PostProcessFramebuffer, error)

NewPostProcessFramebuffer creates a new PostProcessFramebuffer and allocated all the ressources. You do not control the vertex shader but you can give a fragment shader. The fragment shader must have the following uniforms:

-resolution: float vec2, representing the size of the texture
-time: float, glfw time since the begining of the program
-tex: sampler2D, the input texture to this post process pass

func (*PostProcessFramebuffer) Delete

func (ppfb *PostProcessFramebuffer) Delete()

Delete releases all the resources allocated to this post process fbo.

func (*PostProcessFramebuffer) PostRender

func (ppfb *PostProcessFramebuffer) PostRender()

PostRender renable depth test

func (*PostProcessFramebuffer) PreRender

func (ppfb *PostProcessFramebuffer) PreRender()

PreRender binds either the next post process fbo if there is one or unbinds any fbo to render to screen. Also disable depth test.

func (*PostProcessFramebuffer) Render

func (ppfb *PostProcessFramebuffer) Render(t gl2.Texture2D)

Render takes a texture and feed it to the fragment shader as a fullscreen texture. It will call the next post process pass if there is one.

func (*PostProcessFramebuffer) SetNext

SetNext sets the post process effect to pass automatically after this post process.

type PostProcessFramebufferer

type PostProcessFramebufferer interface {
	PreRender()
	Render(gl2.Texture2D)
	SetNext(PostProcessFramebufferer)
}

PostProcessFramebufferer is an interface to represent a single PostProcess effect.

type RenderProgram

type RenderProgram struct {
	Prog                            gl.Program
	M, V, P, Diffuse, Light, N, Eye gl.UniformLocation
}

RenderProgram is the lux representation of a OpenGL program vertex-fragment along with all the common uniforms.

func LoadProgram

func LoadProgram(vertexfile, fragfile string) (out RenderProgram, err error)

LoadProgram loads a vertex-fragment program and gathers: "M": model matrix uniform "V": view matrix uniform "P": projection matrix uniform "N": normal matrix uniform "diffuse":diffuse texture sampler2d "pointlight":array of vec3 for light position

func (*RenderProgram) Delete

func (rp *RenderProgram) Delete()

Delete releases all resources held by this program object

type SceneGraph

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

SceneGraph is a graph for a scene.

type Shader

type Shader struct {
	Stype uint32
	Loc   uint32
}

Shader represent an OpenGL shader object along with its type.

func CompileShader

func CompileShader(source string, shaderType uint32) (Shader, error)

CompileShader will take the shader source and generate a shader object based on which type you give it. Returns an error if it fails.

func (Shader) Delete

func (s Shader) Delete()

Delete releases all the resources held by this shader object.

type ShadowCubeFBO

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

ShadowCubeFBO is a packed framebuffer and cubemap with depth only for shadows.

func NewShadowCubeFBO

func NewShadowCubeFBO(width, height int32) *ShadowCubeFBO

NewShadowCubeFBO makes a new ShadowCubeFBO.

type ShadowFBO

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

ShadowFBO is the structure to hold all the resources required to render shadow maps.

func NewShadowFBO

func NewShadowFBO(width, height int32) (*ShadowFBO, error)

NewShadowFBO will create a new FBO, a new depth texture and the program needed to generate shadow map currently not optimized, we should probably reuse the FBO and absolutely reuse the program.

func (*ShadowFBO) BindForDrawing

func (sfbo *ShadowFBO) BindForDrawing()

BindForDrawing binds this fbo, change face culling for back face, start using the shadow program, calculate projection and clears the texture.

func (*ShadowFBO) Delete

func (sfbo *ShadowFBO) Delete()

Delete will clean up all the resources allocated to this FBO.

func (*ShadowFBO) LookAt

func (sfbo *ShadowFBO) LookAt(ex, ey, ez, tx, ty, tz float32)

LookAt sets the view matrix to look at (tx,ty,tz) from (ex,ey,ez), the up direction is always (0,1,0).

func (*ShadowFBO) Render

func (sfbo *ShadowFBO) Render(mesh Mesh, transform *Transform)

Render takes a mesh and a transform and render them, adding them to the depth texture data.

func (*ShadowFBO) SetOrtho

func (sfbo *ShadowFBO) SetOrtho(left, right, bottom, top, near, far float32)

SetOrtho sets the projection matrix to be used.

func (*ShadowFBO) ShadowMap

func (sfbo *ShadowFBO) ShadowMap() gl2.Texture2D

ShadowMap return the depth texture.

func (*ShadowFBO) ShadowMat

func (sfbo *ShadowFBO) ShadowMat() glm.Mat4

ShadowMat return the 4x4 matric that represent world-to-screen transform used to check pixel occlusion.

func (*ShadowFBO) Unbind

func (sfbo *ShadowFBO) Unbind()

Unbind return cull face to front and unbind this fbo.

type SpotLight

type SpotLight struct {
	X, Y, Z, Tx, Ty, Tz, A, R, G, B float32
}

SpotLight are similar to PointLight except they have an angle

func (*SpotLight) CastsShadow

func (sl *SpotLight) CastsShadow(cast bool)

CastsShadow is a placeholder, dont call it will panic.

func (*SpotLight) Move

func (sl *SpotLight) Move(x, y, z float32)

Move sets the spotlight position to (x,y,z).

func (*SpotLight) SetAngle

func (sl *SpotLight) SetAngle(a float32)

SetAngle sets the max angle that this spotlight will illuminate.

func (*SpotLight) SetColor

func (sl *SpotLight) SetColor(r, g, b float32)

SetColor sets this spotlight color.

func (*SpotLight) Upload

func (sl *SpotLight) Upload(u gl.UniformLocation)

Upload is a placeholder, dont call it will panic.

type Transform

type Transform struct {
	LocalToWorld glm.Mat4
}

Transform represent a single local-to-world transformation matrix. It might be upgraded to be used in a tree. (parent-child relation)

func NewTransform

func NewTransform() *Transform

NewTransform creates a new Transform

func (*Transform) Copy

func (t *Transform) Copy(t2 *Transform)

Copy copies t2 in t.

func (*Transform) Iden

func (t *Transform) Iden()

Iden set this transform to the identity 4x4 matrix

func (*Transform) Mat4

func (t *Transform) Mat4() glm.Mat4

Mat4 returns the mathgl 4x4 matrix that represents this transform local-to-world transformation matrix.

func (*Transform) QuatRotate

func (t *Transform) QuatRotate(angle float32, axis *glm.Vec3)

QuatRotate add the rotation represented by this (angle,quat) to the current transform.

func (*Transform) Scale

func (t *Transform) Scale(amount float32)

Scale add a scaling operation to the currently stored transform.

func (*Transform) SetMatrix

func (t *Transform) SetMatrix(m *[16]float32)

SetMatrix sets this transform matrix

func (*Transform) SetQuatRotate

func (t *Transform) SetQuatRotate(angle float32, axis *glm.Vec3)

SetQuatRotate will reset this transform to represent the rotation represented by this (angle,quat).

func (*Transform) SetScale

func (t *Transform) SetScale(amount float32)

SetScale reset this transform to represent only the scaling transform of `amount`

func (*Transform) SetTranslate

func (t *Transform) SetTranslate(x, y, z float32)

SetTranslate reset this transform to represent only the translation transform given by (x,y,z).

func (*Transform) Translate

func (t *Transform) Translate(x, y, z float32)

Translate add the translation (x,y,z) to the current transform.

type VUNMesh

type VUNMesh struct {
	VAO                              gl2.VertexArray
	Indices, Positions, Uvs, Normals gl2.Buffer
	Msize                            int32
}

VUNMesh is a Vertex-Uv-Normal mesh

func (*VUNMesh) Bind

func (m *VUNMesh) Bind()

Bind the vertex array and all vertex attrib required to render this mesh.

func (VUNMesh) Delete

func (m VUNMesh) Delete()

Delete all allocated resources (buffers, vertexarray,etc).

func (*VUNMesh) DrawCall

func (m *VUNMesh) DrawCall()

DrawCall send a single draw call

func (*VUNMesh) Size

func (m *VUNMesh) Size() int32

Size returns the amount of verteices to be drawn.

func (*VUNMesh) Unbind

func (m *VUNMesh) Unbind()

Unbind all the resources.

Directories

Path Synopsis
Package debug helps control the flow of the messages that come out of the GL_ARB_debug_output extension.
Package debug helps control the flow of the messages that come out of the GL_ARB_debug_output extension.

Jump to

Keyboard shortcuts

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