Skip to content

Commit

Permalink
0.2.3a - Normal mapping on specular lighting
Browse files Browse the repository at this point in the history
  • Loading branch information
skdeng committed Mar 8, 2015
1 parent 98f5411 commit 87455fc
Show file tree
Hide file tree
Showing 73 changed files with 465 additions and 107 deletions.
Binary file modified Debug/astria.exe
Binary file not shown.
Binary file modified Debug/astria.ilk
Binary file not shown.
Binary file modified Debug/astria.pdb
Binary file not shown.
5 changes: 3 additions & 2 deletions Debug/credits.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ SplashScreen - Perilous Ice Shape by tobylewin
Skybox - from www.custommapmakers.org/skyboxes.php
Models - tf3dm.com
- www.turbosquid.com
Font - After shok by eightface
- Gunplay by Typodermic Fonts
Font - After shok by eightface
- Gunplay by Typodermic Fonts
- Ethnocentric by Typodermic Fonts
Music - Self Esteem Fund from Portal
3 changes: 2 additions & 1 deletion Debug/help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ WASD - Movement
Mouse - Look
MouseWheel - Zoom In/Out
Hold Shift - Toggle Sprint
Q - Toggle Wireframe Mode
F - Toggle Fog (to see the beautiful skybox)
G - Toggle Gravity (also collision with map)
N - Toggle Normal Map
M - Pause/Resume Music & Sound Effects
Escape - Pause
2 changes: 1 addition & 1 deletion Debug/params.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
WindowName Desolation
VersionNumber 0.2.3
VersionNumber 0.2.3a
ResolutionWidth 1024
ResolutionHeight 768
IconImage gfx/img/dota2sf_icon.png
Expand Down
23 changes: 19 additions & 4 deletions Debug/shaders/instancing.vert
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
#version 330

layout(location = 0) in vec3 inPosition;
layout(location = 1) in vec2 inCoords;
layout(location = 2) in vec3 inNormal;
layout(location = 3) in mat4 inModelMatrix;
layout (location = 0) in vec3 inPosition;
layout (location = 1) in vec2 inCoords;
layout (location = 2) in vec3 inNormal;
layout (location = 3) in vec3 inTangent;
layout (location = 4) in vec3 inBitangent;
layout (location = 5) in mat4 inModelMatrix;

struct DirectionalLight
{
vec3 vColor;
vec3 vDirection;
float fAmbient;
float fBrightness;
};

uniform struct Matrices
{
Expand All @@ -15,6 +25,11 @@ smooth out vec3 vNormal;
smooth out vec2 vTexCoord;
smooth out vec3 vWorldPos;

out vec3 vLightDir_tangentspace;

uniform DirectionalLight sunLight;
uniform bool bEnableNormalMap;

void main()
{
mat4 mMVP = matrices.mProjection * matrices.mView * inModelMatrix;
Expand Down
42 changes: 27 additions & 15 deletions Debug/shaders/main_shader.frag
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
#version 330

#include

smooth in vec2 vTexCoord;
smooth in vec3 vNormal;
smooth in vec4 vEyeSpacePos;
smooth in vec3 vWorldPos;
out vec4 outputColor;

struct Material
{
sampler2D diffuse;
sampler2D normal;
sampler2D specular;
};

Expand Down Expand Up @@ -54,6 +47,16 @@ uniform FogParameters fogParams;

uniform int bSkybox;
uniform int bFog;
uniform bool bEnableNormalMap;

smooth in vec2 vTexCoord;
smooth in vec3 vNormal;
smooth in vec4 vEyeSpacePos;
smooth in vec3 vWorldPos;
in vec3 vLightDir_tangentspace;
in vec3 vEyeDir_tangentspace;

out vec4 outputColor;

void main()
{
Expand All @@ -69,20 +72,29 @@ void main()
return;
}

vec3 vNormalized = normalize(vNormal);
vec3 vNormal_extended = normalize(vNormal);
vec3 vLightDir = sunLight.vDirection;
vec3 vEyeDirection = vEyePosition - vWorldPos;

if(bEnableNormalMap)
{
vNormal_extended = normalize(texture2D(mat.normal, vTexCoord).rgb*2.0-1.0);
vLightDir = normalize(vLightDir_tangentspace);
vEyeDirection = vEyeDir_tangentspace;
}

//Diffuse light
float fDiffuseIntensity = clamp(dot(vNormal, -sunLight.vDirection), 0.0, 1.0);
vec3 vDiffuseColor = pow(sunLight.fBrightness,2) * sunLight.vColor * fDiffuseIntensity * vec3(texture2D(mat.diffuse, vTexCoord));
float fDiffuseIntensity = clamp(dot(vNormal_extended, -vLightDir), 0.0, 1.0);
vec3 vDiffuseColor = sunLight.fBrightness * sunLight.vColor * fDiffuseIntensity * vec3(texture2D(mat.diffuse, vTexCoord));

//Ambient
vec3 vAmbientColor = sunLight.vColor * sunLight.fAmbient * vec3(texture2D(mat.diffuse, vTexCoord));

//Specular
vec3 vReflected = normalize(reflect(sunLight.vDirection, vNormalized));
vec3 vView = normalize(vEyePosition - vWorldPos);
//Specular
vec3 vReflected = reflect(vLightDir, vNormal_extended);
vec3 vView = normalize(vEyeDirection);
float fSpecularIntensity = clamp(dot(vReflected, vView), 0, 1);
vec3 vSpecularColor = 0.6 * sunLight.vColor * fSpecularIntensity * vec3(texture2D(mat.specular, vTexCoord));
vec3 vSpecularColor = sunLight.fBrightness * 0.6 * sunLight.vColor * fSpecularIntensity * vec3(texture2D(mat.specular, vTexCoord));

outputColor = vec4(vAmbientColor + vDiffuseColor + vSpecularColor, 1.0f);

Expand Down
43 changes: 41 additions & 2 deletions Debug/shaders/main_shader.vert
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,65 @@ uniform struct Matrices
mat4 mNormal;
} matrices;

struct DirectionalLight
{
vec3 vColor;
vec3 vDirection;
float fAmbient;
float fBrightness;
};

layout (location = 0) in vec3 inPosition;
layout (location = 1) in vec2 inCoord;
layout (location = 2) in vec3 inNormal;
layout (location = 3) in vec3 inTangent;
layout (location = 4) in vec3 inBitangent;


smooth out vec3 vNormal;
smooth out vec2 vTexCoord;
smooth out vec3 vWorldPos;

smooth out vec4 vEyeSpacePos;

out vec3 vEyeDir_tangentspace;
out vec3 vLightDir_tangentspace;

uniform vec3 vEyePosition;
uniform DirectionalLight sunLight;
uniform bool bEnableNormalMap;

void main()
{
mat4 mMV = matrices.mView*matrices.mModel; //Matrix multiplication is from left to right
mat4 mMV = matrices.mView*matrices.mModel;
mat4 mMVP = matrices.mProjection*matrices.mView*matrices.mModel;

vTexCoord = inCoord;

vEyeSpacePos = mMV*vec4(inPosition, 1.0);
vEyeSpacePos = mMV * vec4(inPosition, 1.0);
gl_Position = mMVP*vec4(inPosition, 1.0);

vNormal = (matrices.mNormal*vec4(inNormal, 1.0)).xyz;
vWorldPos = (matrices.mModel*vec4(inPosition, 1.0)).xyz;

//Eye space calculations
vec3 vLightDir_eyespace = (mMV * vec4(-sunLight.vDirection, 1.0f)).xyz;
vec3 vEyeDir_eyespace = vec3(0,0,0) - (vEyeSpacePos).xyz;

if(bEnableNormalMap)
{
mat3 mMV3x3 = mat3(mMV);

vec3 vNormal_eyespace = mMV3x3 * inNormal;
vec3 vTangent_eyespace = mMV3x3 * inTangent;
vec3 vBitangent_eyespace = mMV3x3 * inBitangent;

mat3 mTBN = transpose(mat3(vTangent_eyespace, vBitangent_eyespace, vNormal_eyespace));
vLightDir_tangentspace = mTBN * vLightDir_eyespace;
vEyeDir_tangentspace = mTBN * vEyeDir_eyespace;
}
else
{
vLightDir_tangentspace = vec3(0,0,0);
}
}
Binary file removed Release/astria.exe
Binary file not shown.
Binary file modified Release/astria.pdb
Binary file not shown.
5 changes: 3 additions & 2 deletions Release/credits.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ SplashScreen - Perilous Ice Shape by tobylewin
Skybox - from www.custommapmakers.org/skyboxes.php
Models - tf3dm.com
- www.turbosquid.com
Font - After shok by eightface
- Gunplay by Typodermic Fonts
Font - After shok by eightface
- Gunplay by Typodermic Fonts
- Ethnocentric by Typodermic Fonts
Music - Self Esteem Fund from Portal
Binary file modified Release/gfx/Thumbs.db
Binary file not shown.
Binary file modified Release/gfx/barrel/Thumbs.db
Binary file not shown.
Binary file modified Release/gfx/coffee_tree/Thumbs.db
Binary file not shown.
Binary file modified Release/gfx/img/Thumbs.db
Binary file not shown.
Binary file modified Release/gfx/nanosuit/Thumbs.db
Binary file not shown.
2 changes: 2 additions & 0 deletions Release/help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ MouseWheel - Zoom In/Out
Hold Shift - Toggle Sprint
F - Toggle Fog (to see the beautiful skybox)
G - Toggle Gravity (also collision with map)
N - Toggle Normal Map
M - Pause/Resume Music & Sound Effects
Escape - Pause
2 changes: 1 addition & 1 deletion Release/params.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
WindowName Desolation
VersionNumber 0.2.3
VersionNumber 0.2.3a
ResolutionWidth 1024
ResolutionHeight 768
IconImage gfx/img/dota2sf_icon.png
Expand Down
17 changes: 9 additions & 8 deletions Release/shaders/main_shader.frag
Original file line number Diff line number Diff line change
Expand Up @@ -74,27 +74,28 @@ void main()

vec3 vNormal_extended = normalize(vNormal);
vec3 vLightDir = sunLight.vDirection;
vec3 vEyeDirection = vEyePosition - vWorldPos;

if(bEnableNormalMap)
{
vNormal_extended = normalize(texture2D(mat.normal, vTexCoord).rgb*2.0-1.0);
vLightDir = vLightDir_tangentspace;
vLightDir = normalize(vLightDir_tangentspace);
vEyeDirection = vEyeDir_tangentspace;
}

//Diffuse light
float fDiffuseIntensity = clamp(dot(vNormal_extended, -vLightDir), 0.0, 1.0);
vec3 vDiffuseColor = pow(sunLight.fBrightness,2) * sunLight.vColor * fDiffuseIntensity * vec3(texture2D(mat.diffuse, vTexCoord));
//vDiffuseColor = vec3(0,0,0);
vec3 vDiffuseColor = sunLight.fBrightness * sunLight.vColor * fDiffuseIntensity * vec3(texture2D(mat.diffuse, vTexCoord));

//Ambient
vec3 vAmbientColor = sunLight.vColor * sunLight.fAmbient * vec3(texture2D(mat.diffuse, vTexCoord));

//Specular
vec3 vReflected = (reflect(sunLight.vDirection, vNormal)); //Not using normal map yet
vec3 vView = normalize(vEyePosition - vWorldPos);
//Specular
vec3 vReflected = reflect(vLightDir, vNormal_extended);
vec3 vView = normalize(vEyeDirection);
float fSpecularIntensity = clamp(dot(vReflected, vView), 0, 1);
vec3 vSpecularColor = 0.6 * sunLight.vColor * fSpecularIntensity * vec3(texture2D(mat.specular, vTexCoord));
vec3 vSpecularColor = sunLight.fBrightness * 0.6 * sunLight.vColor * fSpecularIntensity * vec3(texture2D(mat.specular, vTexCoord));

outputColor = vec4(vAmbientColor + vDiffuseColor + vSpecularColor, 1.0f);

if (bFog == 1)
Expand Down
17 changes: 11 additions & 6 deletions Release/shaders/main_shader.vert
Original file line number Diff line number Diff line change
Expand Up @@ -32,36 +32,41 @@ smooth out vec4 vEyeSpacePos;
out vec3 vEyeDir_tangentspace;
out vec3 vLightDir_tangentspace;

uniform vec3 vEyePosition;
uniform DirectionalLight sunLight;
uniform bool bEnableNormalMap;

void main()
{
mat4 mMV = matrices.mView*matrices.mModel; //Matrix multiplication is from left to right
mat4 mMV = matrices.mView*matrices.mModel;
mat4 mMVP = matrices.mProjection*matrices.mView*matrices.mModel;

vTexCoord = inCoord;

vEyeSpacePos = mMV*vec4(inPosition, 1.0);
vEyeSpacePos = mMV * vec4(inPosition, 1.0);
gl_Position = mMVP*vec4(inPosition, 1.0);

vNormal = (matrices.mNormal*vec4(inNormal, 1.0)).xyz;
vWorldPos = (matrices.mModel*vec4(inPosition, 1.0)).xyz;

vec3 vEyeDir_eyespace = vec3(0,0,0) - vEyeSpacePos.xyz;
//Eye space calculations
vec3 vLightDir_eyespace = (mMV * vec4(-sunLight.vDirection, 1.0f)).xyz;
vec3 vEyeDir_eyespace = vec3(0,0,0) - (vEyeSpacePos).xyz;

if(bEnableNormalMap)
{
mat3 mMV3x3 = mat3(mMV);

vec3 vNormal_eyespace = mMV3x3 * normalize(vNormal);
vec3 vNormal_eyespace = mMV3x3 * inNormal;
vec3 vTangent_eyespace = mMV3x3 * inTangent;
vec3 vBitangent_eyespace = mMV3x3 * inBitangent;

mat3 mTBN = transpose(mat3(vTangent_eyespace, vBitangent_eyespace, vNormal_eyespace));
vLightDir_tangentspace = normalize(mTBN * sunLight.vDirection);
vEyeDir_tangentspace = normalize(mTBN * vEyeDir_eyespace);
vLightDir_tangentspace = mTBN * vLightDir_eyespace;
vEyeDir_tangentspace = mTBN * vEyeDir_eyespace;
}
else
{
vLightDir_tangentspace = vec3(0,0,0);
}
}
Binary file modified astria.v12.suo
Binary file not shown.
Loading

0 comments on commit 87455fc

Please sign in to comment.