-
-
Notifications
You must be signed in to change notification settings - Fork 5
Shader
Changkun Ou edited this page Aug 20, 2021
·
4 revisions
The polyred package offers a customized rendering pipeline:
Vertex Generation
|
v
Vertex Shading
|
v
Fragment Generation
|
v
Fragment Shading
with the following basic passes:
package render
type Renderer struct {
// contains unexported fields
}
// DrawPrimitives is a pass that executes Draw call concurrently on all
// given triangle primitives, and draws all geometric and rendering
// information on the given buffer. This primitive uses supplied shader
// programs (i.e. currently supports vertex shader and fragment shader)
//
// See shader.Program for more information regarding shader programming.
func (r *Renderer) DrawPrimitives(buf *buffer.Buffer, idx []uint64, verts []*primitive.Vertex, p shader.VertexProgram)
// DrawFragments is a concurrent executor of the given shader that travel
// through all fragments. Each fragment executes the given shaders exactly once.
//
// One should not manipulate the given image buffer in the shader.
// Instead, return the resulting color in the shader can avoid data race.
func (r *Renderer) DrawFragments(buf *buffer.Buffer, funcs ...shader.FragmentProgram)TODO: vertex and fragment
A shader is an interface that implements the VertexShader and
FragmentShader methods:
package shader
type Program interface {
VertexShader(primitive.Vertex) primitive.Vertex
FragmentShader(primitive.Fragment) color.RGBA
}A VertexShader consumes a vertex and returns a transformed vertex.
The input and output vertex may convey different information.
The information stored in a vertex primitive will be interpolated depending
on the specified camera target. An orthographic camera will interpolate
vertex attributes linearly and the interpolation of a perspective camera
is, of course, perspective corrected.
TODO: more about varying in vertex and fragment, smooth and flat.
Copyright © 2021 Changkun Ou. All rights reserved.