Compare commits

..

15 Commits

Author SHA1 Message Date
b48e4e92fa goodbye rock 2023-08-22 00:09:35 +10:00
73b58eb3e0 implemented fragment shader parallax occlusion mapping & add some assets to test it 2023-08-21 02:56:51 +10:00
3020ea8a08 I FUCKING LOVE COLIN 2023-08-21 02:55:19 +10:00
1d3b18becb I forgot the knuxz textures :( 2023-08-20 18:49:27 +10:00
4fdfb2e6ea GBYE KNUX 2023-08-20 18:40:33 +10:00
b894cd4254 unable to shade polygon normals 2023-08-20 06:14:04 +10:00
22be9bbe00 they call me knuckles unlike sonic i dont chuckle i just flex my knuckles 2023-08-20 06:09:48 +10:00
e031523ed1 rock hell 2023-08-20 05:57:33 +10:00
9cde1d98e2 cache ur rocks 2023-08-19 06:58:55 +10:00
745476a7a0 rock 2023-08-19 06:33:56 +10:00
a6d6277070 party refactors in the house tonight 2023-08-19 05:46:29 +10:00
81064b497f wrinkly woman 2023-08-19 02:16:02 +10:00
344080e14d krazy lites 2023-08-19 01:38:20 +10:00
2a88f7d446 point lights 2023-08-18 04:48:22 +10:00
20b42d7a32 specular floor 2023-08-18 03:50:49 +10:00
31 changed files with 349 additions and 134 deletions

View File

@@ -24,6 +24,8 @@ class Colin
private var fov = 60.0f
private var cam: PerspectiveCamera
private var nutted = false
private var colinMode = false
private var backPressed = false
private var texture: Texture = assetManager.get("colin.png")
private val nut: Sound = assetManager.get("nut.wav")
@@ -40,10 +42,7 @@ class Colin
private fun updateCamera()
{
cam.position.set(Vector3(pos.x, 1.0f, pos.y))
val forward = Vector3(0.0f, 0.0f, -1.0f)
val up = Vector3(0.0f, 1.0f, 0.0f)
val right = Vector3(1.0f, 0.0f, 0.0f)
cam.direction.set(forward.rotateRad(right, offsAngle.y).rotateRad(up, offsAngle.x + angle))
cam.direction.set(Util.forward.rotateRad(Util.right, offsAngle.y).rotateRad(Util.up, offsAngle.x + angle))
cam.update()
}
@@ -79,16 +78,29 @@ class Colin
if (!stick.isZero)
pos -= forward * stick.y * speed * deltaTime
offsAngle = Controllers.getCurrent()?.let { pad ->
if (Gdx.input.isKeyJustPressed(Input.Keys.C))
colinMode = !colinMode
Controllers.getCurrent()?.let { pad ->
val dst = Vector2(
pad.getAxis(pad.mapping.axisRightX),
pad.getAxis(pad.mapping.axisRightY))
.radialDeadzone(0.1f, 1.0f) * MathUtils.PI * -0.25f
offsAngle.lerp(dst, 16.0f * deltaTime)
} ?: Vector2.Zero
Controllers.getCurrent()?.let { pad ->
val targetFov = MathUtils.lerp(60.0f, 20.0f, pad.getAxis(5))
.radialDeadzone(0.1f, 1.0f) * MathUtils.PI * -0.5f
offsAngle = offsAngle.lerp(dst, 16.0f * deltaTime)
val targetFov = MathUtils.lerp(60.0f, 20.0f, pad.getAxis(5)) //fixme: where is mapping for rt??
cam.fieldOfView = MathUtils.lerp(cam.fieldOfView, targetFov, 20.0f * deltaTime)
val right = Vector2(MathUtils.cos(angle), -MathUtils.sin(angle))
if (pad.getButton(pad.mapping.buttonL1))
pos -= right * speed * deltaTime
if (pad.getButton(pad.mapping.buttonR1))
pos += right * speed * deltaTime
val back = pad.getButton(pad.mapping.buttonBack)
if (!backPressed && back)
colinMode = !colinMode
backPressed = back
}
if (Controllers.getCurrent()?.let { pad -> pad.getButton(pad.mapping.buttonA) } == true || Gdx.input.isKeyJustPressed(Input.Keys.N))
@@ -110,15 +122,16 @@ class Colin
fun draw(spriteBatch: SpriteBatch)
{
val drawPos = Vector2(pos.x * 100.0f, -pos.y * 100.0f)
//spriteBatch.draw(texture, drawPos.x - 32.0f, drawPos.y - 32.0f, 64.0f, 64.0f)
val region = TextureRegion(texture)
spriteBatch.draw(region,
drawPos.x - 32.0f, drawPos.y - 32.0f,
32.0f, 32.0f,
64.0f, 64.0f,
1.0f, 1.0f, angle * MathUtils.radiansToDegrees)
if (colinMode)
{
val drawPos = Vector2(pos.x * 100.0f, -pos.y * 100.0f)
val region = TextureRegion(texture)
spriteBatch.draw(region,
drawPos.x - 32.0f, drawPos.y - 32.0f,
32.0f, 32.0f,
64.0f, 64.0f,
1.0f, 1.0f, angle * MathUtils.radiansToDegrees)
}
}
val camera get() = cam

View File

@@ -3,6 +3,9 @@ package gay.pizza.CavesOfJolk
import com.badlogic.gdx.graphics.g3d.Attributes
import com.badlogic.gdx.graphics.g3d.Renderable
import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute
import com.badlogic.gdx.graphics.g3d.attributes.FloatAttribute
import com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute
import com.badlogic.gdx.graphics.g3d.shaders.BaseShader
import com.badlogic.gdx.graphics.g3d.shaders.DefaultShader
class CustomDefaultShader(renderable: Renderable, config: Config):
@@ -18,6 +21,13 @@ class CustomDefaultShader(renderable: Renderable, config: Config):
renderable.environment.let { attribs.set(it) }
renderable.material.let { attribs.set(it) }
if (attribs.has(CustomFloatAttribute.BumpHeight) && attribs.has(TextureAttribute.Bump))
{
prefix += "#define " + CustomFloatAttribute.BumpHeightAlias + "Flag\n"
prefix += "#define " + TextureAttribute.BumpAlias + "Flag\n"
prefix += "#define " + TextureAttribute.BumpAlias + "Coord texCoord0\n"
}
if (attribs.has(ColorAttribute.Fog))
{
prefix += "#define fog${
@@ -50,6 +60,41 @@ class CustomDefaultShader(renderable: Renderable, config: Config):
val fogNear = Uniform("u_fogNear")
val fogFar = Uniform("u_fogFar")
val fogDensity = Uniform("u_fogDensity")
val bumpHeight = Uniform("u_bumpHeight")
val bumpTexture = Uniform("u_bumpTexture")
val bumpUVTransform = Uniform("u_bumpUVTransform")
}
object Setters
{
val bumpHeight = object: LocalSetter()
{
override fun set(shader: BaseShader, inputId: Int, renderable: Renderable, combAttribs: Attributes)
{
val attr = combAttribs.get(CustomFloatAttribute.BumpHeight) as FloatAttribute
shader.set(inputId, attr.value)
}
}
val bumpTexture = object: LocalSetter()
{
override fun set(shader: BaseShader, inputId: Int, renderable: Renderable, combAttribs: Attributes)
{
val texAttr = combAttribs.get(TextureAttribute.Bump) as TextureAttribute
val unit = shader.context.textureBinder.bind(texAttr.textureDescription)
shader.set(inputId, unit)
}
}
var bumpUVTransform = object: LocalSetter()
{
override fun set(shader: BaseShader, inputId: Int, renderable: Renderable, combAttribs: Attributes)
{
val ta = combAttribs.get(TextureAttribute.Normal) as TextureAttribute
shader.set(inputId, ta.offsetU, ta.offsetV, ta.scaleU, ta.scaleV)
}
}
}
}
@@ -57,6 +102,10 @@ class CustomDefaultShader(renderable: Renderable, config: Config):
private val u_fogFar = register(Inputs.fogFar)
private val u_fogDensity = register(Inputs.fogDensity)
private val u_bumpHeight = register(Inputs.bumpHeight, Setters.bumpHeight)
private val u_bumpTexture = register(Inputs.bumpTexture, Setters.bumpTexture)
private val u_bumpUVTransform = register(Inputs.bumpUVTransform, Setters.bumpUVTransform)
override fun bindLights(renderable: Renderable?, attributes: Attributes?)
{
if (attributes == null)

View File

@@ -4,6 +4,7 @@ import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.g3d.Renderable
import com.badlogic.gdx.graphics.g3d.Shader
import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute
import com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute
import com.badlogic.gdx.graphics.g3d.shaders.DefaultShader
import com.badlogic.gdx.graphics.g3d.utils.DefaultShaderProvider
@@ -29,6 +30,11 @@ class CustomDefaultShaderProvider(config: DefaultShader.Config): DefaultShaderPr
CustomFloatAttribute.FogDensity
if ((renderableMask and ColorAttribute.Fog == ColorAttribute.Fog) && (renderableMask and fogMask != 0L))
return CustomDefaultShader(renderable, config)
val bumpMask = CustomFloatAttribute.BumpHeight or TextureAttribute.Bump
if (renderableMask and bumpMask == bumpMask)
return CustomDefaultShader(renderable, config)
return super.createShader(renderable)
}
}

View File

@@ -17,5 +17,9 @@ class CustomFloatAttribute private constructor(type: Long, value: Float): FloatA
const val FogDensityAlias = "fogDensity"
val FogDensity = register(FogDensityAlias)
fun createFogDensity(value: Float) = CustomFloatAttribute(FogDensity, value)
const val BumpHeightAlias = "bumpHeight"
val BumpHeight = register(BumpHeightAlias)
fun createBumpHeight(value: Float) = CustomFloatAttribute(BumpHeight, value)
}
}

View File

@@ -6,27 +6,26 @@ import com.badlogic.gdx.graphics.*
import com.badlogic.gdx.graphics.g2d.BitmapFont
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g3d.*
import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute
import com.badlogic.gdx.graphics.g3d.attributes.FloatAttribute
import com.badlogic.gdx.graphics.g3d.attributes.IntAttribute
import com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute
import com.badlogic.gdx.graphics.g3d.attributes.*
import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight
import com.badlogic.gdx.graphics.g3d.environment.PointLight
import com.badlogic.gdx.graphics.g3d.model.data.*
import com.badlogic.gdx.graphics.g3d.shaders.DefaultShader
import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder
import com.badlogic.gdx.graphics.g3d.utils.TextureDescriptor
import com.badlogic.gdx.graphics.g3d.utils.TextureProvider
import com.badlogic.gdx.graphics.g3d.utils.TextureProvider.AssetTextureProvider
import com.badlogic.gdx.math.*
import com.badlogic.gdx.utils.Array
import com.badlogic.gdx.utils.ScreenUtils
import gay.pizza.CavesOfJolk.Resources.Companion.assetManager
import ktx.math.times
class Game: ApplicationAdapter()
{
private lateinit var texJolk: Texture
private lateinit var fntComic: BitmapFont
private lateinit var cube: Model
private lateinit var floor: Model
private lateinit var toybox: Model
private lateinit var spriteBatch: SpriteBatch
private lateinit var modelBatch: ModelBatch
@@ -34,98 +33,85 @@ class Game: ApplicationAdapter()
private lateinit var colin: Colin
private var jolkRot = 0.0f
private var lightTheta = 0.0f
private val rand = RandomXS128(69 + 420 + 1919 + 916 + 42 + 1)
private lateinit var cubeInstance: ModelInstance
private lateinit var floorInstance: ModelInstance
private lateinit var suzanneInstance: ModelInstance
private lateinit var knux: ModelInstance
private lateinit var toyboxInstance: ModelInstance
private fun makeCube(texture: Texture): Model
private fun makeCube(size: Float, material: Material): Model
{
val modelBuilder = ModelBuilder()
val size = 2.0f
val material = Material(
ColorAttribute.createDiffuse(XnaColor.White),
TextureAttribute(TextureAttribute.Diffuse,
TextureDescriptor(texture,
Texture.TextureFilter.Linear,
Texture.TextureFilter.Linear,
Texture.TextureWrap.ClampToEdge,
Texture.TextureWrap.ClampToEdge)),
ColorAttribute.createSpecular(XnaColor.Gray),
FloatAttribute.createShininess(20.0f))
val attribs = VertexAttributes.Usage.Position or VertexAttributes.Usage.TextureCoordinates or VertexAttributes.Usage.Normal
return modelBuilder.createBox(size, size, size, material, attribs.toLong())
ModelBuilder().apply {
val attribs =
VertexAttributes.Usage.Position or
VertexAttributes.Usage.TextureCoordinates or
VertexAttributes.Usage.Normal
return createBox(size, size, size, material, attribs.toLong())
}
}
private fun makeFloor(): Model
private fun makeFloor(size: Float): Model
{
val model = ModelData()
val texs = size / 4.0f
val mesh = ModelMesh()
mesh.id = "floormodel"
mesh.attributes = arrayOf(
VertexAttribute.Position(),
VertexAttribute.Normal(),
VertexAttribute.Tangent(),
VertexAttribute.Binormal(),
VertexAttribute.TexCoords(0))
val normal = Vector3(0.0f, 1.0f, 0.0f)
val tangent = Vector3(1.0f, 0.0f, 0.0f)
val bitangent = Vector3(0.0f, 0.0f, -1.0f)
val vertex = { pos: Vector3, tex: Vector2, norm: Vector3, tan: Vector3, bitan: Vector3 -> floatArrayOf(
pos.x, pos.y, pos.z,
norm.x, norm.y, norm.z,
tan.x, tan.y, tan.z,
bitan.x, bitan.y, bitan.z,
tex.x, tex.y
)}
val size = 16.0f
val texs = 4.0f
mesh.vertices =
vertex(Vector3(0.0f, 0.0f, 0.0f), Vector2(0.0f, texs), normal, tangent, bitangent) +
vertex(Vector3(size, 0.0f, 0.0f), Vector2(texs, texs), normal, tangent, bitangent) +
vertex(Vector3(0.0f, 0.0f, -size), Vector2(0.0f, 0.0f), normal, tangent, bitangent) +
vertex(Vector3(size, 0.0f, -size), Vector2(texs, 0.0f), normal, tangent, bitangent)
val part = ModelMeshPart()
part.id = "floormesh"
part.primitiveType = GL20.GL_TRIANGLES
part.indices = shortArrayOf(
0, 1, 2,
3, 2, 1)
mesh.parts = arrayOf(part)
model.addMesh(mesh)
val vertex = { pos: Vector3, tex: Vector2 ->
val normal = Util.up
val tangent = Util.right
val bitangent = Util.forward
floatArrayOf(
pos.x, pos.y, pos.z,
normal.x, normal.y, normal.z, tangent.x, tangent.y, tangent.z, bitangent.x, bitangent.y, bitangent.z,
tex.x, tex.y)
}
val material = ModelMaterial()
material.id = "floormat"
material.diffuse = XnaColor.White
material.specular = XnaColor.BlanchedAlmond.mix(XnaColor.Black, 0.4f)
material.shininess = 65.0f
val diffuse = ModelTexture()
diffuse.usage = ModelTexture.USAGE_DIFFUSE
diffuse.fileName = "cobblestone.png"
val normalMap = ModelTexture()
normalMap.usage = ModelTexture.USAGE_NORMAL
normalMap.fileName = "cobblestone_normal.png"
material.textures = Array()
material.textures.add(diffuse, normalMap)
model.materials.add(material)
val modelTexture = { modelTextureUsage: Int, textureFilename: String -> ModelTexture().apply {
usage = modelTextureUsage
fileName = textureFilename
}}
val node = ModelNode()
node.id = "floornode"
node.scale = Vector3(1.0f, 1.0f, 1.0f)
node.rotation = Quaternion()
val nodePart = ModelNodePart()
nodePart.meshPartId = "floormesh"
nodePart.materialId = "floormat"
node.parts = arrayOf(nodePart)
model.nodes.add(node)
return Model(model, TextureProvider.FileTextureProvider(
Texture.TextureFilter.Nearest,
Texture.TextureFilter.Nearest,
Texture.TextureWrap.Repeat,
Texture.TextureWrap.Repeat,
false))
return Model(ModelData().apply {
addMesh(ModelMesh().apply {
id = "floormodel"
attributes = arrayOf(VertexAttribute.Position(), VertexAttribute.Normal(), VertexAttribute.Tangent(), VertexAttribute.Binormal(), VertexAttribute.TexCoords(0))
vertices =
vertex(Vector3(0.0f, 0.0f, 0.0f), Vector2(0.0f, texs)) +
vertex(Vector3(size, 0.0f, 0.0f), Vector2(texs, texs)) +
vertex(Vector3(0.0f, 0.0f, -size), Vector2(0.0f, 0.0f)) +
vertex(Vector3(size, 0.0f, -size), Vector2(texs, 0.0f))
parts = arrayOf(ModelMeshPart().apply {
id = "floormesh"
primitiveType = GL20.GL_TRIANGLES
indices = shortArrayOf(
0, 1, 2,
3, 2, 1)
})
})
materials.add(ModelMaterial().apply {
id = "floormat"
diffuse = XnaColor.White
specular = XnaColor.BlanchedAlmond.mix(XnaColor.Black, 0.12f)
shininess = 65.0f
textures = Array()
textures.add(
modelTexture(ModelTexture.USAGE_DIFFUSE, "cobblestone.png"),
modelTexture(ModelTexture.USAGE_NORMAL, "cobblestone_normal.png"),
modelTexture(ModelTexture.USAGE_BUMP, "cobblestone_bump.png"),
modelTexture(ModelTexture.USAGE_SPECULAR, "cobblestone_specular.png"))
})
nodes.add(ModelNode().apply {
id = "floornode"
scale = Util.one
parts = arrayOf(ModelNodePart().apply {
meshPartId = "floormesh"
materialId = "floormat"
})
})
}, AssetTextureProvider(assetManager)).apply {
materials[0].set(CustomFloatAttribute.createBumpHeight(0.0075f))
}
}
override fun create()
@@ -133,29 +119,34 @@ class Game: ApplicationAdapter()
Resources.instance.loadAssets()
assetManager.finishLoading()
texJolk = assetManager.get("jolkmeup.jpg")
fntComic = assetManager.get("Comic Sans MS.ttf")
val suzanne = assetManager.get("suzanne.g3db", Model::class.java)
// Override ridiculous shininess because i cbf to fix the model
for (i in suzanne.materials)
i.set(FloatAttribute.createShininess(30.0f))
cube = makeCube(texJolk)
floor = makeFloor()
cube = makeCube(2.0f, Material(
ColorAttribute.createDiffuse(XnaColor.White),
TextureAttribute(TextureAttribute.Diffuse, TextureDescriptor(assetManager.get("jolkmeup.jpg"))),
ColorAttribute.createSpecular(XnaColor.Gray),
FloatAttribute.createShininess(20.0f)))
toybox = assetManager.get("toybox.g3db", Model::class.java).apply { materials[0].set(
TextureAttribute(TextureAttribute.Diffuse, TextureDescriptor(assetManager.get("toybox_albedo.png"))),
TextureAttribute(TextureAttribute.Normal, TextureDescriptor(assetManager.get("toybox_normal.png"))),
TextureAttribute(TextureAttribute.Bump, TextureDescriptor(assetManager.get("toybox_displace.png"))),
CustomFloatAttribute.createBumpHeight(0.04f),
FloatAttribute.createShininess(35.0f)) }
val joeMany = 56.0f
floor = makeFloor(joeMany)
spriteBatch = SpriteBatch()
env = Environment()
env.set(
IntAttribute.createCullFace(GL20.GL_BACK),
ColorAttribute.createAmbientLight(XnaColor.DarkSlateGray.lighten(-0.6)),
ColorAttribute.createAmbientLight(XnaColor.DarkSlateGray.lighten(-0.666)),
ColorAttribute.createFog(XnaColor.CornflowerBlue))
env.set(
CustomIntAttribute.createFogMode(CustomIntAttribute.FogModes.Depth),
CustomIntAttribute.createFogType(CustomIntAttribute.FogTypes.Smooth),
CustomFloatAttribute.createFogNear(0.75f),
CustomFloatAttribute.createFogFar(20.5f))
CustomFloatAttribute.createFogNear(1.25f),
CustomFloatAttribute.createFogFar(24.5f))
/*
env.set(
CustomIntAttribute.createFogMode(CustomIntAttribute.FogModes.Distance),
@@ -163,12 +154,21 @@ class Game: ApplicationAdapter()
CustomFloatAttribute.createFogDensity(0.1f))
*/
env.add(DirectionalLight().set(
XnaColor.BlanchedAlmond.lighten(0.01),
XnaColor.BlanchedAlmond.lighten(-0.02).mix(XnaColor.LightSlateGray, 0.5f).mix(XnaColor.White, 0.125f),
Vector3(1.0f, -1.0f, -1.0f).nor()))
env.add(PointLight().set(
XnaColor.Green.mix(XnaColor.Gray, 0.5f),
Vector3(3.0f, 0.33f, -5.0f), 2.0f))
env.add(PointLight().set(
XnaColor.Red.mix(XnaColor.Gray, 0.5f),
Vector3(5.5f, 0.33f, -6.0f), 2.0f))
env.add(PointLight().set(
XnaColor.Blue.mix(XnaColor.Gray, 0.5f),
Vector3(4.0f, 0.33f, -7.0f), 2.0f))
val shaderConfig = DefaultShader.Config()
shaderConfig.numDirectionalLights = 1
shaderConfig.numPointLights = 0
shaderConfig.numPointLights = 3
shaderConfig.numBones = 0
modelBatch = ModelBatch(CustomDefaultShaderProvider(shaderConfig))
@@ -176,8 +176,11 @@ class Game: ApplicationAdapter()
cubeInstance = ModelInstance(cube)
floorInstance = ModelInstance(floor)
suzanneInstance = ModelInstance(suzanne)
suzanneInstance = ModelInstance(assetManager.get("suzanne.g3db", Model::class.java))
suzanneInstance.transform = Matrix4().translate(3.0f, 1.0f, -3.5f)
knux = ModelInstance(assetManager.get("knux.g3db", Model::class.java))
toyboxInstance = ModelInstance(toybox)
}
override fun resize(width: Int, height: Int)
@@ -192,6 +195,7 @@ class Game: ApplicationAdapter()
{
colin.update(deltaTime)
lightTheta += deltaTime
jolkRot += 15.0f * deltaTime
}
@@ -202,6 +206,28 @@ class Game: ApplicationAdapter()
ScreenUtils.clear(XnaColor.CornflowerBlue, true)
env.get(PointLightsAttribute.Type)?.let { it as PointLightsAttribute
var thetaa = lightTheta * 6.0f * 0.12f
var thetab = lightTheta * 6.0f * 0.011f
var thetac = lightTheta * 6.0f * 0.056f
for (light in it.lights)
{
val x = 4.0f + 6.0f * MathUtils.cos(thetaa)
val z = -6.0f + 3.0f * MathUtils.sin(thetaa * 2.0f)
val y = 0.33f + 0.33f * MathUtils.sin(thetab)
val i = 3.1f + 1.53f * MathUtils.cos(thetac)
val spacing = 0.5f * MathUtils.PI * (2.0f / 3.0f)
thetaa += spacing
thetab += spacing * 0.98f
thetac += spacing * 0.5566f
light.setPosition(x, y, z)
light.setIntensity(i)
}
}
val jolkPos = Vector3(0.0f, 1.0f + MathUtils.sin(jolkRot * 0.25f) * 0.25f, -4.0f)
val world = Matrix4()
.setTranslation(jolkPos)
@@ -209,11 +235,21 @@ class Game: ApplicationAdapter()
.rotate(0.0f, 1.0f, 0.0f, jolkRot)
.scale(0.25f, 0.25f, 0.25f)
cubeInstance.transform = world
knux.transform.rotate(Quaternion().slerp(rand.nextQuaternion(), deltaTime))
knux.transform.translate(knux.transform * Util.forward * deltaTime)
toyboxInstance.transform = Matrix4(
Vector3(6.0f, 0.667f, -3.5f),
Quaternion().setEulerAnglesRad(lightTheta * 0.5f, 0.0f, 0.0f),
Util.one * 0.25f
)
modelBatch.begin(colin.camera)
modelBatch.render(floorInstance, env)
modelBatch.render(cubeInstance, env)
modelBatch.render(suzanneInstance, env)
modelBatch.render(knux, env)
modelBatch.render(toyboxInstance, env)
modelBatch.end()
spriteBatch.begin()

View File

@@ -1,6 +1,7 @@
package gay.pizza.CavesOfJolk
import com.badlogic.gdx.assets.AssetManager
import com.badlogic.gdx.assets.loaders.TextureLoader
import com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver
import com.badlogic.gdx.audio.Sound
import com.badlogic.gdx.graphics.Texture
@@ -30,13 +31,37 @@ class Resources private constructor()
assetManager.setLoader(BitmapFont::class.java, ".ttf", FreetypeFontLoader(resolver))
}
val linearMipped = TextureLoader.TextureParameter().apply {
minFilter = Texture.TextureFilter.MipMapLinearLinear
magFilter = Texture.TextureFilter.Linear
wrapU = Texture.TextureWrap.Repeat
wrapV = Texture.TextureWrap.Repeat
genMipMaps = true
}
val linearClamp = TextureLoader.TextureParameter().apply {
minFilter = Texture.TextureFilter.Linear
magFilter = Texture.TextureFilter.Linear
wrapU = Texture.TextureWrap.ClampToEdge
wrapV = Texture.TextureWrap.ClampToEdge
}
fun loadAssets()
{
assetManager.load("colin.png", Texture::class.java)
assetManager.load("jolkmeup.jpg", Texture::class.java)
assetManager.load("jolkmeup.jpg", Texture::class.java, linearClamp)
assetManager.loadFont("Comic Sans MS.ttf", 20)
assetManager.load("suzanne.g3db", Model::class.java)
assetManager.load("nut.wav", Sound::class.java)
assetManager.load("cobblestone.png", Texture::class.java, linearMipped)
assetManager.load("cobblestone_normal.png", Texture::class.java, linearMipped)
assetManager.load("cobblestone_specular.png", Texture::class.java, linearMipped)
assetManager.load("knux.g3db", Model::class.java)
assetManager.load("toybox.g3db", Model::class.java)
assetManager.load("cobblestone_bump.png", Texture::class.java, linearMipped)
assetManager.load("toybox_albedo.png", Texture::class.java, linearMipped)
assetManager.load("toybox_normal.png", Texture::class.java, linearMipped)
assetManager.load("toybox_displace.png", Texture::class.java, linearMipped)
}
}

View File

@@ -3,12 +3,13 @@ package gay.pizza.CavesOfJolk
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g3d.Attribute
import com.badlogic.gdx.graphics.g3d.Attributes
import com.badlogic.gdx.math.MathUtils
import com.badlogic.gdx.math.Vector2
import com.badlogic.gdx.math.*
import ktx.math.div
import ktx.math.times
import ktx.math.unaryMinus
import org.hsluv.HUSLColorConverter
import kotlin.math.pow
import kotlin.random.Random
fun Float.axisDeadzone(min: Float, max: Float): Float
{
@@ -43,6 +44,12 @@ class Util
((abgr8888 and 0xFF00u) shr 8).toFloat() / 255.0f,
((abgr8888 and 0xFF0000u) shr 16).toFloat() / 255.0f,
((abgr8888 and 0xFF000000u) shr 24).toFloat() / 255.0f)
val zero get() = Vector3.Zero
val one get() = Vector3(1.0f, 1.0f, 1.0f)
val forward get() = -Vector3.Z
val right get() = Vector3.X
val up get() = Vector3.Y
}
}
@@ -64,3 +71,19 @@ fun Color.mix(rhs: Color, x: Float) = Color(
//FIXME: find some way to get rid of these warnings
@Suppress("EXTENSION_SHADOWED_BY_MEMBER", "UNCHECKED_CAST")
fun <T: Attribute> Attributes.get(type: Long) = get(type) as? T
fun Random.nextFloat(min: Float, max: Float) = min + nextFloat() * (max - min)
fun RandomXS128.nextQuaternion(): Quaternion
{
var x: Float
var y: Float
var z: Float
do { x = nextFloat(-1.0f, 1.0f); y = nextFloat(-1.0f, 1.0f); z = x * x + y * y } while (z > 1.0f)
var u: Float
var v: Float
var w: Float
do { u = nextFloat(-1.0f, 1.0f); v = nextFloat(-1.0f, 1.0f); w = u * u + v * v } while (w > 1.0f)
val s = kotlin.math.sqrt((1.0f - z) / w)
return Quaternion(x, y, s * u, s * v)
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 197 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 235 KiB

Binary file not shown.

View File

@@ -13,7 +13,7 @@ precision mediump float;
varying vec3 v_normal;
#endif // normalFlag
#if defined(tangentFlag) && defined(binormalFlag)
#if (defined(tangentFlag) && defined(binormalFlag)) || (defined(bumpHeightFlag) && defined(bumpTextureFlag))
varying mat3 v_tbn;
#endif // tangentFlag && bitangentFlag
@@ -28,6 +28,10 @@ varying vec4 v_color;
varying MEDP vec2 v_diffuseUV;
uniform sampler2D u_diffuseTexture;
#endif // diffuseTextureFlag
#ifdef bumpTextureFlag
varying MEDP vec2 v_bumpUV;
uniform sampler2D u_bumpTexture;
#endif // bumpTextureFlag
#ifdef normalTextureFlag
varying MEDP vec2 v_normalUV;
uniform sampler2D u_normalTexture;
@@ -60,6 +64,10 @@ uniform float u_shininess;
const float u_shininess = 20.0;
#endif // shininessFlag
#ifdef bumpHeightFlag
uniform float u_bumpHeight;
#endif // bumpHeightFlag
#if numDirectionalLights > 0
struct DirectionalLight
{
@@ -89,10 +97,10 @@ varying vec3 v_ambient;
#endif // lightingFlag
#if defined(specularFlag) || defined(fogFlag)
#if (numPointLights > 0) || defined(specularFlag) || defined(fogFlag)
varying vec4 v_worldPosition;
uniform vec4 u_cameraPosition;
#endif // lightingFlag || fogFlag
#endif // numPointLights > 0 || lightingFlag || fogFlag
#ifdef fogFlag
uniform vec4 u_fogColor;
@@ -114,14 +122,30 @@ vec3 linearDecode(vec3 v) { return vec3(pow(v.r, 1.0 / 2.2), pow(v.g, 1.0 / 2.2)
void main()
{
#if defined(specularFlag) || (defined(bumpHeightFlag) && defined(bumpTextureFlag))
vec3 eyeVec = normalize(u_cameraPosition.xyz - v_worldPosition.xyz);
#endif // specularFlag || (bumpHeightFlag && bumpTextureFlag)
#if defined(bumpHeightFlag) && defined(bumpTextureFlag)
float bumpHeight = (1.0 - texture2D(u_bumpTexture, v_bumpUV).r) * u_bumpHeight;
vec3 tbnEyeVec = normalize(mat3(
-v_tbn[0][0], v_tbn[1][0], v_tbn[2][0],
-v_tbn[0][1], v_tbn[1][1], v_tbn[2][1],
-v_tbn[0][2], v_tbn[1][2], v_tbn[2][2]
) * -eyeVec);
vec2 uvOffset = -tbnEyeVec.xy * bumpHeight;
#else // !(bumpHeightFlag && bumpTextureFlag)
vec2 uvOffset = vec2(0.0);
#endif // bumpHeightFlag && bumpTextureFlag
#if defined(diffuseTextureFlag) && defined(diffuseColorFlag) && defined(colorFlag)
vec4 diffuse = texture2D(u_diffuseTexture, v_diffuseUV) * u_diffuseColor * v_color;
vec4 diffuse = texture2D(u_diffuseTexture, v_diffuseUV + uvOffset) * u_diffuseColor * v_color;
#elif defined(diffuseTextureFlag) && defined(diffuseColorFlag)
vec4 diffuse = texture2D(u_diffuseTexture, v_diffuseUV) * u_diffuseColor;
vec4 diffuse = texture2D(u_diffuseTexture, v_diffuseUV + uvOffset) * u_diffuseColor;
#elif defined(diffuseTextureFlag) && defined(colorFlag)
vec4 diffuse = texture2D(u_diffuseTexture, v_diffuseUV) * v_color;
vec4 diffuse = texture2D(u_diffuseTexture, v_diffuseUV + uvOffset) * v_color;
#elif defined(diffuseTextureFlag)
vec4 diffuse = texture2D(u_diffuseTexture, v_diffuseUV);
vec4 diffuse = texture2D(u_diffuseTexture, v_diffuseUV + uvOffset);
#elif defined(diffuseColorFlag) && defined(colorFlag)
vec4 diffuse = u_diffuseColor * v_color;
#elif defined(diffuseColorFlag)
@@ -136,7 +160,7 @@ void main()
#ifdef lightingFlag
#if defined(normalFlag) && defined(tangentFlag) && defined(binormalFlag) && defined(normalTextureFlag)
vec3 normal = vec3(2.0 * texture2D(u_normalTexture, v_normalUV).rgb - 1.0);
vec3 normal = vec3(2.0 * texture2D(u_normalTexture, v_normalUV + uvOffset).rgb - 1.0);
normal = normalize(v_tbn * normal);
#elif defined(normalFlag)
vec3 normal = normalize(v_normal);
@@ -149,7 +173,6 @@ void main()
#endif // ambientFlag
#ifdef specularFlag
vec3 eyeVec = normalize(u_cameraPosition.xyz - v_worldPosition.xyz);
vec3 specAccum = vec3(0.0);
#endif // specularFlag
@@ -159,7 +182,7 @@ void main()
vec3 lightVec = -u_dirLights[i].direction;
float lambert = dot(normal, lightVec);
float phongTerm = max(lambert, 0.0);
vec3 value = u_dirLights[i].color * phongTerm;
vec3 value = u_dirLights[i].color;
value = linearEncode(value);
value *= phongTerm;
accum += value;
@@ -172,10 +195,36 @@ void main()
}
#endif // normalFlag && numDirectionalLights
#if defined(normalFlag) && (numPointLights > 0)
for (int i = 0; i < numPointLights; ++i)
{
vec3 lightVec = u_pointLights[i].position - v_worldPosition.xyz;
float lightDist2 = dot(lightVec, lightVec);
vec3 lightDir = lightVec;
lightDir *= inversesqrt(lightDist2);
float lambert = dot(normal, lightDir);
float phongTerm = max(lambert, 0.0);
//float lightDist = sqrt(lightDist2);
//float attenuation = clamp(1.0 - lightDist * lightDist / (2.0 * 2.0), 0.0, 1.0);
//attenuation *= attenuation;
float attenuation = 1.0 / (1.0 + lightDist2);
vec3 value = u_pointLights[i].color;
value = linearEncode(value);
value *= phongTerm * attenuation;
accum += value;
#ifdef specularFlag
vec3 halfDir = normalize(lightDir + eyeVec);
float specAngle = max(dot(halfDir, normal), 0.0);
float specTerm = pow(specAngle, u_shininess);
specAccum += value * specTerm;
#endif // specularFlag
}
#endif
vec3 fragment;
#ifdef specularFlag
#ifdef specularTextureFlag
vec3 specularColorTex = texture2D(u_specularTexture, v_specularUV).rgb;
vec3 specularColorTex = texture2D(u_specularTexture, v_specularUV + uvOffset).rgb;
specularColorTex = linearEncode(specularColorTex);
specAccum *= specularColorTex;
#endif // specularTextureFlag
@@ -229,5 +278,6 @@ void main()
fogColor = linearEncode(fogColor);
fragment = mix(fragment, fogColor, fog);
#endif // fogFlag
gl_FragColor = vec4(linearDecode(fragment), diffuse.a);
}

View File

@@ -7,7 +7,7 @@ uniform mat3 u_normalMatrix;
varying vec3 v_normal;
#endif // normalFlag
#if defined(tangentFlag) && defined(binormalFlag)
#if (defined(tangentFlag) && defined(binormalFlag)) || (defined(bumpHeightFlag) && defined(bumpTextureFlag))
attribute vec3 a_tangent;
attribute vec3 a_binormal;
varying mat3 v_tbn;
@@ -35,6 +35,11 @@ uniform vec4 u_diffuseUVTransform;
varying vec2 v_diffuseUV;
#endif // diffuseTextureFlag
#ifdef bumpTextureFlag
uniform vec4 u_bumpUVTransform;
varying vec2 v_bumpUV;
#endif // bumpTextureFlag
#ifdef normalTextureFlag
uniform vec4 u_normalUVTransform;
varying vec2 v_normalUV;
@@ -104,6 +109,10 @@ void main()
v_diffuseUV = u_diffuseUVTransform.xy + a_texCoord0 * u_diffuseUVTransform.zw;
#endif // diffuseTextureFlag
#ifdef bumpTextureFlag
v_bumpUV = u_bumpUVTransform.xy + a_texCoord0 * u_bumpUVTransform.zw;
#endif // bumpTextureFlag
#ifdef normalTextureFlag
v_normalUV = u_normalUVTransform.xy + a_texCoord0 * u_normalUVTransform.zw;
#endif // normalTextureFlag

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 656 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 881 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 475 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 127 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 580 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 295 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 449 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 433 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 B

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 145 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 231 KiB