Skip to content

Commit

Permalink
added sprite illumination capability
Browse files Browse the repository at this point in the history
  • Loading branch information
harbdog committed Jan 17, 2023
1 parent 90ec971 commit fed3f8a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 4 additions & 3 deletions camera.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,7 @@ func (c *Camera) castSprite(spriteOrdIndex int) {
spriteTex := sprite.Texture()
spriteTexRect := sprite.TextureRect()
spriteTexWidth, spriteTexHeight := spriteTex.Size()
spriteIllumination := sprite.Illumination()

//transform sprite with the inverse camera matrix
// [ planeX dirX ] -1 [ dirY -dirX ]
Expand Down Expand Up @@ -714,9 +715,9 @@ func (c *Camera) castSprite(spriteOrdIndex int) {
// distance based lighting/shading
shadowDepth := math.Sqrt(transformY) * c.lightFalloff
spriteLvl.St[stripe] = &color.RGBA{255, 255, 255, 255}
spriteLvl.St[stripe].R = byte(geom.ClampInt(int(float64(spriteLvl.St[stripe].R)+shadowDepth+c.globalIllumination), int(c.minLightRGB.R), int(c.maxLightRGB.R)))
spriteLvl.St[stripe].G = byte(geom.ClampInt(int(float64(spriteLvl.St[stripe].G)+shadowDepth+c.globalIllumination), int(c.minLightRGB.G), int(c.maxLightRGB.G)))
spriteLvl.St[stripe].B = byte(geom.ClampInt(int(float64(spriteLvl.St[stripe].B)+shadowDepth+c.globalIllumination), int(c.minLightRGB.B), int(c.maxLightRGB.B)))
spriteLvl.St[stripe].R = byte(geom.ClampInt(int(float64(spriteLvl.St[stripe].R)+shadowDepth+c.globalIllumination+spriteIllumination), int(c.minLightRGB.R), int(c.maxLightRGB.R)))
spriteLvl.St[stripe].G = byte(geom.ClampInt(int(float64(spriteLvl.St[stripe].G)+shadowDepth+c.globalIllumination+spriteIllumination), int(c.minLightRGB.G), int(c.maxLightRGB.G)))
spriteLvl.St[stripe].B = byte(geom.ClampInt(int(float64(spriteLvl.St[stripe].B)+shadowDepth+c.globalIllumination+spriteIllumination), int(c.minLightRGB.B), int(c.maxLightRGB.B)))
}
}

Expand Down
3 changes: 3 additions & 0 deletions sprite.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ type Sprite interface {
// TextureRect needs to return the rectangle of the texture coordinates to draw
TextureRect() image.Rectangle

// Illumination needs to return sprite specific illumination offset (for normal illumination, default to 0)
Illumination() float64

// SetScreenRect accepts the raycasted rectangle of the screen coordinates to be rendered (nil if not on screen)
SetScreenRect(rect *image.Rectangle)

Expand Down

0 comments on commit fed3f8a

Please sign in to comment.