From 7e25e7198d8e0b7f2569908e9b39c0e75bf002e1 Mon Sep 17 00:00:00 2001 From: Robear Selwans Date: Sun, 25 Jul 2021 10:48:35 +0200 Subject: [PATCH] Multiple Demo Changes Signed-off-by: Robear Selwans --- assets/meshes/Cube.mesh | Bin 0 -> 2201 bytes assets/shaders/custom.frag | 112 ++++++ assets/shaders/custom.vert | 89 +++++ assets/shaders/mrt.frag | 14 +- game.proj | 18 +- prefabs/DamagedHelmet.pf | 26 ++ scenes/DamagedHelmet.evsc | 141 +++++++- scenes/DemoScene0.evsc | 556 +++++++++++++++++++++++++++++ scripts/MainScene/Camera.lua | 9 +- scripts/MainScene/CameraHelper.lua | 13 +- scripts/demo/gravitygun.lua | 50 +++ scripts/demo/spawnpoint.lua | 11 + scripts/demo/trigger.lua | 3 + 13 files changed, 1009 insertions(+), 33 deletions(-) create mode 100644 assets/meshes/Cube.mesh create mode 100755 assets/shaders/custom.frag create mode 100755 assets/shaders/custom.vert create mode 100644 prefabs/DamagedHelmet.pf create mode 100644 scenes/DemoScene0.evsc create mode 100644 scripts/demo/gravitygun.lua create mode 100644 scripts/demo/spawnpoint.lua create mode 100644 scripts/demo/trigger.lua diff --git a/assets/meshes/Cube.mesh b/assets/meshes/Cube.mesh new file mode 100644 index 0000000000000000000000000000000000000000..64a24d7350b0c7805d0f8f600fd467a43e077555 GIT binary patch literal 2201 zcmbW3O-~y^42Gw)K)(z0gX?O~JwQN}-~f@3IHI0-&1_ zi8IM2N=9<*v1cB?-rYm~g%Gx$hVZu@US0No_rBi^2K`a*X85OHAMYO?e$@Pr>$|Jl z`uO0JCDIAhfAvSVQx}gqd%2=lJL9v1>(S3|pw*u*&c5`{4?6WdWW>`+LrQY=Tovml zDdul%G>(&=9Inj6IiE|_#0z>>&M)FAhka-9zLG`LwNRh&aHoy8)Vwozlw$14Y0Da! zi)okjYEkBNOigFrgL@YfwU~BOJoFMKJ^Sjim^?o(%TkN!;7p#fjFImks8}mB&gC_! zU)G4dU*vURetBN`9EC$B4fjg@oOdN2SuH%#;{?h+YC^r~$hum1mF698;(fHv>+VS} z>tDRztkvq;$nv7E89zUkOI|=PTXxTMm3h`PQ}1~m-^WTka$9)*`?E81^(jlVD%0ku zSex@b8`t^>qeH%W3z}S zY`X-{efhnxY`jJDPVqRWnVZY=x-KuhxQ~qB%370h!gMv`Rmd&F3*iyEtVyrrA0vJO yTZe6EOuq@ke}?c3_FQB77qFMGSFqO_)4zdj!M0&L8q>dpy@S1nebAVG7xo|V=J*!? literal 0 HcmV?d00001 diff --git a/assets/shaders/custom.frag b/assets/shaders/custom.frag new file mode 100755 index 0000000..65d3f53 --- /dev/null +++ b/assets/shaders/custom.frag @@ -0,0 +1,112 @@ +#version 450 +#extension GL_EXT_nonuniform_qualifier : require + +#include "shaders://_builtins/constants.glsl" +#include "shaders://_builtins/srgb_ops.glsl" +#include "shaders://_builtins/PBR.glsl" +#include "shaders://_builtins/types.glsl" + +struct Light { + vec3 color; + uint intensity; +}; + +struct Scene { + uint lightsCount; +}; + +vec3 directional_light = vec3(1.0); + +layout( push_constant ) uniform constants +{ + mat4 render_matrix; + uint indexBufferIndex; + uint vertexBufferIndex; + uint materialBufferIndex; +} PushConstants; + +layout(set = 0, binding = 0) uniform SceneData { + layout(align = 16) Scene mesh; +} SceneBuffers[]; + +layout(set = 0, binding = 1) uniform LightBuffer { + layout(align = 16) Light lights[]; +} LightsBuffers; + +layout (set = 0, binding = 2) uniform samplerCube skybox; + +layout(set = 2, binding = 3) buffer MaterialBuffer { + layout(align = 16) Material materials[]; +} MaterialBuffers; + +layout(set = 2, binding = 4) uniform sampler2D texSampler[]; + +layout(location = 0) in vec2 uv; +layout(location = 1) smooth in mat3 TBN; +layout(location = 4) in vec4 outpos; +layout(location = 5) in vec3 cameraPos; + +layout (location = 0) out vec4 gPosition; +layout (location = 1) out vec4 gNormal; +layout (location = 2) out vec4 gAlbedo; +layout (location = 3) out vec4 gSpecular; + +void main() { + Material material = MaterialBuffers.materials[ PushConstants.materialBufferIndex ]; + + vec3 outNormal; + if(material.normalTexture == 0) { + outNormal = TBN[2].xyz; + } else { + vec3 sampled_normal = LinearToSRGB(texture(texSampler[material.normalTexture], uv)).rgb; + sampled_normal = 2.0 * sampled_normal - vec3(1.0); + outNormal = normalize(TBN * sampled_normal); + } + + //float intensity = dot(outNormal, normalize(directional_light)) + 0.2; + + vec3 outColor; + if(material.albedoTexture == 0) { + outColor = material.baseColor.xyz; + } else { + outColor = texture(texSampler[material.albedoTexture], uv).xyz; + } + + // outColor = vec3(1.0, 0.0, 0.0); + + vec3 outSpecular; + if(material.metallicRoughnessTexture == 0) { + outSpecular.b = material.metallicFactor; + outSpecular.g = material.roughnessFactor; + outSpecular.r = 1.0; + } else { + outSpecular = LinearToSRGB(texture(texSampler[material.metallicRoughnessTexture], uv)).xyz; + } + + float metallicFactor = outSpecular.z; + float roughnessFactor = outSpecular.y; + float ao = outSpecular.x; + + gNormal.w = ao; + gAlbedo.w = roughnessFactor; + gPosition.w = metallicFactor; + + float reflectance = 1.0 - roughnessFactor; + gSpecular.w = reflectance; + + vec3 I = normalize(outpos.xyz - cameraPos); + vec3 R = reflect(I, normalize(outNormal)); + //R = R * -1; + outSpecular = texture(skybox, R).rgb; + + if(material.emissiveTexture != 0) { + gSpecular.w = 1.0; + outSpecular += texture(texSampler[material.emissiveTexture], uv).rgb * material.emissiveFactor.xyz; + } + + + gPosition.xyz = outpos.xyz; + gNormal.xyz = outNormal; + gAlbedo.xyz = outColor; + gSpecular.xyz = outSpecular; +} diff --git a/assets/shaders/custom.vert b/assets/shaders/custom.vert new file mode 100755 index 0000000..36a06f6 --- /dev/null +++ b/assets/shaders/custom.vert @@ -0,0 +1,89 @@ +#version 450 +#extension GL_EXT_nonuniform_qualifier : require + +struct Material { + vec4 baseColor; + uint albedoTexture; + + uint normalTexture; + + float metallicFactor; + float roughnessFactor; + uint metallicRoughnessTexture; +}; + +struct Vertex { + vec4 position; + vec4 normal; + vec2 uv[2]; + vec4 tangent; + vec4 bitangent; // No longer needed. // TODO remove +}; + +struct Light { + vec3 color; + uint intensity; +}; + +struct Scene { + uint lightsCount; +}; + +struct Mesh { + uint asd; +}; + +layout( push_constant ) uniform constants +{ + mat4 render_matrix; + uint indexBufferIndex; + uint vertexBufferIndex; + uint materialBufferIndex; +} PushConstants; + +layout(set = 1, binding = 0) uniform CameraParam { + mat4 projection; + mat4 view; +} Camera; + +layout(set = 2, binding = 0) buffer MeshBuffer { + layout(align = 16) Mesh mesh; +} MeshBuffers[]; + +layout(set = 2, binding = 1) buffer VertexBuffer { + layout(align = 16) Vertex vertices[]; +} VertexBuffers[]; + +layout(set = 2, binding = 2) buffer IndexBuffer { + uint indices[]; +} IndexBuffers[]; + +layout(set = 2, binding = 4) uniform sampler2D texSampler[]; + +layout(location = 0) out vec2 uv; +layout(location = 1) smooth out mat3 TBN; + +layout(location = 4) out vec4 outpos; +layout(location = 5) out vec3 cameraPos; + +void main() +{ + uint index = IndexBuffers[ PushConstants.indexBufferIndex ].indices[gl_VertexIndex]; + Vertex vertex = VertexBuffers[ PushConstants.vertexBufferIndex ].vertices[ index ]; + + uv = vertex.uv[0]; + + mat3 model = transpose(inverse(mat3(PushConstants.render_matrix))); + + vec3 T = normalize(model * vec3(vertex.tangent)); + vec3 N = normalize(model * vec3(vertex.normal)); + vec3 B = normalize(model * vec3(vertex.bitangent)); + /* T = normalize(T - dot(T, N) * N); // Re-orthoganize T with respect to N */ + /* vec3 B = normalize(cross(N, T)); */ + TBN = mat3(T, B, N); + + gl_Position = Camera.projection * Camera.view * PushConstants.render_matrix * vec4(vertex.position.xyz, 1.0); + outpos = PushConstants.render_matrix * vec4(vertex.position.xyz, 1.0); + + cameraPos = inverse(Camera.view)[3].xyz; +} diff --git a/assets/shaders/mrt.frag b/assets/shaders/mrt.frag index c41614d..618c4a0 100755 --- a/assets/shaders/mrt.frag +++ b/assets/shaders/mrt.frag @@ -65,11 +65,14 @@ void main() { //float intensity = dot(outNormal, normalize(directional_light)) + 0.2; - vec3 outColor; + vec4 outColor; if(material.albedoTexture == 0) { - outColor = material.baseColor.xyz; + outColor = material.baseColor; } else { - outColor = texture(texSampler[material.albedoTexture], uv).xyz; + outColor = texture(texSampler[material.albedoTexture], uv); + } + if(outColor.a < 0.5) { + discard; } vec3 outSpecular; @@ -89,7 +92,8 @@ void main() { gAlbedo.w = roughnessFactor; gPosition.w = metallicFactor; - float reflectance = 1.0 - roughnessFactor; + // float reflectance = roughnessFactor * metallicFactor; + float reflectance = 1 - roughnessFactor; gSpecular.w = reflectance; vec3 I = normalize(outpos.xyz - cameraPos); @@ -105,6 +109,6 @@ void main() { gPosition.xyz = outpos.xyz; gNormal.xyz = outNormal; - gAlbedo.xyz = outColor; + gAlbedo.xyz = outColor.xyz; gSpecular.xyz = outSpecular; } diff --git a/game.proj b/game.proj index 33b1e84..652879f 100755 --- a/game.proj +++ b/game.proj @@ -28,26 +28,18 @@ "id": "MainScene", "path": "scenes://MainScene.evsc" }, - { - "id": "SponzaScene", - "path": "scenes://Sponza.evsc" - }, { "id": "DamagedHelmetScene", "path": "scenes://DamagedHelmet.evsc" }, { - "id": "BoomBox", - "path": "scenes://BoomBox.evsc" + "id": "Sponza", + "path": "scenes://Sponza.evsc" }, { - "id": "CesiumMilkTruck", - "path": "scenes://CesiumMilkTruck.evsc" - }, - { - "id": "Car", - "path": "scenes://Car.evsc" + "id": "Demo0", + "path": "scenes://DemoScene0.evsc" } ], - "activeScene": "DamagedHelmetScene" + "activeScene": "Demo0" } diff --git a/prefabs/DamagedHelmet.pf b/prefabs/DamagedHelmet.pf new file mode 100644 index 0000000..fbd1cd2 --- /dev/null +++ b/prefabs/DamagedHelmet.pf @@ -0,0 +1,26 @@ +{ + "components": [ + { + "position": [ 1, 0, 0 ], + "rotation": [ -180, 0, 0 ], + "scale": [ 1, 1, 1 ], + "type": "TransformComponent" + }, + { + "material": "CustomMaterial", + "mesh": "assets://meshes/DamagedHelmet_mesh_helmet_LP_13930damagedHelmet.mesh", + "type": "RenderComponent" + }, + { + "type": "RigidbodyComponent", + "mass": 1, + "restitution": 1, + "rigidbodyType": "Dynamic", + "collisionShape": { + "type": "Sphere", + "radius": 1.0 + } + } + ], + "id": "DamagedHelmet" +} diff --git a/scenes/DamagedHelmet.evsc b/scenes/DamagedHelmet.evsc index 923e398..3ba4403 100644 --- a/scenes/DamagedHelmet.evsc +++ b/scenes/DamagedHelmet.evsc @@ -13,6 +13,26 @@ "pipeline": "DefferedPipeline", "roughnessFactor": 1 }, + { + "baseColor": [ 1, 0, 0, 1 ], + "emissiveFactor": [ 1, 1, 1 ], + "id": "DotMaterial", + "metallicFactor": 0, + "pipeline": "DefferedPipeline", + "roughnessFactor": 1 + }, + { + "albedoTexture": "assets://textures/Default_albedo.tx", + "baseColor": [ 1, 1, 1, 1 ], + "emissiveFactor": [ 1, 1, 1 ], + "emissiveTexture": "assets://textures/Default_emissive.tx", + "id": "CustomMaterial", + "metallicFactor": 1, + "metallicRoughnessTexture": "assets://textures/Default_AO-Default_metalRoughness.tx", + "normalTexture": "assets://textures/Default_normal.tx", + "pipeline": "CustomPipeline", + "roughnessFactor": 1 + }, { "baseColor": [ 1, 1, 1, 1 ], "emissiveFactor": [ 1, 1, 1 ], @@ -34,16 +54,11 @@ { "components": [ { - "position": [ 0, 0, 0 ], + "position": [ -1, 0, 0 ], "rotation": [ -180, 0, 0 ], "scale": [ 1, 1, 1 ], "type": "TransformComponent" }, - { - "type": "ScriptComponent", - "script_name": "RotationHelper", - "script_path": "scripts://MainScene/objectRotation.lua" - }, { "material": "Material_MR", "mesh": "assets://meshes/DamagedHelmet_mesh_helmet_LP_13930damagedHelmet.mesh", @@ -52,6 +67,32 @@ ], "id": "node_damagedHelmet_-6514" }, + { + "components": [ + { + "position": [ 1, 0, 0 ], + "rotation": [ -180, 0, 0 ], + "scale": [ 1, 1, 1 ], + "type": "TransformComponent" + }, + { + "material": "CustomMaterial", + "mesh": "assets://meshes/DamagedHelmet_mesh_helmet_LP_13930damagedHelmet.mesh", + "type": "RenderComponent" + }, + { + "type": "RigidbodyComponent", + "mass": 1, + "restitution": 1, + "rigidbodyType": "Kinematic", + "collisionShape": { + "type": "Sphere", + "radius": 1.0 + } + } + ], + "id": "CustomDamagedHelmet" + }, { "components": [ { @@ -170,10 +211,98 @@ "script_name": "MainCameraRotationHelper", "script_path": "scripts://MainScene/CameraHelper.lua" } + ], + "children": [ + { + "id": "Center", + "components": [ + { + "type": "TransformComponent", + "position": [0,0,-0.2], + "rotation": [0,0,0], + "scale": [0.005,0.005,0.005] + }, + { + "type": "RenderComponent", + "material": "DotMaterial", + "mesh": "assets://meshes/lightSphere_Sphere.mesh" + } + ] + }, + { + "id": "GravityGun", + "components": [ + { + "type": "TransformComponent", + "position": [ 0, 0, 0 ], + "rotation": [ 0, 0, 0 ], + "scale": [ 1, 1, 1 ] + }, + { + "type": "ScriptComponent", + "script_name": "GravityGunScript", + "script_path": "scripts://demo/gravitygun.lua" + } + ] + } ] } ] } ], + "pipelines": [ + { + "id": "DefaultPipeline", + "shaderStages": [ + { + "type": "Vertex", + "shaderPath": "shaders://default.vert" + }, + { + "type": "Fragment", + "shaderPath": "shaders://default.frag" + } + ] + }, + { + "id": "LightSpherePipeline", + "shaderStages": [ + { + "type": "Vertex", + "shaderPath": "shaders://lightObject.vert" + }, + { + "type": "Fragment", + "shaderPath": "shaders://lightObject.frag" + } + ] + }, + { + "id": "DefferedPipeline", + "shaderStages": [ + { + "type": "Vertex", + "shaderPath": "shaders://mrt.vert" + }, + { + "type": "Fragment", + "shaderPath": "shaders://mrt.frag" + } + ] + }, + { + "id": "CustomPipeline", + "shaderStages": [ + { + "type": "Vertex", + "shaderPath": "shaders://custom.vert" + }, + { + "type": "Fragment", + "shaderPath": "shaders://custom.frag" + } + ] + } + ], "activeCamera": "Camera.RotationHelper" } diff --git a/scenes/DemoScene0.evsc b/scenes/DemoScene0.evsc new file mode 100644 index 0000000..fae93d5 --- /dev/null +++ b/scenes/DemoScene0.evsc @@ -0,0 +1,556 @@ +{ + "id": "Scene", + "materials": [ + { + "albedoTexture": "assets://textures/Default_albedo.tx", + "baseColor": [ 1, 1, 1, 1 ], + "emissiveFactor": [ 1, 1, 1 ], + "emissiveTexture": "assets://textures/Default_emissive.tx", + "id": "Material_MR", + "metallicFactor": 1, + "metallicRoughnessTexture": "assets://textures/Default_AO-Default_metalRoughness.tx", + "normalTexture": "assets://textures/Default_normal.tx", + "pipeline": "DefferedPipeline", + "roughnessFactor": 1 + }, + { + "baseColor": [ 1, 0, 0, 1 ], + "emissiveFactor": [ 1, 1, 1 ], + "id": "TriggerMaterial", + "metallicFactor": 1, + "pipeline": "DefferedPipeline", + "roughnessFactor": 0 + }, + { + "baseColor": [ 1, 1, 1, 1 ], + "emissiveFactor": [ 1, 1, 1 ], + "id": "SpawnPointMaterial", + "metallicFactor": 1, + "pipeline": "DefferedPipeline", + "roughnessFactor": 0 + }, + { + "baseColor": [ 1, 0, 0, 1 ], + "emissiveFactor": [ 1, 1, 1 ], + "id": "DotMaterial", + "metallicFactor": 0, + "pipeline": "DefferedPipeline", + "roughnessFactor": 1 + }, + { + "baseColor": [ 0.86, 0.86, 0.86, 1 ], + "emissiveFactor": [ 1, 1, 1 ], + "id": "MapMaterial", + "metallicFactor": 0.0, + "pipeline": "DefferedPipeline", + "roughnessFactor": 0.99 + }, + { + "albedoTexture": "assets://textures/Default_albedo.tx", + "baseColor": [ 1, 1, 1, 1 ], + "emissiveFactor": [ 1, 1, 1 ], + "emissiveTexture": "assets://textures/Default_emissive.tx", + "id": "CustomMaterial", + "metallicFactor": 1, + "metallicRoughnessTexture": "assets://textures/Default_AO-Default_metalRoughness.tx", + "normalTexture": "assets://textures/Default_normal.tx", + "pipeline": "CustomPipeline", + "roughnessFactor": 1 + }, + { + "baseColor": [ 1, 1, 1, 1 ], + "emissiveFactor": [ 1, 1, 1 ], + "id": "Scene_Material_Dummy_1", + "metallicFactor": 1, + "pipeline": "DefferedPipeline", + "roughnessFactor": 1 + }, + { + "baseColor":[1.0,1.0,1.0,1.0], + "emissiveFactor":[1.0,1.0,1.0], + "id":"LightMaterial", + "metallicFactor":1.0, + "pipeline":"LightSpherePipeline", + "roughnessFactor":1.0 + } + ], + "nodes": [ + { + "components": [ + { + "position": [ -18.5, 14, -18.5 ], + "rotation": [ 0, 0, 0 ], + "scale": [ 1, 1, 1], + "type": "TransformComponent" + }, + { + "material":"LightMaterial", + "mesh":"assets://meshes/lightSphere_Sphere.mesh", + "type":"RenderComponent" + }, + { + "color": [1.0, 1.0, 1.0, 1.0], + "intensity": 300, + "type": "LightComponent" + } + ] + }, + { + "components": [ + { + "position": [ -18.5, 14, 18.5 ], + "rotation": [ 0, 0, 0 ], + "scale": [ 1, 1, 1], + "type": "TransformComponent" + }, + { + "material":"LightMaterial", + "mesh":"assets://meshes/lightSphere_Sphere.mesh", + "type":"RenderComponent" + }, + { + "color": [1.0, 1.0, 1.0, 1.0], + "intensity": 300, + "type": "LightComponent" + } + ] + }, + { + "components": [ + { + "position": [ 18.5, 14, 18.5 ], + "rotation": [ 0, 0, 0 ], + "scale": [ 1, 1, 1], + "type": "TransformComponent" + }, + { + "material":"LightMaterial", + "mesh":"assets://meshes/lightSphere_Sphere.mesh", + "type":"RenderComponent" + }, + { + "color": [1.0, 1.0, 1.0, 1.0], + "intensity": 300, + "type": "LightComponent" + } + ] + }, + { + "components": [ + { + "position": [ 18.5, 14, -18.5 ], + "rotation": [ 0, 0, 0 ], + "scale": [ 1, 1, 1], + "type": "TransformComponent" + }, + { + "material":"LightMaterial", + "mesh":"assets://meshes/lightSphere_Sphere.mesh", + "type":"RenderComponent" + }, + { + "color": [1.0, 1.0, 1.0, 1.0], + "intensity": 300, + "type": "LightComponent" + } + ] + }, + { + "id": "Ground", + "components": [ + { + "type": "TransformComponent", + "position": [0, -5.0, 0.0], + "rotation": [0.0, 0.0, 0.0], + "scale": [1.0, 1.0, 1.0] + }, + { + "type": "RigidbodyComponent", + "mass": 0.0, + "restitution": 0.0, + "rigidbodyType": "Static", + "collisionShape": { + "type": "Box", + "halfExtents": [20.0, 1.0, 20.0] + } + } + ], + "children": [ + { + "id": "GraphicsGround", + "components": [ + { + "type": "TransformComponent", + "position": [0.0, 0.0, 0.0], + "rotation": [0.0, 0.0, 0.0], + "scale": [20.0, 1.0, 20.0] + }, + { + "type": "RenderComponent", + "material": "MapMaterial", + "mesh": "assets://meshes/Cube.mesh" + } + ] + } + + ] + }, + { + "id": "WallRight", + "components": [ + { + "type": "TransformComponent", + "position": [20, 5.0, 0.0], + "rotation": [0.0, 0.0, 0.0], + "scale": [1.0, 1.0, 1.0] + }, + { + "type": "RigidbodyComponent", + "mass": 0.0, + "restitution": 0.0, + "rigidbodyType": "Static", + "collisionShape": { + "type": "Box", + "halfExtents": [1.0, 10.0, 20.0] + } + } + ], + "children": [ + { + "id": "GraphicsWallRight", + "components": [ + { + "type": "TransformComponent", + "position": [0.0, 0.0, 0.0], + "rotation": [0.0, 0.0, 0.0], + "scale": [1.0, 10.0, 20.0] + }, + { + "type": "RenderComponent", + "material": "MapMaterial", + "mesh": "assets://meshes/Cube.mesh" + } + ] + } + + ] + }, + { + "id": "WallLeft", + "components": [ + { + "type": "TransformComponent", + "position": [-20.0, 5.0, 0.0], + "rotation": [0.0, 0.0, 0.0], + "scale": [1.0, 1.0, 1.0] + }, + { + "type": "RigidbodyComponent", + "mass": 0.0, + "restitution": 0.0, + "rigidbodyType": "Static", + "collisionShape": { + "type": "Box", + "halfExtents": [1.0, 10.0, 20.0] + } + } + ], + "children": [ + { + "id": "GraphicsWallLeft", + "components": [ + { + "type": "TransformComponent", + "position": [0.0, 0.0, 0.0], + "rotation": [0.0, 0.0, 0.0], + "scale": [1.0, 10.0, 20.0] + }, + { + "type": "RenderComponent", + "material": "MapMaterial", + "mesh": "assets://meshes/Cube.mesh" + } + ] + } + + ] + }, + { + "id": "Column", + "components": [ + { + "type": "TransformComponent", + "position": [0.0, 0.0, 0.0], + "rotation": [0.0, 0.0, 0.0], + "scale": [1.0, 1.0, 1.0] + }, + { + "type": "RigidbodyComponent", + "mass": 0.0, + "restitution": 0.0, + "rigidbodyType": "Static", + "collisionShape": { + "type": "Box", + "halfExtents": [2.0, 10.0, 2.0] + } + } + ], + "children": [ + { + "id": "GraphicsColumn", + "components": [ + { + "type": "TransformComponent", + "position": [0.0, 0.0, 0.0], + "rotation": [0.0, 0.0, 0.0], + "scale": [2.0, 10.0, 2.0] + }, + { + "type": "RenderComponent", + "material": "MapMaterial", + "mesh": "assets://meshes/Cube.mesh" + } + ] + } + + ] + }, + { + "id": "WallFront", + "components": [ + { + "type": "TransformComponent", + "position": [0, 5.0, 20.0], + "rotation": [0.0, 0.0, 0.0], + "scale": [1.0, 1.0, 1.0] + }, + { + "type": "RigidbodyComponent", + "mass": 0.0, + "restitution": 0.0, + "rigidbodyType": "Static", + "collisionShape": { + "type": "Box", + "halfExtents": [20.0, 10.0, 1.0] + } + } + ], + "children": [ + { + "id": "GraphicsWallBack", + "components": [ + { + "type": "TransformComponent", + "position": [0.0, 0.0, 0.0], + "rotation": [0.0, 0.0, 0.0], + "scale": [20.0, 10.0, 1.0] + }, + { + "type": "RenderComponent", + "material": "MapMaterial", + "mesh": "assets://meshes/Cube.mesh" + } + ] + } + + ] + }, + { + "id": "SpawnPoint", + "components": [ + { + "type": "TransformComponent", + "position": [40.0, 0.0, -40.0], + "rotation": [0.0, 0.0, 0.0], + "scale": [3.0, 3.0, 3.0] + }, + { + "type": "RenderComponent", + "material": "SpawnPointMaterial", + "mesh": "assets://meshes/Cube.mesh" + }, + { + "type": "ScriptComponent", + "script_name": "SpawningScript", + "script_path": "scripts://demo/spawnpoint.lua" + } + ] + }, + { + "id": "Trigger", + "components": [ + { + "type": "TransformComponent", + "position": [0.0, -100.0, 0.0], + "rotation": [0.0, 0.0, 0.0], + "scale": [1.0, 1.0, 1.0] + }, + { + "type": "RigidbodyComponent", + "mass": 0.0, + "restitution": 0.0, + "rigidbodyType": "Ghost", + "collisionShape": { + "type": "Box", + "halfExtents": [200.0, 10.0, 200.0] + } + }, + { + "type": "ScriptComponent", + "script_name": "TriggerScript", + "script_path": "scripts://demo/trigger.lua" + } + ], + "children": [ + { + "id": "GraphicsTrigger", + "components": [ + { + "type": "TransformComponent", + "position": [0.0, 0.0, 0.0], + "rotation": [0.0, 0.0, 0.0], + "scale": [200.0, 10.0, 200.0] + }, + { + "type": "RenderComponent", + "material": "TriggerMaterial", + "mesh": "assets://meshes/Cube.mesh" + } + ] + } + + ] + }, + { + "id": "Camera", + "components": [ + { + "type": "TransformComponent", + "position": [0, -2.0, 11.0], + "rotation": [0.0, 0.0, 0.0], + "scale": [1.0, 1.0, 1.0] + }, + { + "type": "ScriptComponent", + "script_name": "MainCameraController", + "script_path": "scripts://MainScene/Camera.lua" + } + ], + "children": [ + { + "id": "RotationHelper", + "components": [ + { + "type": "TransformComponent", + "position": [0.0, 0.0, 0.0], + "rotation": [0.0, 0.0, 0.0], + "scale": [1.0, 1.0, 1.0] + }, + { + "type": "CameraComponent", + "view": "Perspective", + "fov": 90, + "near": 0.001, + "far": 1000, + "aspectRatio": 1.3333 + }, + { + "type": "ScriptComponent", + "script_name": "MainCameraRotationHelper", + "script_path": "scripts://MainScene/CameraHelper.lua" + } + ], + "children": [ + { + "id": "Center", + "components": [ + { + "type": "TransformComponent", + "position": [0,0,-0.2], + "rotation": [0,0,0], + "scale": [0.005,0.005,0.005] + }, + { + "type": "RenderComponent", + "material": "DotMaterial", + "mesh": "assets://meshes/lightSphere_Sphere.mesh" + } + ] + }, + { + "id": "GravityGun", + "components": [ + { + "type": "TransformComponent", + "position": [ 0, 0, 0 ], + "rotation": [ 0, 0, 0 ], + "scale": [ 1, 1, 1 ] + }, + { + "type": "ScriptComponent", + "script_name": "GravityGunScript", + "script_path": "scripts://demo/gravitygun.lua" + } + ] + } + ] + } + ] + } + ], + "pipelines": [ + { + "id": "DefaultPipeline", + "shaderStages": [ + { + "type": "Vertex", + "shaderPath": "shaders://default.vert" + }, + { + "type": "Fragment", + "shaderPath": "shaders://default.frag" + } + ] + }, + { + "id": "LightSpherePipeline", + "shaderStages": [ + { + "type": "Vertex", + "shaderPath": "shaders://lightObject.vert" + }, + { + "type": "Fragment", + "shaderPath": "shaders://lightObject.frag" + } + ] + }, + { + "id": "DefferedPipeline", + "shaderStages": [ + { + "type": "Vertex", + "shaderPath": "shaders://mrt.vert" + }, + { + "type": "Fragment", + "shaderPath": "shaders://mrt.frag" + } + ] + }, + { + "id": "CustomPipeline", + "shaderStages": [ + { + "type": "Vertex", + "shaderPath": "shaders://custom.vert" + }, + { + "type": "Fragment", + "shaderPath": "shaders://custom.frag" + } + ] + } + ], + "activeCamera": "Camera.RotationHelper" +} diff --git a/scripts/MainScene/Camera.lua b/scripts/MainScene/Camera.lua index f1e028f..587d2c8 100755 --- a/scripts/MainScene/Camera.lua +++ b/scripts/MainScene/Camera.lua @@ -1,5 +1,5 @@ this.on_init = function() - this.speed = 0.01 + this.speed = 0.1 this.angles = Vec3:new() this.mouse_sens = 0.01 end @@ -33,12 +33,5 @@ this.on_update = function() pos = pos - helper.right * this.speed end - if Input.getMouseButtonJustPressed(0) then - hit = rayCast(this.worldPosition, helper.forward, 300) - if(hit.hasHit) then - hit.object.position = hit.object.position + Vec3:new(0, 0, -15) - end - end - this.position = pos end diff --git a/scripts/MainScene/CameraHelper.lua b/scripts/MainScene/CameraHelper.lua index 8b003b9..4549d64 100755 --- a/scripts/MainScene/CameraHelper.lua +++ b/scripts/MainScene/CameraHelper.lua @@ -3,9 +3,20 @@ this.on_init = function() this.mouse_sens = 0.01 end +function clamp(min, max, val) + if val < min then + return min + elseif val > max then + return max + else + return val + end +end + this.on_update = function() local deltaMouseMovement = Input.getDeltaMousePos() - this.angles.x = this.angles.x - deltaMouseMovement.y * this.mouse_sens + this.angles.x = clamp(-1.57, 1.57, this.angles.x - deltaMouseMovement.y * this.mouse_sens) + print(this.angles.x) this.eulerAngles = this.angles if Input.getKeyJustPressed(Input.KeyCode.O) then diff --git a/scripts/demo/gravitygun.lua b/scripts/demo/gravitygun.lua new file mode 100644 index 0000000..9f393ea --- /dev/null +++ b/scripts/demo/gravitygun.lua @@ -0,0 +1,50 @@ +-- Parameters +this.held = nil +this.held_distance = 0 +this.rigidness = 0.2 +this.distance_change_speed = 0.1 +this.speed_factor = 5.0 + +-- this.on_init = function() +-- end + +this.vec_mag = function(v) + return (v.x^2 + v.y^2 + v.z^2) ^0.5 +end + +this.vec_lerp = function(v1,v2,t) + return v1 * (1-t) + v2 * (t) +end + +this.check_inputs = function() + if Input.getMouseButtonJustPressed(0) then + hit = rayCast(this.worldPosition, this.forward, 3000) + if(hit.hasHit) then + this.held = hit.object + this.held_distance = this.vec_mag(hit.object.worldPosition - this.worldPosition) + end + end + + if Input.getMouseButtonJustReleased(0) then + this.held = nil + end + + if Input.getMouseButtonDown(3) then + this.held_distance = this.held_distance + this.distance_change_speed + end + + if Input.getMouseButtonDown(4) then + this.held_distance = this.held_distance - this.distance_change_speed + end +end + +this.on_update = function() + this.check_inputs() + + if this.held then + target_position = this.worldPosition + this.forward * this.held_distance + -- this.held.position = this.vec_lerp(this.held.position, target_position, this.rigidness) + rb = this.held:getComponent(Rigidbody) + rb:setVelocity((target_position - this.held.worldPosition) * this.speed_factor) + end +end diff --git a/scripts/demo/spawnpoint.lua b/scripts/demo/spawnpoint.lua new file mode 100644 index 0000000..b8f9940 --- /dev/null +++ b/scripts/demo/spawnpoint.lua @@ -0,0 +1,11 @@ +this.shootForce = 600 + + +this.on_update = function() + if Input.getKeyJustPressed(Input.KeyCode.P) then + spawn = loadPrefab('prefabs://DamagedHelmet.pf') + spawn.position = this.worldPosition + rb = spawn:getComponent(Rigidbody) + rb:addForce(Vec3:new(-1, -2, 1) * this.shootForce) + end +end diff --git a/scripts/demo/trigger.lua b/scripts/demo/trigger.lua new file mode 100644 index 0000000..d589666 --- /dev/null +++ b/scripts/demo/trigger.lua @@ -0,0 +1,3 @@ +this.on_collisionenter = function(other) + destroyObject(other) +end