commit 6d6bc6ec572ac989324fc33f5d8954b9546dab08 Author: a dinosaur Date: Wed Aug 16 13:10:48 2023 +1000 seedy projeckt jolked diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f35ca9e --- /dev/null +++ b/.gitignore @@ -0,0 +1,39 @@ +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### IntelliJ IDEA ### +.idea/ +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..bd66a1e --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,46 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + kotlin("jvm") version "1.9.0" + application +} + +group = "gay.pizza" +version = "1.0-SNAPSHOT" + +repositories { + mavenCentral() +} + +dependencies { + implementation(kotlin("stdlib")) + val gdxVersion: String by rootProject + val ktxVersion: String by rootProject + val gdxControllersVersion: String by rootProject + val hsluvVersion: String by rootProject + implementation("com.badlogicgames.gdx:gdx:$gdxVersion") + implementation("com.badlogicgames.gdx:gdx-backend-lwjgl3:$gdxVersion") + implementation("com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop") + implementation("com.badlogicgames.gdx:gdx-freetype:$gdxVersion") + implementation("com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop") + implementation("com.badlogicgames.gdx-controllers:gdx-controllers-core:$gdxControllersVersion") + implementation("com.badlogicgames.gdx-controllers:gdx-controllers-desktop:$gdxControllersVersion") + implementation("io.github.libktx:ktx-math:$ktxVersion") + implementation("org.hsluv:hsluv:$hsluvVersion") +} + +tasks.withType { + val kotlinOptionsJvmTarget: String by rootProject + kotlinOptions.jvmTarget = kotlinOptionsJvmTarget +} + +java { + val javaVersionCompatibility: String by rootProject + sourceCompatibility = JavaVersion.toVersion(javaVersionCompatibility) + targetCompatibility = JavaVersion.toVersion(javaVersionCompatibility) +} + +application { + mainClass.set("gay.pizza.CavesOfJolk.Program") + applicationDefaultJvmArgs = listOf("-XstartOnFirstThread") // Make MacOS happy +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..3970161 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,9 @@ +#org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 + +gdxVersion = 1.12.0 +ktxVersion = 1.12.0-rc1 +gdxControllersVersion = 2.2.3 +hsluvVersion = 0.3 + +javaVersionCompatibility = 1.8 +kotlinOptionsJvmTarget = 1.8 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..943f0cb Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..17a8ddc --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip +networkTimeout=10000 +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..65dcd68 --- /dev/null +++ b/gradlew @@ -0,0 +1,244 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..93e3f59 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..cf9328f --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,3 @@ + +rootProject.name = "CavesOfJolk" + diff --git a/src/main/kotlin/Colin.kt b/src/main/kotlin/Colin.kt new file mode 100644 index 0000000..51a1d5e --- /dev/null +++ b/src/main/kotlin/Colin.kt @@ -0,0 +1,105 @@ +package gay.pizza.CavesOfJolk + +import com.badlogic.gdx.Gdx +import com.badlogic.gdx.Input +import com.badlogic.gdx.audio.Sound +import com.badlogic.gdx.controllers.Controllers +import com.badlogic.gdx.graphics.PerspectiveCamera +import com.badlogic.gdx.graphics.Texture +import com.badlogic.gdx.graphics.g2d.SpriteBatch +import com.badlogic.gdx.graphics.g2d.TextureRegion +import com.badlogic.gdx.math.MathUtils +import com.badlogic.gdx.math.Vector2 +import com.badlogic.gdx.math.Vector3 +import gay.pizza.CavesOfJolk.Resources.Companion.assetManager +import ktx.math.minusAssign +import ktx.math.plusAssign +import ktx.math.times + +class Colin +{ + private var pos = Vector2() + private var angle = 0.0f + private var cam: PerspectiveCamera + private var nutted = false + + private var texture: Texture = assetManager.get("colin.png") + private val nut: Sound = assetManager.get("nut.wav") + + init + { + cam = PerspectiveCamera(60.0f, + Gdx.graphics.width.toFloat(), + Gdx.graphics.height.toFloat()) + cam.near = 0.1f + cam.far = 40.0f + } + + 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) + cam.direction.set(forward.rotateRad(up, angle)) + cam.update() + } + + fun update(deltaTime: Float) + { + val stick = Controllers.getCurrent()?.let { pad -> + Vector2( + pad.getAxis(pad.mapping.axisLeftX), + pad.getAxis(pad.mapping.axisLeftY)) + .cardinalDeadzone(0.1f, 1.0f) + } ?: Vector2() + + val turnSpeed = MathUtils.PI2 * 0.1f + if (Gdx.input.isKeyPressed(Input.Keys.LEFT)) + angle += turnSpeed * deltaTime + if (Gdx.input.isKeyPressed(Input.Keys.RIGHT)) + angle -= turnSpeed * deltaTime + if (!stick.isZero) + angle -= stick.x * 2.0f * turnSpeed * deltaTime + + val speed = 2.0f + val forward = Vector2(-MathUtils.sin(angle), -MathUtils.cos(angle)) + if (Gdx.input.isKeyPressed(Input.Keys.UP)) + pos += forward * speed * deltaTime + if (Gdx.input.isKeyPressed(Input.Keys.DOWN)) + pos -= forward * speed * deltaTime + if (!stick.isZero) + pos -= forward * stick.y * speed * deltaTime + + if (Controllers.getCurrent()?.let { pad -> pad.getButton(pad.mapping.buttonA) } == true || Gdx.input.isKeyJustPressed(Input.Keys.N)) + { + if (!nutted) + { + nut.stop() + nut.play() + nutted = true + } + } + else + { + nutted = false + } + + updateCamera() + } + + 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) + + } + + val camera get() = cam + val position get() = pos +} diff --git a/src/main/kotlin/Game.kt b/src/main/kotlin/Game.kt new file mode 100644 index 0000000..c90bef2 --- /dev/null +++ b/src/main/kotlin/Game.kt @@ -0,0 +1,155 @@ +package gay.pizza.CavesOfJolk + +import com.badlogic.gdx.ApplicationAdapter +import com.badlogic.gdx.Gdx +import com.badlogic.gdx.audio.Sound +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.IntAttribute +import com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute +import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight +import com.badlogic.gdx.graphics.g3d.shaders.DefaultShader +import com.badlogic.gdx.graphics.g3d.utils.DefaultShaderProvider +import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder +import com.badlogic.gdx.graphics.g3d.utils.TextureDescriptor +import com.badlogic.gdx.math.* +import com.badlogic.gdx.utils.ScreenUtils +import gay.pizza.CavesOfJolk.Resources.Companion.assetManager + +class Game: ApplicationAdapter() +{ + private lateinit var texJolk: Texture + private lateinit var fntComic: BitmapFont + private lateinit var nut: Sound + private lateinit var cube: Model + private lateinit var floor: Model + + private lateinit var spriteBatch: SpriteBatch + private lateinit var modelBatch: ModelBatch + private lateinit var env: Environment + + private lateinit var colin: Colin + private var jolkRot = 0.0f + + private lateinit var cubeInstance: ModelInstance + private lateinit var floorInstance: ModelInstance + private lateinit var suzanneInstance: ModelInstance + + private fun makeCube(texture: Texture): Model + { + val modelBuilder = ModelBuilder() + val size = 2.0f + //val material = Material(ColorAttribute.createDiffuse(Color.WHITE)) + val material = Material(TextureAttribute(TextureAttribute.Diffuse, + TextureDescriptor(texture, + Texture.TextureFilter.Linear, + Texture.TextureFilter.Linear, + Texture.TextureWrap.ClampToEdge, + Texture.TextureWrap.ClampToEdge))) + val attribs = VertexAttributes.Usage.Position or VertexAttributes.Usage.TextureCoordinates or VertexAttributes.Usage.Normal + return modelBuilder.createBox(size, size, size, material, attribs.toLong()) + } + + private fun makeFloor(texture: Texture): Model + { + val modelBuilder = ModelBuilder() + //val material = Material(ColorAttribute.createDiffuse(XnaColor.BlanchedAlmond)) + val material = Material(TextureAttribute.createDiffuse(texture)) + val attribs = VertexAttributes.Usage.Position or VertexAttributes.Usage.TextureCoordinates or VertexAttributes.Usage.Normal + val size = 10.0f + return modelBuilder.createRect( + 0.0f, 0.0f, 0.0f, + size, 0.0f, 0.0f, + size, 0.0f, -size, + 0.0f, 0.0f, -size, + 0.0f, 1.0f, 0.0f, + material, attribs.toLong()) + } + + override fun create() + { + Resources.instance.loadAssets() + assetManager.finishLoading() + + texJolk = assetManager.get("jolkmeup.jpg") + fntComic = assetManager.get("Comic Sans MS.ttf") + + + cube = makeCube(texJolk) + floor = makeFloor(assetManager.get("cobblestone.png")) + + spriteBatch = SpriteBatch() + + env = Environment() + env.set(IntAttribute.createCullFace(GL20.GL_BACK)) + env.set(ColorAttribute.createAmbientLight(XnaColor.DarkSlateGray.lighten(-0.6))) + env.set(ColorAttribute.createFog(XnaColor.CornflowerBlue)) + env.add(DirectionalLight().set(XnaColor.White, Vector3(1.0f, -1.0f, -1.0f).nor())) + + val shaderConfig = DefaultShader.Config( + Gdx.files.internal("lit.vert.glsl").readString(), + Gdx.files.internal("lit.frag.glsl").readString()) + shaderConfig.numDirectionalLights = 1 + shaderConfig.numPointLights = 0 + shaderConfig.numBones = 0 + modelBatch = ModelBatch(DefaultShaderProvider(shaderConfig)) + + colin = Colin() + + cubeInstance = ModelInstance(cube) + floorInstance = ModelInstance(floor) + suzanneInstance = ModelInstance(assetManager.get("suzanne.g3db", Model::class.java)) + suzanneInstance.transform = Matrix4().translate(3.0f, 1.0f, -3.5f) + } + + private fun update(deltaTime: Float) + { + colin.update(deltaTime) + + jolkRot += 15.0f * deltaTime + } + + override fun render() + { + val deltaTime = Gdx.graphics.deltaTime + update(deltaTime) + + val fogColour = XnaColor.CornflowerBlue.lighten(Math.sin(0.056 * jolkRot.toDouble()) * 0.15 - 0.15) + ScreenUtils.clear(fogColour, true) + env.set(ColorAttribute.createFog(fogColour)) + + val jolkPos = Vector3(0.0f, 1.0f + MathUtils.sin(jolkRot * 0.25f) * 0.25f, -4.0f) + val world = Matrix4() + .setTranslation(jolkPos) + .rotateRad(1.0f, 0.0f, 0.0f, jolkRot * 0.25f) + .rotate(0.0f, 1.0f, 0.0f, jolkRot) + .scale(0.25f, 0.25f, 0.25f) + cubeInstance.transform = world + + modelBatch.begin(colin.camera) + modelBatch.render(floorInstance, env) + modelBatch.render(cubeInstance, env) + modelBatch.render(suzanneInstance, env) + modelBatch.end() + + spriteBatch.begin() + colin.draw(spriteBatch) + val textPos = colin.camera.project(jolkPos) + if (textPos.z < 1.0) + fntComic.draw(spriteBatch, "I am filled with jolk", textPos.x, textPos.y) + fntComic.draw(spriteBatch, "${colin.position.x}\n${colin.position.y}", 10.0f, Gdx.graphics.height - 10.0f) + spriteBatch.end() + } + + override fun dispose() + { + floor.dispose() + cube.dispose() + modelBatch.dispose() + spriteBatch.dispose() + assetManager.dispose() + } +} diff --git a/src/main/kotlin/Program.kt b/src/main/kotlin/Program.kt new file mode 100644 index 0000000..0be1989 --- /dev/null +++ b/src/main/kotlin/Program.kt @@ -0,0 +1,19 @@ +@file:JvmName("Program") +package gay.pizza.CavesOfJolk + +import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application +import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration +import com.badlogic.gdx.graphics.glutils.HdpiMode + +fun main() +{ + //val conf = Lwjgl3WindowConfiguration() + val conf = Lwjgl3ApplicationConfiguration() + conf.setTitle("Caves of Jolk: Ultimate Edition") + conf.setHdpiMode(HdpiMode.Logical) + //conf.useVsync(false) + //conf.setForegroundFPS(300) + conf.setWindowedMode(1280, 720) + conf.setResizable(false) + Lwjgl3Application(Game(), conf) +} diff --git a/src/main/kotlin/Resources.kt b/src/main/kotlin/Resources.kt new file mode 100644 index 0000000..1600a86 --- /dev/null +++ b/src/main/kotlin/Resources.kt @@ -0,0 +1,50 @@ +package gay.pizza.CavesOfJolk + +import com.badlogic.gdx.assets.AssetManager +import com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver +import com.badlogic.gdx.audio.Sound +import com.badlogic.gdx.graphics.Texture +import com.badlogic.gdx.graphics.g2d.BitmapFont +import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator +import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGeneratorLoader +import com.badlogic.gdx.graphics.g2d.freetype.FreetypeFontLoader +import com.badlogic.gdx.graphics.g3d.Model + + +class Resources private constructor() +{ + companion object + { + @Volatile private var _instance: Resources? = null + + val instance get() = _instance ?: synchronized(this) { _instance ?: Resources().also { _instance = it } } + val assetManager get() = instance.assetManager + } + + private val assetManager: AssetManager = AssetManager() + + init + { + val resolver = InternalFileHandleResolver() + assetManager.setLoader(FreeTypeFontGenerator::class.java, FreeTypeFontGeneratorLoader(resolver)) + assetManager.setLoader(BitmapFont::class.java, ".ttf", FreetypeFontLoader(resolver)) + } + + fun loadAssets() + { + assetManager.load("colin.png", Texture::class.java) + assetManager.load("jolkmeup.jpg", Texture::class.java) + assetManager.load("cobblestone.png", Texture::class.java) + assetManager.loadFont("Comic Sans MS.ttf", 20) + assetManager.load("suzanne.g3db", Model::class.java) + assetManager.load("nut.wav", Sound::class.java) + } +} + +fun AssetManager.loadFont(filePath: String, size: Int) +{ + val fontParam = FreetypeFontLoader.FreeTypeFontLoaderParameter() + fontParam.fontFileName = filePath + fontParam.fontParameters.size = size + this.load(filePath, BitmapFont::class.java, fontParam) +} diff --git a/src/main/kotlin/Util.kt b/src/main/kotlin/Util.kt new file mode 100644 index 0000000..43776d0 --- /dev/null +++ b/src/main/kotlin/Util.kt @@ -0,0 +1,53 @@ +package gay.pizza.CavesOfJolk + +import com.badlogic.gdx.graphics.Color +import com.badlogic.gdx.math.Vector2 +import ktx.math.div +import ktx.math.times +import org.hsluv.HUSLColorConverter +import kotlin.math.pow + +fun Float.axisDeadzone(min: Float, max: Float): Float +{ + val xabs = Math.abs(this) + return if (xabs <= min) 0.0f + else if (xabs >= max) Math.copySign(1.0f, this) + else Math.copySign(xabs - min, this) / (max - min) +} + +fun Vector2.cardinalDeadzone(min: Float, max: Float) += Vector2(this.x.axisDeadzone(min, max), this.y.axisDeadzone(min, max)) + +fun Vector2.radialDeadzone(min: Float, max: Float): Vector2 +{ + val magnitude = this.len() + if (magnitude == 0.0f || magnitude < min) + return Vector2() + if (magnitude > max) + return this / magnitude + val rescale = (magnitude - min) / (max - min) + return this / magnitude * rescale +} + +val Double.saturate get() = if (this > 1.0) 1.0 else if (this < 0.0) 0.0 else this + +class Util +{ + companion object + { + public fun colorFromAbgr8888(abgr8888: UInt) = Color( + (abgr8888 and 0xFFu).toFloat() / 255.0f, + ((abgr8888 and 0xFF00u) shr 8).toFloat() / 255.0f, + ((abgr8888 and 0xFF0000u) shr 16).toFloat() / 255.0f, + ((abgr8888 and 0xFF000000u) shr 24).toFloat() / 255.0f) + } +} + +fun Color.lighten(ld: Double): Color +{ + val hsl = HUSLColorConverter.rgbToHsluv(doubleArrayOf(r.toDouble(), g.toDouble(), b.toDouble())) + val gamma = 3.0 + hsl[2] = ((hsl[2] / 100.0).pow(1.0 / gamma) + ld * 0.8).saturate.pow(gamma) * 100.0 + val rgb = HUSLColorConverter.hsluvToRgb(hsl) + return Color(rgb[0].toFloat(), rgb[1].toFloat(), rgb[2].toFloat(), a) +} diff --git a/src/main/kotlin/XnaColor.kt b/src/main/kotlin/XnaColor.kt new file mode 100644 index 0000000..0fd8087 --- /dev/null +++ b/src/main/kotlin/XnaColor.kt @@ -0,0 +1,147 @@ +package gay.pizza.CavesOfJolk + +object XnaColor +{ + val Transparent = Util.colorFromAbgr8888(0x00000000u) + val AliceBlue = Util.colorFromAbgr8888(0xFFFFF8F0u) + val AntiqueWhite = Util.colorFromAbgr8888(0xFFD7EBFAu) + val Aqua = Util.colorFromAbgr8888(0xFFFFFF00u) + val Aquamarine = Util.colorFromAbgr8888(0xFFD4FF7Fu) + val Azure = Util.colorFromAbgr8888(0xFFFFFFF0u) + val Beige = Util.colorFromAbgr8888(0xFFDCF5F5u) + val Bisque = Util.colorFromAbgr8888(0xFFC4E4FFu) + val Black = Util.colorFromAbgr8888(0xFF000000u) + val BlanchedAlmond = Util.colorFromAbgr8888(0xFFCDEBFFu) + val Blue = Util.colorFromAbgr8888(0xFFFF0000u) + val BlueViolet = Util.colorFromAbgr8888(0xFFE22B8Au) + val Brown = Util.colorFromAbgr8888(0xFF2A2AA5u) + val BurlyWood = Util.colorFromAbgr8888(0xFF87B8DEu) + val CadetBlue = Util.colorFromAbgr8888(0xFFA09E5Fu) + val Chartreuse = Util.colorFromAbgr8888(0xFF00FF7Fu) + val Chocolate = Util.colorFromAbgr8888(0xFF1E69D2u) + val Coral = Util.colorFromAbgr8888(0xFF507FFFu) + val CornflowerBlue = Util.colorFromAbgr8888(0xFFED9564u) + val Cornsilk = Util.colorFromAbgr8888(0xFFDCF8FFu) + val Crimson = Util.colorFromAbgr8888(0xFF3C14DCu) + val Cyan = Util.colorFromAbgr8888(0xFFFFFF00u) + val DarkBlue = Util.colorFromAbgr8888(0xFF8B0000u) + val DarkCyan = Util.colorFromAbgr8888(0xFF8B8B00u) + val DarkGoldenrod = Util.colorFromAbgr8888(0xFF0B86B8u) + val DarkGray = Util.colorFromAbgr8888(0xFFA9A9A9u) + val DarkGreen = Util.colorFromAbgr8888(0xFF006400u) + val DarkKhaki = Util.colorFromAbgr8888(0xFF6BB7BDu) + val DarkMagenta = Util.colorFromAbgr8888(0xFF8B008Bu) + val DarkOliveGreen = Util.colorFromAbgr8888(0xFF2F6B55u) + val DarkOrange = Util.colorFromAbgr8888(0xFF008CFFu) + val DarkOrchid = Util.colorFromAbgr8888(0xFFCC3299u) + val DarkRed = Util.colorFromAbgr8888(0xFF00008Bu) + val DarkSalmon = Util.colorFromAbgr8888(0xFF7A96E9u) + val DarkSeaGreen = Util.colorFromAbgr8888(0xFF8BBC8Fu) + val DarkSlateBlue = Util.colorFromAbgr8888(0xFF8B3D48u) + val DarkSlateGray = Util.colorFromAbgr8888(0xFF4F4F2Fu) + val DarkTurquoise = Util.colorFromAbgr8888(0xFFD1CE00u) + val DarkViolet = Util.colorFromAbgr8888(0xFFD30094u) + val DeepPink = Util.colorFromAbgr8888(0xFF9314FFu) + val DeepSkyBlue = Util.colorFromAbgr8888(0xFFFFBF00u) + val DimGray = Util.colorFromAbgr8888(0xFF696969u) + val DodgerBlue = Util.colorFromAbgr8888(0xFFFF901Eu) + val Firebrick = Util.colorFromAbgr8888(0xFF2222B2u) + val FloralWhite = Util.colorFromAbgr8888(0xFFF0FAFFu) + val ForestGreen = Util.colorFromAbgr8888(0xFF228B22u) + val Fuchsia = Util.colorFromAbgr8888(0xFFFF00FFu) + val Gainsboro = Util.colorFromAbgr8888(0xFFDCDCDCu) + val GhostWhite = Util.colorFromAbgr8888(0xFFFFF8F8u) + val Gold = Util.colorFromAbgr8888(0xFF00D7FFu) + val Goldenrod = Util.colorFromAbgr8888(0xFF20A5DAu) + val Gray = Util.colorFromAbgr8888(0xFF808080u) + val Green = Util.colorFromAbgr8888(0xFF008000u) + val GreenYellow = Util.colorFromAbgr8888(0xFF2FFFADu) + val Honeydew = Util.colorFromAbgr8888(0xFFF0FFF0u) + val HotPink = Util.colorFromAbgr8888(0xFFB469FFu) + val IndianRed = Util.colorFromAbgr8888(0xFF5C5CCDu) + val Indigo = Util.colorFromAbgr8888(0xFF82004Bu) + val Ivory = Util.colorFromAbgr8888(0xFFF0FFFFu) + val Khaki = Util.colorFromAbgr8888(0xFF8CE6F0u) + val Lavender = Util.colorFromAbgr8888(0xFFFAE6E6u) + val LavenderBlush = Util.colorFromAbgr8888(0xFFF5F0FFu) + val LawnGreen = Util.colorFromAbgr8888(0xFF00FC7Cu) + val LemonChiffon = Util.colorFromAbgr8888(0xFFCDFAFFu) + val LightBlue = Util.colorFromAbgr8888(0xFFE6D8ADu) + val LightCoral = Util.colorFromAbgr8888(0xFF8080F0u) + val LightCyan = Util.colorFromAbgr8888(0xFFFFFFE0u) + val LightGoldenrodYellow = Util.colorFromAbgr8888(0xFFD2FAFAu) + val LightGray = Util.colorFromAbgr8888(0xFFD3D3D3u) + val LightGreen = Util.colorFromAbgr8888(0xFF90EE90u) + val LightPink = Util.colorFromAbgr8888(0xFFC1B6FFu) + val LightSalmon = Util.colorFromAbgr8888(0xFF7AA0FFu) + val LightSeaGreen = Util.colorFromAbgr8888(0xFFAAB220u) + val LightSkyBlue = Util.colorFromAbgr8888(0xFFFACE87u) + val LightSlateGray = Util.colorFromAbgr8888(0xFF998877u) + val LightSteelBlue = Util.colorFromAbgr8888(0xFFDEC4B0u) + val LightYellow = Util.colorFromAbgr8888(0xFFE0FFFFu) + val Lime = Util.colorFromAbgr8888(0xFF00FF00u) + val LimeGreen = Util.colorFromAbgr8888(0xFF32CD32u) + val Linen = Util.colorFromAbgr8888(0xFFE6F0FAu) + val Magenta = Util.colorFromAbgr8888(0xFFFF00FFu) + val Maroon = Util.colorFromAbgr8888(0xFF000080u) + val MediumAquamarine = Util.colorFromAbgr8888(0xFFAACD66u) + val MediumBlue = Util.colorFromAbgr8888(0xFFCD0000u) + val MediumOrchid = Util.colorFromAbgr8888(0xFFD355BAu) + val MediumPurple = Util.colorFromAbgr8888(0xFFDB7093u) + val MediumSeaGreen = Util.colorFromAbgr8888(0xFF71B33Cu) + val MediumSlateBlue = Util.colorFromAbgr8888(0xFFEE687Bu) + val MediumSpringGreen = Util.colorFromAbgr8888(0xFF9AFA00u) + val MediumTurquoise = Util.colorFromAbgr8888(0xFFCCD148u) + val MediumVioletRed = Util.colorFromAbgr8888(0xFF8515C7u) + val MidnightBlue = Util.colorFromAbgr8888(0xFF701919u) + val MintCream = Util.colorFromAbgr8888(0xFFFAFFF5u) + val MistyRose = Util.colorFromAbgr8888(0xFFE1E4FFu) + val Moccasin = Util.colorFromAbgr8888(0xFFB5E4FFu) + val MonoGameOrange = Util.colorFromAbgr8888(0xFF003CE7u) + val NavajoWhite = Util.colorFromAbgr8888(0xFFADDEFFu) + val Navy = Util.colorFromAbgr8888(0xFF800000u) + val OldLace = Util.colorFromAbgr8888(0xFFE6F5FDu) + val Olive = Util.colorFromAbgr8888(0xFF008080u) + val OliveDrab = Util.colorFromAbgr8888(0xFF238E6Bu) + val Orange = Util.colorFromAbgr8888(0xFF00A5FFu) + val OrangeRed = Util.colorFromAbgr8888(0xFF0045FFu) + val Orchid = Util.colorFromAbgr8888(0xFFD670DAu) + val PaleGoldenrod = Util.colorFromAbgr8888(0xFFAAE8EEu) + val PaleGreen = Util.colorFromAbgr8888(0xFF98FB98u) + val PaleTurquoise = Util.colorFromAbgr8888(0xFFEEEEAFu) + val PaleVioletRed = Util.colorFromAbgr8888(0xFF9370DBu) + val PapayaWhip = Util.colorFromAbgr8888(0xFFD5EFFFu) + val PeachPuff = Util.colorFromAbgr8888(0xFFB9DAFFu) + val Peru = Util.colorFromAbgr8888(0xFF3F85CDu) + val Pink = Util.colorFromAbgr8888(0xFFCBC0FFu) + val Plum = Util.colorFromAbgr8888(0xFFDDA0DDu) + val PowderBlue = Util.colorFromAbgr8888(0xFFE6E0B0u) + val Purple = Util.colorFromAbgr8888(0xFF800080u) + val Red = Util.colorFromAbgr8888(0xFF0000FFu) + val RosyBrown = Util.colorFromAbgr8888(0xFF8F8FBCu) + val RoyalBlue = Util.colorFromAbgr8888(0xFFE16941u) + val SaddleBrown = Util.colorFromAbgr8888(0xFF13458Bu) + val Salmon = Util.colorFromAbgr8888(0xFF7280FAu) + val SandyBrown = Util.colorFromAbgr8888(0xFF60A4F4u) + val SeaGreen = Util.colorFromAbgr8888(0xFF578B2Eu) + val SeaShell = Util.colorFromAbgr8888(0xFFEEF5FFu) + val Sienna = Util.colorFromAbgr8888(0xFF2D52A0u) + val Silver = Util.colorFromAbgr8888(0xFFC0C0C0u) + val SkyBlue = Util.colorFromAbgr8888(0xFFEBCE87u) + val SlateBlue = Util.colorFromAbgr8888(0xFFCD5A6Au) + val SlateGray = Util.colorFromAbgr8888(0xFF908070u) + val Snow = Util.colorFromAbgr8888(0xFFFAFAFFu) + val SpringGreen = Util.colorFromAbgr8888(0xFF7FFF00u) + val SteelBlue = Util.colorFromAbgr8888(0xFFB48246u) + val Tan = Util.colorFromAbgr8888(0xFF8CB4D2u) + val Teal = Util.colorFromAbgr8888(0xFF808000u) + val Thistle = Util.colorFromAbgr8888(0xFFD8BFD8u) + val Tomato = Util.colorFromAbgr8888(0xFF4763FFu) + val Turquoise = Util.colorFromAbgr8888(0xFFD0E040u) + val Violet = Util.colorFromAbgr8888(0xFFEE82EEu) + val Wheat = Util.colorFromAbgr8888(0xFFB3DEF5u) + val White = Util.colorFromAbgr8888(UInt.MAX_VALUE) + val WhiteSmoke = Util.colorFromAbgr8888(0xFFF5F5F5u) + val Yellow = Util.colorFromAbgr8888(0xFF00FFFFu) + val YellowGreen = Util.colorFromAbgr8888(0xFF32CD9Au) +} diff --git a/src/main/resources/Comic Sans MS.ttf b/src/main/resources/Comic Sans MS.ttf new file mode 100644 index 0000000..831e3d8 Binary files /dev/null and b/src/main/resources/Comic Sans MS.ttf differ diff --git a/src/main/resources/cobblestone.png b/src/main/resources/cobblestone.png new file mode 100644 index 0000000..23f066a Binary files /dev/null and b/src/main/resources/cobblestone.png differ diff --git a/src/main/resources/colin.png b/src/main/resources/colin.png new file mode 100644 index 0000000..ac31500 Binary files /dev/null and b/src/main/resources/colin.png differ diff --git a/src/main/resources/jolkmeup.jpg b/src/main/resources/jolkmeup.jpg new file mode 100644 index 0000000..d50b38c Binary files /dev/null and b/src/main/resources/jolkmeup.jpg differ diff --git a/src/main/resources/lit.frag.glsl b/src/main/resources/lit.frag.glsl new file mode 100644 index 0000000..908007c --- /dev/null +++ b/src/main/resources/lit.frag.glsl @@ -0,0 +1,241 @@ +#ifdef GL_ES +#define LOWP lowp +#define MEDP mediump +#define HIGHP highp +precision mediump float; +#else +#define LOWP +#define MEDP +#define HIGHP +#endif + +#ifdef normalFlag +varying vec3 v_normal; +#endif // normalFlag + +#ifdef colorFlag +varying vec4 v_color; +#endif // colorFlag + +#if defined(diffuseTextureFlag) || defined(specularTextureFlag) || defined(emissiveTextureFlag) +#define textureFlag +#endif +#ifdef diffuseTextureFlag +varying MEDP vec2 v_diffuseUV; +uniform sampler2D u_diffuseTexture; +#endif // diffuseTextureFlag +#ifdef specularTextureFlag +varying MEDP vec2 v_specularUV; +uniform sampler2D u_specularTexture; +#endif // specularTextureFlag +/* +#ifdef emissiveTextureFlag +varying MEDP vec2 v_emissiveUV; +uniform sampler2D u_emissiveTexture; +#endif // emissiveTextureFlag +*/ + +#ifdef diffuseColorFlag +uniform vec4 u_diffuseColor; +#endif // diffuseColorFlag + +#ifdef specularColorFlag +uniform vec4 u_specularColor; +#endif + +#ifdef lightingFlag +varying vec3 v_lightDiffuse; + +#ifdef shininessFlag +uniform float u_shininess; +#else +const float u_shininess = 20.0; +#endif // shininessFlag + +#if numDirectionalLights > 0 +struct DirectionalLight +{ + vec3 color; + vec3 direction; +}; +uniform DirectionalLight u_dirLights[numDirectionalLights]; +#endif // numDirectionalLights + +#if numPointLights > 0 +struct PointLight +{ + vec3 color; + vec3 position; +}; +uniform PointLight u_pointLights[numPointLights]; +#endif // numPointLights + +#if defined(ambientLightFlag) || defined(ambientCubemapFlag) || defined(sphericalHarmonicsFlag) +#define ambientFlag +varying vec3 v_ambient; +#endif // ambientFlag + +#if defined(specularTextureFlag) || defined(specularColorFlag) +#define specularFlag +#endif + +#endif // lightingFlag + +#if defined(specularFlag) || defined(fogFlag) +varying vec4 v_worldPosition; +uniform vec4 u_cameraPosition; +#endif // lightingFlag || fogFlag + +#ifdef fogFlag +uniform vec4 u_fogColor; +varying float v_fog; +#endif // fogFlag + +uniform mat4 u_projViewTrans; +uniform mat4 u_worldTrans; + +vec3 linearEncode(vec3 v) { return vec3(pow(v.r, 2.2), pow(v.g, 2.2), pow(v.b, 2.2)); } +vec3 linearDecode(vec3 v) { return vec3(pow(v.r, 1.0 / 2.2), pow(v.g, 1.0 / 2.2), pow(v.b, 1.0 / 2.2)); } + +void main() +{ +#if defined(diffuseTextureFlag) && defined(diffuseColorFlag) && defined(colorFlag) + vec4 diffuse = texture2D(u_diffuseTexture, v_diffuseUV) * u_diffuseColor * v_color; +#elif defined(diffuseTextureFlag) && defined(diffuseColorFlag) + vec4 diffuse = texture2D(u_diffuseTexture, v_diffuseUV) * u_diffuseColor; +#elif defined(diffuseTextureFlag) && defined(colorFlag) + vec4 diffuse = texture2D(u_diffuseTexture, v_diffuseUV) * v_color; +#elif defined(diffuseTextureFlag) + vec4 diffuse = texture2D(u_diffuseTexture, v_diffuseUV); +#elif defined(diffuseColorFlag) && defined(colorFlag) + vec4 diffuse = u_diffuseColor * v_color; +#elif defined(diffuseColorFlag) + vec4 diffuse = u_diffuseColor; +#elif defined(colorFlag) + vec4 diffuse = v_color; +#else + vec4 diffuse = vec4(1.0); +#endif + diffuse.rgb = linearEncode(diffuse.rgb); + +#ifdef lightingFlag + +#ifdef normalFlag + vec3 normal = normalize(v_normal); +#endif // normalFlag + +#ifdef ambientFlag + vec3 accum = v_ambient; +#else // !ambientFlag + vec3 accum = vec3(0.0); +#endif // ambientFlag + +#ifdef specularFlag + vec3 eyeVec = normalize(u_cameraPosition.xyz - v_worldPosition.xyz); + vec3 specAccum = vec3(0.0); +#endif // specularFlag + +#if defined(normalFlag) && (numDirectionalLights > 0) + for (int i = 0; i < numDirectionalLights; ++i) + { + vec3 lightVec = -u_dirLights[i].direction; + float lambert = dot(normal, lightVec); + float phongTerm = max(lambert, 0.0); + vec3 value = u_dirLights[i].color * phongTerm; + value = linearEncode(value); + value *= phongTerm; + accum += value; +#ifdef specularFlag + vec3 halfDir = normalize(lightVec + eyeVec); + float specAngle = max(dot(halfDir, normal), 0.0); + float specTerm = pow(specAngle, u_shininess); + specAccum += value * specTerm; +#endif // specularFlag + } +#endif // normalFlag && numDirectionalLights + + vec3 fragment; +#ifdef specularFlag +#ifdef specularTextureFlag + vec3 specularColorTex = texture2D(u_specularTexture, v_specularUV).rgb; + specularColorTex = linearEncode(specularColorTex); + specAccum *= specularColorTex; +#endif // specularTextureFlag +#ifdef specularColorFlag + vec3 specularColor = u_specularColor.rgb; + specularColor = linearEncode(specularColor); + specAccum *= specularColor; +#endif // specularColorFlag + fragment = diffuse.rgb * accum + specAccum; +#else // !specularFlag + fragment = diffuse.rgb * accum; +#endif // specularFlag +#else // !lightingFlag + fragment = diffuse.rgb; +#endif // lightingFlag + +#ifdef fogFlag +#define fogDistance +//#define fogDepth + +//#define fogOriginal +//#define fogLinear +#define fogSmooth +//#define fogInvSquare +//#define fogExp +//#define fogExp2 + +#if defined(fogLinear) || defined(fogSmooth) || defined(fogInvSquare) + float near = 1.5; + float far = 20.5; +#elif defined(fogExp) || defined(fogExp2) + float density = 0.12; +#endif + +#ifdef fogOriginal + vec3 fvec = u_cameraPosition.xyz - v_worldPosition.xyz; + float flen = dot(fvec, fvec); + float fog = min(flen * u_cameraPosition.w, 1.0); +#elif defined(fogDistance) + float flen = length(v_worldPosition.xyz - u_cameraPosition.xyz); +#elif defined(fogDepth) + float flen = gl_FragCoord.z / gl_FragCoord.w; +#endif // fogOriginal || fogDistance || fogDepth + +#ifdef fogLinear + // fog = saturate(linearstep(near, far, x)) + float fog = clamp((flen - near) / (far - near), 0.0, 1.0); +#elif defined(fogSmooth) + // fog = smoothstep(saturate(linearstep(near, far, x))) + float fog = clamp((flen - near) / (far - near), 0.0, 1.0); + fog = fog * fog * (3.0 - 2.0 * fog); + //fog = fog * fog * fog * (fog * (6.0 * fog - 15.0) + 10.0); +#elif defined(fogInvSquare) + // fog = isqstep(saturate(linearstep(near, far, x))) + float fog = clamp((flen - near) / (far - near), 0.0, 1.0); + fog = 1.0 - fog; + fog = 1.0 - fog * fog; +#elif defined(fogExp) + float fog = max(1.0 - exp(-density * flen), 0.0); +#elif defined(fogExp2) + float dz = density * flen; + float fog = max(1.0 - exp(-dz * dz), 0.0); +#endif // fogLinear || fogSmooth || fogInvSquare || fogExp || fogExp2 + + vec3 fogColor = u_fogColor.rgb; + fogColor = linearEncode(fogColor); + fragment = mix(fragment, fogColor, fog); +#endif // fogFlag + gl_FragColor = vec4(linearDecode(fragment), diffuse.a); + /* + if (gl_FragCoord.x > 1280.0) + { + if (fog <= 0.0) + gl_FragColor = vec4(1.0, 0.0, 1.0, diffuse.a); + else if (fog >= 1.0) + gl_FragColor = vec4(1.0, 0.0, 0.0, diffuse.a); + else + gl_FragColor = vec4(fog, fog, 0.0, diffuse.a); + } + */ +} diff --git a/src/main/resources/lit.vert.glsl b/src/main/resources/lit.vert.glsl new file mode 100644 index 0000000..3ab2c56 --- /dev/null +++ b/src/main/resources/lit.vert.glsl @@ -0,0 +1,119 @@ +attribute vec3 a_position; +uniform mat4 u_projViewTrans; + +#ifdef normalFlag +attribute vec3 a_normal; +uniform mat3 u_normalMatrix; +varying vec3 v_normal; +#endif // normalFlag + +#ifdef colorFlag +varying vec4 v_color; +attribute vec4 a_color; +#endif // colorFlag + +#if defined(diffuseTextureFlag) || defined(specularTextureFlag) || defined(emissiveTextureFlag) +#define textureFlag +#endif + +#if defined(ambientLightFlag) || defined(ambientCubemapFlag) || defined(sphericalHarmonicsFlag) +#define ambientFlag +#endif // ambientFlag + +#ifdef textureFlag +attribute vec2 a_texCoord0; +#endif // textureFlag + +#ifdef diffuseTextureFlag +uniform vec4 u_diffuseUVTransform; +varying vec2 v_diffuseUV; +#endif + +#ifdef emissiveTextureFlag +uniform vec4 u_emissiveUVTransform; +varying vec2 v_emissiveUV; +#endif + +#ifdef specularTextureFlag +uniform vec4 u_specularUVTransform; +varying vec2 v_specularUV; +#endif + +uniform mat4 u_worldTrans; + +#ifdef lightingFlag + +#ifdef ambientLightFlag +uniform vec3 u_ambientLight; +#endif // ambientLightFlag + +#ifdef ambientLightFlag +uniform vec3 u_ambientLight; +#endif // ambientLightFlag + +#ifdef ambientCubemapFlag +uniform vec3 u_ambientCubemap[6]; +#endif // ambientCubemapFlag + +/* +#ifdef sphericalHarmonicsFlag +uniform vec3 u_sphericalHarmonics[9]; +#endif // sphericalHarmonicsFlag +*/ + +#ifdef ambientFlag +varying vec3 v_ambient; +#endif // ambientFlag + +#endif // lightingFlag + +#if defined(lightingFlag) || defined(fogFlag) +varying vec4 v_worldPosition; +#endif // lightingFlag || fogFlag + +void main() +{ +#ifdef normalFlag + //vec3 normal = u_normalMatrix * a_normal; + vec3 normal = normalize(u_normalMatrix * a_normal); + v_normal = normal; +#endif // normalFlag + +#ifdef colorFlag + v_color = a_color; +#endif // colorFlag + +#ifdef diffuseTextureFlag + v_diffuseUV = u_diffuseUVTransform.xy + a_texCoord0 * u_diffuseUVTransform.zw; +#endif // diffuseTextureFlag + +#ifdef emissiveTextureFlag + v_emissiveUV = u_emissiveUVTransform.xy + a_texCoord0 * u_emissiveUVTransform.zw; +#endif // emissiveTextureFlag + +#ifdef specularTextureFlag + v_specularUV = u_specularUVTransform.xy + a_texCoord0 * u_specularUVTransform.zw; +#endif // specularTextureFlag + +#ifdef ambientLightFlag + v_ambient = u_ambientLight; +#else // !ambientLightFlag + v_ambient = vec3(0.0); +#endif // ambientLightFlag + +#ifdef ambientCubemapFlag + vec3 norm2 = normal * normal; + vec3 isPositive = step(0.0, normal); + v_ambient += + norm2.x * mix(u_ambientCubemap[0], u_ambientCubemap[1], isPositive.x) + + norm2.y * mix(u_ambientCubemap[2], u_ambientCubemap[3], isPositive.y) + + norm2.z * mix(u_ambientCubemap[4], u_ambientCubemap[5], isPositive.z); +#endif // ambientCubemapFlag + + vec4 worldPos = u_worldTrans * vec4(a_position, 1.0); +#if defined(lightingFlag) || defined(fogFlag) + v_worldPosition = worldPos; + //v_cameraPosition = u_cameraPosition; +#endif // lightingFlag || fogFlag + gl_Position = u_projViewTrans * worldPos; +} diff --git a/src/main/resources/nut.wav b/src/main/resources/nut.wav new file mode 100644 index 0000000..b7b2c18 Binary files /dev/null and b/src/main/resources/nut.wav differ diff --git a/src/main/resources/suzanne.g3db b/src/main/resources/suzanne.g3db new file mode 100644 index 0000000..fa43a3b Binary files /dev/null and b/src/main/resources/suzanne.g3db differ diff --git a/src/main/resources/wall.png b/src/main/resources/wall.png new file mode 100644 index 0000000..432d68a Binary files /dev/null and b/src/main/resources/wall.png differ