示例#1
0
func NewLightPass(input *render.GeometryBuffer) *LightPass {

	shadowPass := NewShadowPass(input)

	/* use a virtual material to help with vertex attributes and textures */
	mat := render.CreateMaterial(render.CompileVFShader("/assets/shaders/voxel_light_pass"))

	/* we're going to render a simple quad, so we input
	 * position and texture coordinates */
	mat.AddDescriptor("position", gl.FLOAT, 3, 20, 0, false, false)
	mat.AddDescriptor("texcoord", gl.FLOAT, 2, 20, 12, false, false)

	/* the shader uses 3 textures from the geometry frame buffer.
	 * they are previously rendered in the geometry pass. */
	mat.AddTexture("tex_diffuse", input.Diffuse)
	mat.AddTexture("tex_normal", input.Normal)
	mat.AddTexture("tex_depth", input.Depth)
	mat.AddTexture("tex_shadow", shadowPass.Output)

	/* create a render quad */
	quad := render.NewRenderQuad()
	/* set up vertex attribute pointers */
	mat.SetupVertexPointers()

	p := &LightPass{
		Material: mat,
		quad:     quad,
		Shadows:  shadowPass,
	}
	return p
}
示例#2
0
func GetShader(name string) *render.ShaderProgram {
	// check shader cache
	if shader, exists := cache.Shaders[name]; exists {
		fmt.Println("Shader cache hit", name)
		return shader
	}

	// attempt to load
	fmt.Println("Loading shader", name)
	shader := render.CompileVFShader("assets/shaders/" + name)
	cache.Shaders[name] = shader

	return shader
}