|
@@ -46,48 +46,54 @@ const (
|
|
|
UseLightAll UseLights = 0xFF
|
|
UseLightAll UseLights = 0xFF
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
-// Interface for all materials
|
|
|
|
|
|
|
+// IMaterial is the interface for all materials.
|
|
|
type IMaterial interface {
|
|
type IMaterial interface {
|
|
|
GetMaterial() *Material
|
|
GetMaterial() *Material
|
|
|
RenderSetup(gs *gls.GLS)
|
|
RenderSetup(gs *gls.GLS)
|
|
|
Dispose()
|
|
Dispose()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-//
|
|
|
|
|
-// Base Material
|
|
|
|
|
-//
|
|
|
|
|
|
|
+// Material is the base material.
|
|
|
type Material struct {
|
|
type Material struct {
|
|
|
refcount int // Current number of references
|
|
refcount int // Current number of references
|
|
|
|
|
+
|
|
|
|
|
+ // Shader specification // TODO Move ShaderSpecs into Material ?
|
|
|
shader string // Shader name
|
|
shader string // Shader name
|
|
|
shaderUnique bool // shader has only one instance (does not depend on lights or textures)
|
|
shaderUnique bool // shader has only one instance (does not depend on lights or textures)
|
|
|
- uselights UseLights // consider lights for shader selection
|
|
|
|
|
- sidevis Side // sides visible
|
|
|
|
|
- transparent bool // whether at all transparent
|
|
|
|
|
- wireframe bool // show as wirefrme
|
|
|
|
|
|
|
+ ShaderDefines gls.ShaderDefines // shader defines
|
|
|
|
|
+
|
|
|
|
|
+ uselights UseLights // Which light types to consider
|
|
|
|
|
+ sidevis Side // Face side(s) visibility
|
|
|
|
|
+ blending Blending // Blending mode
|
|
|
|
|
+ transparent bool // Whether at all transparent
|
|
|
|
|
+ wireframe bool // Whether to render only the wireframe
|
|
|
|
|
+ lineWidth float32 // Line width for lines and mesh wireframe
|
|
|
|
|
+ textures []*texture.Texture2D // List of textures
|
|
|
|
|
+
|
|
|
|
|
+ polyOffsetFactor float32 // polygon offset factor
|
|
|
|
|
+ polyOffsetUnits float32 // polygon offset units
|
|
|
|
|
+
|
|
|
depthMask bool // Enable writing into the depth buffer
|
|
depthMask bool // Enable writing into the depth buffer
|
|
|
depthTest bool // Enable depth buffer test
|
|
depthTest bool // Enable depth buffer test
|
|
|
depthFunc uint32 // Active depth test function
|
|
depthFunc uint32 // Active depth test function
|
|
|
- blending Blending // blending mode
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // Equations used for custom blending (when blending=BlendingCustom) // TODO implement methods
|
|
|
blendRGB uint32 // separate blend equation for RGB
|
|
blendRGB uint32 // separate blend equation for RGB
|
|
|
blendAlpha uint32 // separate blend equation for Alpha
|
|
blendAlpha uint32 // separate blend equation for Alpha
|
|
|
blendSrcRGB uint32 // separate blend func source RGB
|
|
blendSrcRGB uint32 // separate blend func source RGB
|
|
|
blendDstRGB uint32 // separate blend func dest RGB
|
|
blendDstRGB uint32 // separate blend func dest RGB
|
|
|
blendSrcAlpha uint32 // separate blend func source Alpha
|
|
blendSrcAlpha uint32 // separate blend func source Alpha
|
|
|
blendDstAlpha uint32 // separate blend func dest Alpha
|
|
blendDstAlpha uint32 // separate blend func dest Alpha
|
|
|
- lineWidth float32 // line width for lines and mesh wireframe
|
|
|
|
|
- polyOffsetFactor float32 // polygon offset factor
|
|
|
|
|
- polyOffsetUnits float32 // polygon offset units
|
|
|
|
|
- ShaderDefines gls.ShaderDefines // shader defines
|
|
|
|
|
- textures []*texture.Texture2D // List of textures
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// NewMaterial returns a pointer to a new material
|
|
|
|
|
|
|
+// NewMaterial creates and returns a pointer to a new Material.
|
|
|
func NewMaterial() *Material {
|
|
func NewMaterial() *Material {
|
|
|
|
|
|
|
|
mat := new(Material)
|
|
mat := new(Material)
|
|
|
return mat.Init()
|
|
return mat.Init()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// Init initializes the material.
|
|
|
func (mat *Material) Init() *Material {
|
|
func (mat *Material) Init() *Material {
|
|
|
|
|
|
|
|
mat.refcount = 1
|
|
mat.refcount = 1
|
|
@@ -103,12 +109,15 @@ func (mat *Material) Init() *Material {
|
|
|
mat.polyOffsetFactor = 0
|
|
mat.polyOffsetFactor = 0
|
|
|
mat.polyOffsetUnits = 0
|
|
mat.polyOffsetUnits = 0
|
|
|
mat.textures = make([]*texture.Texture2D, 0)
|
|
mat.textures = make([]*texture.Texture2D, 0)
|
|
|
|
|
+
|
|
|
|
|
+ // Setup shader defines and add default values
|
|
|
mat.ShaderDefines = *gls.NewShaderDefines()
|
|
mat.ShaderDefines = *gls.NewShaderDefines()
|
|
|
|
|
|
|
|
|
|
+
|
|
|
return mat
|
|
return mat
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// GetMaterial satisfies the IMaterial interface
|
|
|
|
|
|
|
+// GetMaterial satisfies the IMaterial interface.
|
|
|
func (mat *Material) GetMaterial() *Material {
|
|
func (mat *Material) GetMaterial() *Material {
|
|
|
|
|
|
|
|
return mat
|
|
return mat
|
|
@@ -179,7 +188,7 @@ func (mat *Material) UseLights() UseLights {
|
|
|
return mat.uselights
|
|
return mat.uselights
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// Sets the visible side(s) (SideFront | SideBack | SideDouble)
|
|
|
|
|
|
|
+// SetSide sets the visible side(s) (SideFront | SideBack | SideDouble)
|
|
|
func (mat *Material) SetSide(side Side) {
|
|
func (mat *Material) SetSide(side Side) {
|
|
|
|
|
|
|
|
mat.sidevis = side
|
|
mat.sidevis = side
|
|
@@ -191,23 +200,30 @@ func (mat *Material) Side() Side {
|
|
|
return mat.sidevis
|
|
return mat.sidevis
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// SetTransparent sets whether this material is transparent
|
|
|
|
|
|
|
+// SetTransparent sets whether this material is transparent.
|
|
|
func (mat *Material) SetTransparent(state bool) {
|
|
func (mat *Material) SetTransparent(state bool) {
|
|
|
|
|
|
|
|
mat.transparent = state
|
|
mat.transparent = state
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// Transparent returns whether this material is transparent
|
|
|
|
|
|
|
+// Transparent returns whether this material is transparent.
|
|
|
func (mat *Material) Transparent() bool {
|
|
func (mat *Material) Transparent() bool {
|
|
|
|
|
|
|
|
return mat.transparent
|
|
return mat.transparent
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// SetWireframe sets whether only the wireframe is rendered.
|
|
|
func (mat *Material) SetWireframe(state bool) {
|
|
func (mat *Material) SetWireframe(state bool) {
|
|
|
|
|
|
|
|
mat.wireframe = state
|
|
mat.wireframe = state
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// Wireframe returns whether only the wireframe is rendered.
|
|
|
|
|
+func (mat *Material) Wireframe() bool {
|
|
|
|
|
+
|
|
|
|
|
+ return mat.wireframe
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
func (mat *Material) SetDepthMask(state bool) {
|
|
func (mat *Material) SetDepthMask(state bool) {
|
|
|
|
|
|
|
|
mat.depthMask = state
|
|
mat.depthMask = state
|
|
@@ -234,6 +250,7 @@ func (mat *Material) SetPolygonOffset(factor, units float32) {
|
|
|
mat.polyOffsetUnits = units
|
|
mat.polyOffsetUnits = units
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// RenderSetup is called by the renderer before drawing objects with this material.
|
|
|
func (mat *Material) RenderSetup(gs *gls.GLS) {
|
|
func (mat *Material) RenderSetup(gs *gls.GLS) {
|
|
|
|
|
|
|
|
// Sets triangle side view mode
|
|
// Sets triangle side view mode
|
|
@@ -275,7 +292,7 @@ func (mat *Material) RenderSetup(gs *gls.GLS) {
|
|
|
gs.Disable(gls.BLEND)
|
|
gs.Disable(gls.BLEND)
|
|
|
case BlendingNormal:
|
|
case BlendingNormal:
|
|
|
gs.Enable(gls.BLEND)
|
|
gs.Enable(gls.BLEND)
|
|
|
- gs.BlendEquationSeparate(gls.FUNC_ADD, gls.FUNC_ADD)
|
|
|
|
|
|
|
+ gs.BlendEquation(gls.FUNC_ADD)
|
|
|
gs.BlendFunc(gls.SRC_ALPHA, gls.ONE_MINUS_SRC_ALPHA)
|
|
gs.BlendFunc(gls.SRC_ALPHA, gls.ONE_MINUS_SRC_ALPHA)
|
|
|
case BlendingAdditive:
|
|
case BlendingAdditive:
|
|
|
gs.Enable(gls.BLEND)
|
|
gs.Enable(gls.BLEND)
|