mapping but it's normal
This commit is contained in:
@ -11,10 +11,13 @@ 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.environment.DirectionalLight
|
||||
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.math.*
|
||||
import com.badlogic.gdx.utils.Array
|
||||
import com.badlogic.gdx.utils.ScreenUtils
|
||||
import gay.pizza.CavesOfJolk.Resources.Companion.assetManager
|
||||
|
||||
@ -54,23 +57,75 @@ class Game: ApplicationAdapter()
|
||||
return modelBuilder.createBox(size, size, size, material, attribs.toLong())
|
||||
}
|
||||
|
||||
private fun makeFloor(texture: Texture): Model
|
||||
private fun makeFloor(): Model
|
||||
{
|
||||
val modelBuilder = ModelBuilder()
|
||||
val material = Material(
|
||||
ColorAttribute.createDiffuse(XnaColor.BlanchedAlmond.lighten(0.01)),
|
||||
ColorAttribute.createSpecular(XnaColor.BlanchedAlmond.mix(XnaColor.Black, 0.4f)),
|
||||
FloatAttribute.createShininess(65.0f),
|
||||
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())
|
||||
val model = ModelData()
|
||||
|
||||
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 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 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))
|
||||
}
|
||||
|
||||
override fun create()
|
||||
@ -87,7 +142,7 @@ class Game: ApplicationAdapter()
|
||||
i.set(FloatAttribute.createShininess(30.0f))
|
||||
|
||||
cube = makeCube(texJolk)
|
||||
floor = makeFloor(assetManager.get("cobblestone.png"))
|
||||
floor = makeFloor()
|
||||
|
||||
spriteBatch = SpriteBatch()
|
||||
|
||||
@ -107,7 +162,9 @@ class Game: ApplicationAdapter()
|
||||
CustomIntAttribute.createFogType(CustomIntAttribute.FogTypes.Exp2),
|
||||
CustomFloatAttribute.createFogDensity(0.1f))
|
||||
*/
|
||||
env.add(DirectionalLight().set(XnaColor.White, Vector3(1.0f, -1.0f, -1.0f).nor()))
|
||||
env.add(DirectionalLight().set(
|
||||
XnaColor.BlanchedAlmond.lighten(0.01),
|
||||
Vector3(1.0f, -1.0f, -1.0f).nor()))
|
||||
|
||||
val shaderConfig = DefaultShader.Config()
|
||||
shaderConfig.numDirectionalLights = 1
|
||||
|
@ -34,7 +34,6 @@ class Resources private constructor()
|
||||
{
|
||||
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)
|
||||
|
BIN
src/main/resources/cobblestone_normal.png
Normal file
BIN
src/main/resources/cobblestone_normal.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 265 KiB |
@ -13,17 +13,25 @@ precision mediump float;
|
||||
varying vec3 v_normal;
|
||||
#endif // normalFlag
|
||||
|
||||
#if defined(tangentFlag) && defined(binormalFlag)
|
||||
varying mat3 v_tbn;
|
||||
#endif // tangentFlag && bitangentFlag
|
||||
|
||||
#ifdef colorFlag
|
||||
varying vec4 v_color;
|
||||
#endif // colorFlag
|
||||
|
||||
#if defined(diffuseTextureFlag) || defined(specularTextureFlag) || defined(emissiveTextureFlag)
|
||||
#if defined(diffuseTextureFlag) || defined(normalTextureFlag) || defined(specularTextureFlag) || defined(emissiveTextureFlag)
|
||||
#define textureFlag
|
||||
#endif
|
||||
#ifdef diffuseTextureFlag
|
||||
varying MEDP vec2 v_diffuseUV;
|
||||
uniform sampler2D u_diffuseTexture;
|
||||
#endif // diffuseTextureFlag
|
||||
#ifdef normalTextureFlag
|
||||
varying MEDP vec2 v_normalUV;
|
||||
uniform sampler2D u_normalTexture;
|
||||
#endif // normalTextureFlag
|
||||
#ifdef specularTextureFlag
|
||||
varying MEDP vec2 v_specularUV;
|
||||
uniform sampler2D u_specularTexture;
|
||||
@ -127,7 +135,10 @@ void main()
|
||||
|
||||
#ifdef lightingFlag
|
||||
|
||||
#ifdef normalFlag
|
||||
#if defined(normalFlag) && defined(tangentFlag) && defined(binormalFlag) && defined(normalTextureFlag)
|
||||
vec3 normal = vec3(2.0 * texture2D(u_normalTexture, v_normalUV).rgb - 1.0);
|
||||
normal = normalize(v_tbn * normal);
|
||||
#elif defined(normalFlag)
|
||||
vec3 normal = normalize(v_normal);
|
||||
#endif // normalFlag
|
||||
|
||||
|
@ -7,6 +7,12 @@ uniform mat3 u_normalMatrix;
|
||||
varying vec3 v_normal;
|
||||
#endif // normalFlag
|
||||
|
||||
#if defined(tangentFlag) && defined(binormalFlag)
|
||||
attribute vec3 a_tangent;
|
||||
attribute vec3 a_binormal;
|
||||
varying mat3 v_tbn;
|
||||
#endif // tangentFlag && bitangentFlag
|
||||
|
||||
#ifdef colorFlag
|
||||
varying vec4 v_color;
|
||||
attribute vec4 a_color;
|
||||
@ -27,17 +33,22 @@ attribute vec2 a_texCoord0;
|
||||
#ifdef diffuseTextureFlag
|
||||
uniform vec4 u_diffuseUVTransform;
|
||||
varying vec2 v_diffuseUV;
|
||||
#endif
|
||||
#endif // diffuseTextureFlag
|
||||
|
||||
#ifdef normalTextureFlag
|
||||
uniform vec4 u_normalUVTransform;
|
||||
varying vec2 v_normalUV;
|
||||
#endif // normalTextureFlag
|
||||
|
||||
#ifdef emissiveTextureFlag
|
||||
uniform vec4 u_emissiveUVTransform;
|
||||
varying vec2 v_emissiveUV;
|
||||
#endif
|
||||
#endif // emissiveTextureFlag
|
||||
|
||||
#ifdef specularTextureFlag
|
||||
uniform vec4 u_specularUVTransform;
|
||||
varying vec2 v_specularUV;
|
||||
#endif
|
||||
#endif // specularTextureFlag
|
||||
|
||||
uniform mat4 u_worldTrans;
|
||||
|
||||
@ -74,9 +85,15 @@ varying vec4 v_worldPosition;
|
||||
void main()
|
||||
{
|
||||
#ifdef normalFlag
|
||||
//vec3 normal = u_normalMatrix * a_normal;
|
||||
//vec3 normal = (transpose(inverse(u_normalMatrix)) * a_normal);
|
||||
vec3 normal = normalize(u_normalMatrix * a_normal);
|
||||
v_normal = normal;
|
||||
|
||||
#if defined(tangentFlag) && defined(binormalFlag)
|
||||
vec3 tangent = normalize(u_normalMatrix * a_tangent);
|
||||
vec3 bitangent = normalize(u_normalMatrix * a_binormal);
|
||||
v_tbn = mat3(tangent, bitangent, normal);
|
||||
#endif // tangentFlag && bitangentFlag
|
||||
#endif // normalFlag
|
||||
|
||||
#ifdef colorFlag
|
||||
@ -87,6 +104,10 @@ void main()
|
||||
v_diffuseUV = u_diffuseUVTransform.xy + a_texCoord0 * u_diffuseUVTransform.zw;
|
||||
#endif // diffuseTextureFlag
|
||||
|
||||
#ifdef normalTextureFlag
|
||||
v_normalUV = u_normalUVTransform.xy + a_texCoord0 * u_normalUVTransform.zw;
|
||||
#endif // normalTextureFlag
|
||||
|
||||
#ifdef emissiveTextureFlag
|
||||
v_emissiveUV = u_emissiveUVTransform.xy + a_texCoord0 * u_emissiveUVTransform.zw;
|
||||
#endif // emissiveTextureFlag
|
||||
|
Reference in New Issue
Block a user