Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • gamedev/fggl
  • onuralpsezer/fggl
2 results
Show changes
Showing
with 301 additions and 115 deletions
packs/
demo/data/backpack/ao.jpg

132 B

source diff could not be displayed: it is stored in LFS. Options to address this: view the blob.
source diff could not be displayed: it is stored in LFS. Options to address this: view the blob.
demo/data/backpack/diffuse.jpg

132 B

image diff could not be displayed: it is too large. Options to address this: view the blob.
demo/data/backpack/roughness.jpg

132 B

Model by Berk Gedik, from: https://sketchfab.com/3d-models/survival-guitar-backpack-low-poly-799f8c4511f84fab8c3f12887f7e6b36
Modified material assignment (Joey de Vries) for easier load in OpenGL model loading chapter, and renamed albedo to diffuse and metallic to specular to match non-PBR lighting setup.
\ No newline at end of file
demo/data/backpack/specular.jpg

132 B

---
- define: label
attrs:
value: """
- define: button
children:
- template: label
- define: textinput
children:
- template: label
- define: checkbox
attrs:
state: False
- define: radio
attrs:
state: False
- define: frame
......@@ -12,7 +12,7 @@ uniform mat4 model;
void main()
{
gl_Position = view * model * vec4(aPos, 1.0);
gl_Position = view * model * vec4(aPos, 1.0);
mat3 normalMatrix = mat3(transpose(inverse(view * model)));
vs_out.normal = normalize(vec3(vec4(normalMatrix * aNormal, 0.0)));
}
---
# This currently isn't functional, it's an experiment in how this
# might be defined in a user-friendly(ish) way.
prefabs:
wallX:
transform:
staticMesh:
pipeline: phong
shape: # TODO
rigidBody:
type: static
shape:
type: box
extents: [0.5, 2.5, 20.5]
wallZ:
transform:
staticMesh:
pipeline: phong
rigidBody:
type: static
shape:
type: box
extents: [39.0, 2.5, 0.5]
floor:
transform:
staticMesh:
pipeline: phong
shape: # TODO
rigidBody:
type: static
shape: box
extents: [20, 0.5, 20.0]
player:
transform:
rigidBody:
mass: 1
shape:
type: sphere
extents: [0.5, 0.5, 0.5]
dynamics:
staticMesh:
pipeline: phong
shape: # TODO
collectable:
transform:
staticMesh:
shader: phong
shape: # TODO
callbacks:
scene:
entities:
- prefab: wallX
transform:
origin: [20, 0, 0]
- prefab: wallX
transform:
origin: [-20, 0, 0]
- prefab: wallZ
transform: [0, 0, -20]
- prefab: wallZ
transform: [0, 0, 20]
- prefab: floor
transform: [0, -2.5, 0]
- prefab: player
\ No newline at end of file
/**
* OpenGL RedBook Shader.
* Examples 7.8, 7.9 and 7.10.
*
* Reflections are happening in camera space
*/
#version 330 core
in Vertex {
vec3 Position;
vec3 Normal;
vec3 Colour;
vec2 TexPos;
};
out vec4 FragColour;
const float constant = 1.0;
const float linear = 0.022;
const float quadratic = 0.0019;
float specPower = 0.5;
const float shininess = 8;
uniform sampler2D diffuseTexture;
uniform sampler2D specularTexture;
uniform mat4 MVMatrix;
uniform vec3 viewerPos_ws;
struct DirectionalLight {
vec3 direction;
vec3 ambient;
vec3 diffuse;
vec3 specular;
};
struct Material {
vec3 emission;
vec3 ambient;
vec3 diffuse;
vec3 specular;
};
uniform DirectionalLight light;
uniform Material material;
const int hasPos = 0;
vec4 calcDirLight(DirectionalLight light, vec3 Normal, vec3 viewDir, vec4 specPx, vec4 diffPx) {
vec3 lightDir = normalize( ( vec4(light.direction, 1) * MVMatrix).xyz - Position.xyz );
vec4 ambient = 0.1 * vec4( light.ambient, 1);
vec3 reflectDir = reflect( -lightDir, Normal );
float spec = pow( max( dot(viewDir, reflectDir), 0.0), shininess);
vec4 specular = 1.0 * vec4( light.specular, 1) * specPower * (spec * specPx);
float diff = max( dot(Normal, lightDir), 0.0 );
vec4 diffuse = vec4(light.diffuse,1) * (diff * diffPx);
if ( hasPos == 1 ) {
vec3 lightPos = ( vec4(light.direction, 1) * MVMatrix).xyz;
float distance = length( lightPos - Position.xyz );
float att = 1.0 / (constant +
(linear * distance) +
(quadratic * (distance * distance)));
ambient *= att;
diffuse *= att;
specular *= att;
}
return (ambient + diffuse + specular);
}
void main() {
vec3 viewDir = normalize(-Position);
vec4 diffPx = vec4(material.diffuse, 1);
vec4 specPx = vec4(material.specular, 1);
if ( hasPos != 1) {
diffPx *= texture(diffuseTexture, TexPos);
specPx *= texture(specularTexture, TexPos);
}
FragColour = vec4(Colour, 1);
FragColour *= calcDirLight(light, Normal, viewDir, specPx, diffPx);
}
\ No newline at end of file
/**
* OpenGL RedBook Shader.
* Example 7.8
*/
#version 330 core
layout (location = 0) in vec3 VertexPosition;
layout (location = 1) in vec3 VertexNormal;
layout (location = 2) in vec3 VertexColour;
layout (location = 3) in vec2 VertexTex;
uniform mat4 MVPMatrix;
uniform mat4 MVMatrix;
uniform mat3 NormalMatrix;
out Vertex {
vec3 Position;
vec3 Normal;
vec3 Colour;
vec2 TexPos;
};
void main() {
Colour = VertexColour;
Normal = mat3(transpose(inverse(MVMatrix))) * VertexNormal;
TexPos = VertexTex;
Position = vec3(MVMatrix * vec4(VertexPosition, 1));
gl_Position = MVPMatrix * vec4(VertexPosition, 1);
}
\ No newline at end of file
......@@ -86,8 +86,6 @@ void main() {
}
float diffuse = max(0.0, dot(Normal, lightDirection));
if (diffuse == 0.0)
specular = 0.0;
else
......
......@@ -8,9 +8,9 @@ uniform mat4 MVPMatrix;
uniform mat4 MVMatrix;
uniform mat3 NormalMatrix;
in vec4 VertexPosition;
in vec3 VertexNormal;
in vec4 VertexColour;
layout (location = 0) in vec3 VertexPosition;
layout (location = 1) in vec3 VertexNormal;
layout (location = 2) in vec3 VertexColour;
out vec4 Position;
out vec3 Normal;
......@@ -20,7 +20,8 @@ out int matIndex;
void main() {
Colour = vec4(1.0, 1.0, 1.0, 1.0f);
Normal = NormalMatrix * VertexNormal;
Position = MVMatrix * VertexPosition;
gl_Position = MVPMatrix * VertexPosition;
Position = MVMatrix * vec4(VertexPosition, 1.0);
matIndex = 0;
gl_Position = MVPMatrix * vec4(VertexPosition, 1.0);
}
\ No newline at end of file
print("File has been loaded!")
-- when the scene loads, switch to topdown to show state integration
--switch_scene(state, "topdown");
\ No newline at end of file
---
prefabs:
- name: "wallX"
- name: "rb_environment"
components:
gfx::material:
ambient: [0.0215, 0.1754, 0.0215]
diffuse: [1, 1, 1]
specular: [0.0633, 0.727811, 0.633]
shininess: 16
- name: "rb_wallX"
parent: "rb_environment"
components:
Transform:
StaticMesh:
pipeline: redbook/lighting
pipeline: redbook/debug
shape_id: "mesh_rb_wall_x"
shape:
type: box
scale: [1.0, 5.0, 41]
......@@ -14,11 +23,13 @@ prefabs:
type: box
extents: [0.5, 2.5, 20.5]
# Wall Z shorter to avoid z-fighting
- name: "wallZ"
- name: "rb_wallZ"
parent: "rb_environment"
components:
Transform:
StaticMesh:
pipeline: redbook/lighting
pipeline: redbook/debug
shape_id: "mesh_rb_wall_z"
shape:
type: box
scale: [39, 5, 1]
......@@ -27,11 +38,13 @@ prefabs:
shape:
type: box
extents: [ 19.5, 2.5, 0.5 ]
- name: "floor"
- name: "rb_floor"
parent: "rb_environment"
components:
Transform:
StaticMesh:
pipeline: redbook/lighting
pipeline: redbook/debug
shape_id: "mesh_rb_floor"
shape:
type: box # we don't (currently) support planes...
scale: [39, 0.5, 39]
......@@ -40,11 +53,12 @@ prefabs:
shape:
type: box # we don't (currently) support planes...
extents: [19.5, 0.25, 19.5]
- name: player
- name: rb_player
components:
Transform:
StaticMesh:
pipeline: redbook/lighting
pipeline: redbook/debug
shape_id: "mesh_rb_player"
shape:
type: sphere
gfx::material:
......@@ -56,11 +70,14 @@ prefabs:
shape:
type: sphere
radius: 1
- name: collectable
- name: rb_collectable
tags:
- "collectable"
components:
Transform:
StaticMesh:
pipeline: redbook/lighting
pipeline: redbook/debug
shape_id: "mesh_rb_collect"
shape:
type: box
gfx::material:
......@@ -72,5 +89,46 @@ prefabs:
type: kinematic
shape:
type: box
phys::Callbacks:
phys::Cache:
\ No newline at end of file
- name: rb_light
components:
Transform:
gfx::phong::directional:
direction: [10, 5, 0]
scene:
- prefab: rb_wallX
components:
Transform:
origin: [20, 0, 0]
- prefab: rb_wallX
components:
Transform:
origin: [-20, 0, 0]
- prefab: rb_wallZ
components:
Transform:
origin: [0, 0, -20]
- prefab: rb_wallZ
components:
Transform:
origin: [0, 0, 20]
- prefab: rb_floor
components:
Transform:
origin: [0, -2.5, 0]
- prefab: rb_collectable
components:
Transform:
origin: [-5, -0.5, 12]
- prefab: rb_collectable
components:
Transform:
origin: [15, -0.5, 0.5]
- prefab: rb_collectable
components:
Transform:
origin: [6, -0.5, -15]
- prefab: rb_player
name: "player"
- prefab: rb_light
scripts:
- "rollball.lua"
\ No newline at end of file
---
floors:
ground:
visible: true
walls:
none:
visible: false
solid:
visible: true
\ No newline at end of file
......@@ -4,47 +4,66 @@ prefabs:
components:
Transform:
StaticMesh:
pipeline: phong
pipeline: redbook/debug
shape_id: td_wall_x
shape:
type: box
scale: [1.0, 5.0, 41]
phys::Body:
type: static
shape:
type: box
extents: [0.5, 2.5, 20.5]
gfx::material:
ambient: [0.25, 0.25, 0.25]
diffuse: [0.4, 0.4, 0.4]
specular: [0.774597,0.774597,0.774597]
shininess: 0.6
# phys::Body:
# type: static
# shape:
# type: box
# extents: [0.5, 2.5, 20.5]
# Wall Z shorter to avoid z-fighting
- name: "wallZ"
components:
Transform:
StaticMesh:
pipeline: phong
pipeline: redbook/debug
shape_id: td_wall_y
shape:
type: box
scale: [39, 5, 1]
phys::Body:
type: static
shape:
type: box
extents: [ 19.5, 2.5, 0.5 ]
gfx::material:
ambient: [0.25, 0.25, 0.25]
diffuse: [0.4, 0.4, 0.4]
specular: [0.774597,0.774597,0.774597]
shininess: 0.6
# phys::Body:
# type: static
# shape:
# type: box
# extents: [ 19.5, 2.5, 0.5 ]
- name: "floor"
components:
Transform:
StaticMesh:
pipeline: phong
pipeline: redbook/debug
shape_id: td_floor
shape:
type: box # we don't (currently) support planes...
scale: [39, 0.5, 39]
phys::Body:
type: static
shape:
type: box # we don't (currently) support planes...
extents: [19.5, 0.25, 19.5]
gfx::material:
ambient: [0.25, 0.25, 0.25]
diffuse: [0.4, 0.4, 0.4]
specular: [0.774597,0.774597,0.774597]
shininess: 0.6
# phys::Body:
# type: static
# shape:
# type: box # we don't (currently) support planes...
# extents: [19.5, 0.25, 19.5]
- name: player
components:
Transform:
StaticMesh:
pipeline: phong
pipeline: redbook/lighting
shape_id: td_player
shape:
type: sphere
gfx::material:
......@@ -52,15 +71,16 @@ prefabs:
diffuse: [0.4, 0.4, 0.4]
specular: [0.774597,0.774597,0.774597]
shininess: 0.6
phys::Body:
shape:
type: sphere
radius: 1
# phys::Body:
# shape:
# type: sphere
# radius: 1
- name: collectable
components:
Transform:
StaticMesh:
pipeline: phong
pipeline: redbook/lighting
shape_id: td_collect
shape:
type: box
gfx::material:
......@@ -68,9 +88,9 @@ prefabs:
diffuse: [1, 1, 1]
specular: [0.0633, 0.727811, 0.633]
shininess: 0.6
phys::Body:
type: kinematic
shape:
type: box
phys::Callbacks:
phys::Cache:
\ No newline at end of file
# phys::Body:
# type: kinematic
# shape:
# type: box
# phys::Callbacks:
# phys::Cache:
\ No newline at end of file