Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 0 additions & 148 deletions tutorial/src/main/assets/shaders/basic_lighting/6.multiple_lights.frag

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ out vec4 FragColor;
void main()
{
FragColor = vec4(1.0); // set all 4 vector values to 1.0
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ uniform mat4 projection;
void main()
{
gl_Position = projection * view * model * vec4(aPos, 1.0);
}
}
50 changes: 50 additions & 0 deletions tutorial/src/main/assets/shaders/basic_lighting/lighting_maps.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#version 320 es
precision mediump float;
out vec4 FragColor;

struct Material {
sampler2D diffuse;
sampler2D specular;
sampler2D emission;
float shininess;
};

struct Light {
vec3 position;

vec3 ambient;
vec3 diffuse;
vec3 specular;
};

in vec3 FragPos;
in vec3 Normal;
in vec2 TexCoords;

uniform vec3 viewPos;
uniform Material material;
uniform Light light;

void main()
{
// ambient
vec3 ambient = light.ambient * texture(material.diffuse, TexCoords).rgb;

// diffuse
vec3 norm = normalize(Normal);
vec3 lightDir = normalize(light.position - FragPos);
float diff = max(dot(norm, lightDir), 0.0);
vec3 diffuse = light.diffuse * diff * texture(material.diffuse, TexCoords).rgb;

// specular
vec3 viewDir = normalize(viewPos - FragPos);
vec3 reflectDir = reflect(-lightDir, norm);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
vec3 specular = light.specular * spec * texture(material.specular, TexCoords).rgb;

// emission
vec3 emission = texture(material.emission, TexCoords).rgb;

vec3 result = ambient + diffuse + specular + emission;
FragColor = vec4(result, 1.0);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#version 320 es

layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aNormal;
layout (location = 2) in vec2 aTexCoords;
Expand All @@ -18,4 +19,4 @@ void main()
TexCoords = aTexCoords;

gl_Position = projection * view * vec4(FragPos, 1.0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ void main()

if(gl_InvocationID == 0)
{
const int MIN_TESS_LEVEL = 4;
const int MAX_TESS_LEVEL = 64;
const float MIN_TESS_LEVEL = 4.;
const float MAX_TESS_LEVEL = 64.;
const float MIN_DISTANCE = 20.;
const float MAX_DISTANCE = 800.;

Expand All @@ -26,15 +26,15 @@ void main()
vec4 eyeSpacePos11 = view * model * gl_in[3].gl_Position;

// "distance" from camera scaled between 0 and 1
float distance00 = clamp( (abs(eyeSpacePos00.z) - MIN_DISTANCE) / (MAX_DISTANCE-MIN_DISTANCE), 0.0, 1.0 );
float distance01 = clamp( (abs(eyeSpacePos01.z) - MIN_DISTANCE) / (MAX_DISTANCE-MIN_DISTANCE), 0.0, 1.0 );
float distance10 = clamp( (abs(eyeSpacePos10.z) - MIN_DISTANCE) / (MAX_DISTANCE-MIN_DISTANCE), 0.0, 1.0 );
float distance11 = clamp( (abs(eyeSpacePos11.z) - MIN_DISTANCE) / (MAX_DISTANCE-MIN_DISTANCE), 0.0, 1.0 );

float tessLevel0 = mix( MAX_TESS_LEVEL, MIN_TESS_LEVEL, min(distance10, distance00) );
float tessLevel1 = mix( MAX_TESS_LEVEL, MIN_TESS_LEVEL, min(distance00, distance01) );
float tessLevel2 = mix( MAX_TESS_LEVEL, MIN_TESS_LEVEL, min(distance01, distance11) );
float tessLevel3 = mix( MAX_TESS_LEVEL, MIN_TESS_LEVEL, min(distance11, distance10) );
float distance00 = clamp((abs(eyeSpacePos00.z) - MIN_DISTANCE) / (MAX_DISTANCE - MIN_DISTANCE), 0.0, 1.0);
float distance01 = clamp((abs(eyeSpacePos01.z) - MIN_DISTANCE) / (MAX_DISTANCE - MIN_DISTANCE), 0.0, 1.0);
float distance10 = clamp((abs(eyeSpacePos10.z) - MIN_DISTANCE) / (MAX_DISTANCE - MIN_DISTANCE), 0.0, 1.0);
float distance11 = clamp((abs(eyeSpacePos11.z) - MIN_DISTANCE) / (MAX_DISTANCE - MIN_DISTANCE), 0.0, 1.0);

float tessLevel0 = mix(MAX_TESS_LEVEL, MIN_TESS_LEVEL, min(distance10, distance00));
float tessLevel1 = mix(MAX_TESS_LEVEL, MIN_TESS_LEVEL, min(distance00, distance01));
float tessLevel2 = mix(MAX_TESS_LEVEL, MIN_TESS_LEVEL, min(distance01, distance11));
float tessLevel3 = mix(MAX_TESS_LEVEL, MIN_TESS_LEVEL, min(distance11, distance10));

gl_TessLevelOuter[0] = tessLevel0;
gl_TessLevelOuter[1] = tessLevel1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#version 320 es
layout(quads, fractional_odd_spacing, ccw) in;
layout (quads, fractional_odd_spacing, ccw) in;

uniform sampler2D heightMap;
uniform mat4 model;
Expand Down Expand Up @@ -33,7 +33,7 @@ void main()

vec4 uVec = p01 - p00;
vec4 vVec = p10 - p00;
vec4 normal = normalize( vec4(cross(vVec.xyz, uVec.xyz), 0.) );
vec4 normal = normalize(vec4(cross(vVec.xyz, uVec.xyz), 0.));

vec4 p0 = (p01 - p00) * u + p00;
vec4 p1 = (p11 - p10) * u + p10;
Expand Down
4 changes: 2 additions & 2 deletions tutorial/src/main/cpp/basic/AsteroidScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ void AsteroidScene::init() {

// load models
// -----------
m_pRockModel = new Model("models/rock/rock.obj");
m_pPlanetModel = new Model("models/planet/planet.obj");
m_pRockModel = new Model("objects/rock/rock.obj");
m_pPlanetModel = new Model("objects/planet/planet.obj");

// generate a large list of semi-random model transformation matrices
// ------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions tutorial/src/main/cpp/basic/ModelScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ void ModelScene::init() {
m_camera = new TargetCamera;
// configure global opengl state
// -----------------------------
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);

// build and compile our shader zprogram
Expand Down
Loading