Moved shaders to separate OpenGL and DirectX folders
This commit is contained in:
@@ -110,8 +110,8 @@ void dd::Renderer::Initialize()
|
||||
m_DeviceContext->RSSetViewports(1, &viewport);
|
||||
|
||||
shaderProgram = new ShaderProgram();
|
||||
shaderProgram->CompileVertexShader(L"vertex.hlsl");
|
||||
shaderProgram->CompilePixelShader(L"pixel.hlsl");
|
||||
shaderProgram->CompileVertexShader(L"Shaders/DirectX/vertex.hlsl");
|
||||
shaderProgram->CompilePixelShader(L"Shaders/DirectX/pixel.hlsl");
|
||||
D3D11_INPUT_ELEMENT_DESC VertexIED[] = {
|
||||
{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
|
||||
{"NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
cbuffer ConstantBuffer
|
||||
{
|
||||
float4x4 MVP;
|
||||
float4x4 ModelMatrix;
|
||||
float4x4 ViewMatrix;
|
||||
float4x4 ProjectionMatrix;
|
||||
float4x4 InverseTransposeViewModel;
|
||||
float3 LightPosition;
|
||||
}
|
||||
|
||||
Texture2D Texture;
|
||||
SamplerState samplerState;
|
||||
|
||||
struct VOut
|
||||
{
|
||||
float4 PixelPosition : SV_POSITION;
|
||||
float4 Position : POSITION;
|
||||
float4 Normal : NORMAL;
|
||||
float4 Tangent : TANGENT0;
|
||||
float4 BiTangent : TANGENT1;
|
||||
float2 TextureCoord : TEXCOORD;
|
||||
float4 DiffuseColor : COLOR0;
|
||||
float4 SpecularColor : COLOR1;
|
||||
float4 BoneIndices1 : BLENDINDICES0;
|
||||
float4 BoneIndices2 : BLENDINDICES1;
|
||||
float4 BoneWeights1 : BLENDWEIGHT0;
|
||||
float4 BoneWeights2 : BLENDWEIGHT1;
|
||||
};
|
||||
|
||||
float4 main(VOut input) : SV_TARGET
|
||||
{
|
||||
float4 ambientLight = float4(1.0f, 1.0f, 1.0f, 1.0f) * 0.1f;
|
||||
////float4 lightPos = float4(0.0f, -1.0f, 2.0f, 0.0f);
|
||||
float4 lightColor = float4(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
|
||||
|
||||
float3 lightToPixel = normalize(LightPosition - mul(input.Position, transpose(ModelMatrix)));
|
||||
|
||||
//float3 lightModelPos = mul(ModelMatrix, LightPosition);
|
||||
float diffuseBrightness = saturate(dot(lightToPixel, normalize(mul(input.Normal, transpose(ModelMatrix)))));
|
||||
|
||||
//input.texcoord.y = 1 - input.texcoord.y;
|
||||
//return float4(input.normal.xy, 0.0f, 0.0f);
|
||||
return Texture.Sample(samplerState, input.TextureCoord);
|
||||
//return float4(input.color.xy, 0.0f, 0.0f);
|
||||
//return (ambientLight + lightColor * diffuseBrightness) * Texture.Sample(samplerState, input.texcoord);
|
||||
//return float4(0.0f, 0.0f, 1.0f, 1.0f);
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
cbuffer ConstantBuffer
|
||||
{
|
||||
float4x4 MVP;
|
||||
float4x4 ModelMatrix;
|
||||
float4x4 ViewMatrix;
|
||||
float4x4 ProjectionMatrix;
|
||||
float4x4 InverseTransposeViewModel;
|
||||
float3 LightPosition;
|
||||
}
|
||||
|
||||
struct VIn
|
||||
{
|
||||
float4 Position : POSITION;
|
||||
float4 Normal : NORMAL;
|
||||
float4 Tangent : TANGENT0;
|
||||
float4 BiTangent : TANGENT1;
|
||||
float2 TextureCoord : TEXCOORD;
|
||||
float4 DiffuseColor : COLOR0;
|
||||
float4 SpecularColor : COLOR1;
|
||||
float4 BoneIndices1 : BLENDINDICES0;
|
||||
float4 BoneIndices2 : BLENDINDICES1;
|
||||
float4 BoneWeights1 : BLENDWEIGHT0;
|
||||
float4 BoneWeights2 : BLENDWEIGHT1;
|
||||
};
|
||||
|
||||
struct VOut
|
||||
{
|
||||
float4 PixelPosition : SV_POSITION;
|
||||
float4 Position : POSITION;
|
||||
float4 Normal : NORMAL;
|
||||
float4 Tangent : TANGENT0;
|
||||
float4 BiTangent : TANGENT1;
|
||||
float2 TextureCoord : TEXCOORD;
|
||||
float4 DiffuseColor : COLOR0;
|
||||
float4 SpecularColor : COLOR1;
|
||||
float4 BoneIndices1 : BLENDINDICES0;
|
||||
float4 BoneIndices2 : BLENDINDICES1;
|
||||
float4 BoneWeights1 : BLENDWEIGHT0;
|
||||
float4 BoneWeights2 : BLENDWEIGHT1;
|
||||
};
|
||||
|
||||
VOut main(VIn input)
|
||||
{
|
||||
/*float4 ambientLight = float4(1.0f, 1.0f, 1.0f, 1.0f) * 0.1f;
|
||||
float4 lightPos = float4(0.0f, 0.0f, 8.0f, 0.0f);
|
||||
float4 lightColor = float4(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
float diffuseBrightness = saturate(dot(normal, lightPos));*/
|
||||
|
||||
VOut output;
|
||||
|
||||
output.PixelPosition = mul(MVP, input.Position);
|
||||
//TODO: Make sure that boneTransform works here.
|
||||
//output.Position = (V * M * boneTransform * vec4(Position, 1.0)).xyz;
|
||||
//output.Normal = (inverse(transpose(V * M)) * boneTransform * vec4(Normal, 0.0)).xyz;
|
||||
output.Tangent = input.Tangent;
|
||||
output.BiTangent = input.BiTangent;
|
||||
output.TextureCoord = input.TextureCoord;
|
||||
output.DiffuseColor = input.DiffuseColor;
|
||||
output.SpecularColor = input.SpecularColor;
|
||||
output.BoneIndices1 = input.BoneIndices1;
|
||||
output.BoneIndices2 = input.BoneIndices2;
|
||||
output.BoneWeights1 = input.BoneWeights1;
|
||||
output.BoneWeights2 = input.BoneWeights2;
|
||||
|
||||
return output;
|
||||
}
|
||||
@@ -80,7 +80,7 @@ void dd::Renderer::LoadShaders()
|
||||
*/
|
||||
|
||||
// Pass #1: Fill G-buffers
|
||||
m_SpDeferred1 = ResourceManager::Load<ShaderProgram>("Shaders/Deferred/1/");
|
||||
m_SpDeferred1 = ResourceManager::Load<ShaderProgram>("Shaders/OpenGL/Deferred/1/");
|
||||
m_SpDeferred1->BindFragDataLocation(0, "GDiffuse");
|
||||
m_SpDeferred1->BindFragDataLocation(1, "GPosition");
|
||||
m_SpDeferred1->BindFragDataLocation(2, "GNormal");
|
||||
@@ -88,30 +88,30 @@ void dd::Renderer::LoadShaders()
|
||||
m_SpDeferred1->Link();
|
||||
|
||||
// Pass #2: Lighting
|
||||
m_SpDeferred2 = ResourceManager::Load<ShaderProgram>("Shaders/Deferred/2/");
|
||||
m_SpDeferred2 = ResourceManager::Load<ShaderProgram>("Shaders/OpenGL/Deferred/2/");
|
||||
//glBindFragDataLocation(m_SPDeferred2, 0, "FragmentLighting");
|
||||
m_SpDeferred2->Link();
|
||||
|
||||
//Water Pass
|
||||
m_SpWater = ResourceManager::Load<ShaderProgram>("Shaders/Deferred/water/");
|
||||
m_SpWater = ResourceManager::Load<ShaderProgram>("Shaders/OpenGL/Deferred/water/");
|
||||
m_SpWater->Link();
|
||||
m_SpWater2 = ResourceManager::Load<ShaderProgram>("Shaders/Deferred/water2/");
|
||||
m_SpWater2 = ResourceManager::Load<ShaderProgram>("Shaders/OpenGL/Deferred/water2/");
|
||||
m_SpWater2->Link();
|
||||
|
||||
// Pass #3: Combining into final image
|
||||
m_SpDeferred3 = ResourceManager::Load<ShaderProgram>("Shaders/Deferred/3/");
|
||||
m_SpDeferred3 = ResourceManager::Load<ShaderProgram>("Shaders/OpenGL/Deferred/3/");
|
||||
m_SpDeferred3->Link();
|
||||
|
||||
/*
|
||||
Forward rendering
|
||||
*/
|
||||
m_SpForward = ResourceManager::Load<ShaderProgram>("Shaders/Forward/");
|
||||
m_SpForward = ResourceManager::Load<ShaderProgram>("Shaders/OpenGL/Forward/");
|
||||
m_SpForward->Link();
|
||||
|
||||
/*
|
||||
Screen draw
|
||||
*/
|
||||
m_SpScreen = ResourceManager::Load<ShaderProgram>("Shaders/Screen/");
|
||||
m_SpScreen = ResourceManager::Load<ShaderProgram>("Shaders/OpenGL/Screen/");
|
||||
m_SpScreen->Link();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
This file is part of Daydream Engine.
|
||||
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
|
||||
|
||||
Daydream Engine is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Daydream Engine is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#version 440
|
||||
|
||||
layout (binding = 0) uniform sampler2D DiffuseTexture;
|
||||
layout (binding = 1) uniform sampler2D NormalMap;
|
||||
layout (binding = 2) uniform sampler2D SpecularMap;
|
||||
|
||||
uniform mat4 V;
|
||||
uniform float MaterialShininess;
|
||||
uniform vec4 Color;
|
||||
|
||||
in VertexData
|
||||
{
|
||||
vec3 Position;
|
||||
vec3 Normal;
|
||||
vec3 Tangent;
|
||||
vec3 BiTangent;
|
||||
vec2 TextureCoord;
|
||||
vec4 DiffuseColor;
|
||||
vec4 SpecularColor;
|
||||
vec4 BoneIndices1;
|
||||
vec4 BoneIndices2;
|
||||
vec4 BoneWeights1;
|
||||
vec4 BoneWeights2;
|
||||
} Input;
|
||||
|
||||
out vec4 GDiffuse;
|
||||
out vec4 GPosition;
|
||||
out vec4 GNormal;
|
||||
out vec4 GSpecular;
|
||||
|
||||
void main()
|
||||
{
|
||||
// Diffuse Texture
|
||||
GDiffuse = texture(DiffuseTexture, Input.TextureCoord) * Input.DiffuseColor;
|
||||
GDiffuse = GDiffuse * Color;
|
||||
|
||||
// G-buffer Position
|
||||
GPosition = vec4(Input.Position.xyz, 1.0);
|
||||
|
||||
// G-buffer Normal
|
||||
mat3 TBN = mat3(Input.Tangent, Input.BiTangent, Input.Normal);
|
||||
GNormal = normalize(vec4(TBN * vec3(texture(NormalMap, Input.TextureCoord)), 0.0));
|
||||
|
||||
// G-buffer Specular
|
||||
vec4 specularGloss = texture(SpecularMap, Input.TextureCoord);
|
||||
float specularExponent = MaterialShininess;
|
||||
GSpecular = vec4(specularGloss.rgb, specularExponent);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
This file is part of Daydream Engine.
|
||||
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
|
||||
|
||||
Daydream Engine is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Daydream Engine is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#version 440
|
||||
|
||||
uniform mat4 MVP;
|
||||
uniform mat4 M;
|
||||
uniform mat4 V;
|
||||
uniform mat4 P;
|
||||
uniform mat4 Bones[100];
|
||||
|
||||
layout (location = 0) in vec3 Position;
|
||||
layout (location = 1) in vec3 Normal;
|
||||
layout (location = 2) in vec3 Tangent;
|
||||
layout (location = 3) in vec3 BiTangent;
|
||||
layout (location = 4) in vec2 TextureCoord;
|
||||
layout (location = 5) in vec4 DiffuseColor;
|
||||
layout (location = 6) in vec4 SpecularColor;
|
||||
layout (location = 7) in vec4 BoneIndices1;
|
||||
layout (location = 8) in vec4 BoneIndices2;
|
||||
layout (location = 9) in vec4 BoneWeights1;
|
||||
layout (location = 10) in vec4 BoneWeights2;
|
||||
|
||||
out VertexData
|
||||
{
|
||||
vec3 Position;
|
||||
vec3 Normal;
|
||||
vec3 Tangent;
|
||||
vec3 BiTangent;
|
||||
vec2 TextureCoord;
|
||||
vec4 DiffuseColor;
|
||||
vec4 SpecularColor;
|
||||
vec4 BoneIndices1;
|
||||
vec4 BoneIndices2;
|
||||
vec4 BoneWeights1;
|
||||
vec4 BoneWeights2;
|
||||
} Output;
|
||||
|
||||
void main()
|
||||
{
|
||||
mat4 boneTransform = mat4(1);
|
||||
if (length(BoneWeights1 + BoneWeights2) > 0) {
|
||||
boneTransform = BoneWeights1[0] * Bones[int(BoneIndices1[0])]
|
||||
+ BoneWeights1[1] * Bones[int(BoneIndices1[1])]
|
||||
+ BoneWeights1[2] * Bones[int(BoneIndices1[2])]
|
||||
+ BoneWeights1[3] * Bones[int(BoneIndices1[3])]
|
||||
+ BoneWeights2[0] * Bones[int(BoneIndices2[0])]
|
||||
+ BoneWeights2[1] * Bones[int(BoneIndices2[1])]
|
||||
+ BoneWeights2[2] * Bones[int(BoneIndices2[2])]
|
||||
+ BoneWeights2[3] * Bones[int(BoneIndices2[3])];
|
||||
}
|
||||
|
||||
gl_Position = MVP * boneTransform * vec4(Position, 1.0);
|
||||
|
||||
Output.Position = (V * M * boneTransform * vec4(Position, 1.0)).xyz;
|
||||
Output.Normal = (inverse(transpose(V * M)) * boneTransform * vec4(Normal, 0.0)).xyz;
|
||||
Output.Tangent = Tangent;
|
||||
Output.BiTangent = BiTangent;
|
||||
Output.TextureCoord = TextureCoord;
|
||||
Output.DiffuseColor = DiffuseColor;
|
||||
Output.SpecularColor = SpecularColor;
|
||||
Output.BoneIndices1 = BoneIndices1;
|
||||
Output.BoneIndices2 = BoneIndices2;
|
||||
Output.BoneWeights1 = BoneWeights1;
|
||||
Output.BoneWeights2 = BoneWeights2;
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
This file is part of Daydream Engine.
|
||||
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
|
||||
|
||||
Daydream Engine is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Daydream Engine is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#version 440
|
||||
|
||||
layout (binding=0) uniform sampler2D PositionTexture;
|
||||
layout (binding=1) uniform sampler2D NormalTexture;
|
||||
layout (binding=2) uniform sampler2D SpecularTexture;
|
||||
|
||||
uniform vec2 ViewportSize;
|
||||
uniform mat4 MVP;
|
||||
uniform mat4 M;
|
||||
uniform mat4 V;
|
||||
uniform mat4 P;
|
||||
uniform vec3 LightPosition;
|
||||
uniform float LightRadius;
|
||||
uniform vec3 LightSpecular;
|
||||
uniform vec3 LightDiffuse;
|
||||
|
||||
out vec4 FragmentColor;
|
||||
|
||||
vec4 phong(vec3 position, vec3 normal, vec3 specular, float specularExponent)
|
||||
{
|
||||
// Diffuse
|
||||
vec3 lightPos = vec3(V * vec4(LightPosition, 1.0));
|
||||
vec3 distanceToLight = lightPos - position;
|
||||
vec3 directionToLight = normalize(distanceToLight);
|
||||
float dotProd = dot(directionToLight, normal);
|
||||
dotProd = max(dotProd, 0.0);
|
||||
vec3 Idiffuse = LightDiffuse * dotProd;
|
||||
|
||||
// Specular
|
||||
//vec3 reflection = reflect(-directionToLight, normal);
|
||||
vec3 surfaceToViewer = normalize(-position);
|
||||
vec3 halfWay = normalize(surfaceToViewer + directionToLight);
|
||||
float dotSpecular = max(dot(halfWay, normal), 0.0);
|
||||
float specularFactor = pow(dotSpecular, specularExponent);
|
||||
vec3 Ispecular = specular * LightSpecular * specularFactor;
|
||||
|
||||
//Attenuation
|
||||
float dist = distance(lightPos, position);
|
||||
//float attenuation = 1.0 - pow(dist / LightRadius, 2);
|
||||
float attenuation = pow(max(0.0f, 1.0 - (dist / LightRadius)), 2);
|
||||
|
||||
return vec4((Idiffuse + Ispecular) * attenuation, 1.0);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 TextureCoord = gl_FragCoord.xy / ViewportSize;
|
||||
vec4 PositionTexel = texture(PositionTexture, TextureCoord);
|
||||
vec4 NormalTexel = texture(NormalTexture, TextureCoord);
|
||||
vec4 SpecularTexel = texture(SpecularTexture, TextureCoord);
|
||||
|
||||
FragmentColor = phong(PositionTexel.xyz, normalize(NormalTexel.xyz), SpecularTexel.rgb, SpecularTexel.a);
|
||||
//FragmentColor = vec4(1, 1, 1, 1);
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
This file is part of Daydream Engine.
|
||||
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
|
||||
|
||||
Daydream Engine is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Daydream Engine is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#version 440
|
||||
|
||||
uniform mat4 MVP;
|
||||
|
||||
layout (location = 0) in vec3 Position;
|
||||
|
||||
out VertexData
|
||||
{
|
||||
vec3 Position;
|
||||
vec2 TextureCoord;
|
||||
} Output;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = MVP * vec4(Position, 1.0);
|
||||
Output.Position = Position;
|
||||
Output.TextureCoord = (vec2(Position) + 1.0) / 2.0;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
This file is part of Daydream Engine.
|
||||
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
|
||||
|
||||
Daydream Engine is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Daydream Engine is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#version 440
|
||||
|
||||
uniform vec3 La;
|
||||
|
||||
layout (binding=0) uniform sampler2D DiffuseTexture;
|
||||
layout (binding=1) uniform sampler2D LightingTexture;
|
||||
|
||||
in VertexData
|
||||
{
|
||||
vec3 Position;
|
||||
vec2 TextureCoord;
|
||||
} Input;
|
||||
|
||||
out vec4 frag_Diffuse;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 DiffuseTexel = texture(DiffuseTexture, Input.TextureCoord);
|
||||
vec4 LightingTexel = texture(LightingTexture, Input.TextureCoord);
|
||||
|
||||
//frag_Diffuse = DiffuseTexel * (vec4(La, 0.0) * (vec4(LightingTexel.rgb, 0.0) + vec4(LightingTexel.a, LightingTexel.a, LightingTexel.a, 0.0)));
|
||||
//frag_Diffuse = DiffuseTexel * (vec4(La, 0.0) + LightingTexel);
|
||||
//frag_Diffuse = DiffuseTexel * (vec4(1.f, 1.f, 1.f, 0.0) + LightingTexel);
|
||||
frag_Diffuse = DiffuseTexel + LightingTexel;
|
||||
//frag_Diffuse = DiffuseTexel;
|
||||
//frag_Diffuse = vec4(LightingTexel.r, LightingTexel.g, LightingTexel.b, 1.0);
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
This file is part of Daydream Engine.
|
||||
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
|
||||
|
||||
Daydream Engine is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Daydream Engine is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#version 440
|
||||
|
||||
layout (location = 0) in vec3 Position;
|
||||
|
||||
out VertexData
|
||||
{
|
||||
vec3 Position;
|
||||
vec2 TextureCoord;
|
||||
} Output;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(Position, 1.0);
|
||||
Output.Position = Position;
|
||||
Output.TextureCoord = (vec2(Position) + 1) / 2;
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
This file is part of Daydream Engine.
|
||||
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
|
||||
|
||||
Daydream Engine is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Daydream Engine is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#version 440
|
||||
|
||||
layout (binding=0) uniform sampler2D DiffuseTexture;
|
||||
layout (binding=1) uniform sampler2D NormalMap;
|
||||
layout (binding=2) uniform sampler2D SpecularMap;
|
||||
|
||||
uniform mat4 MVP;
|
||||
uniform mat4 M;
|
||||
uniform mat4 V;
|
||||
uniform mat4 P;
|
||||
uniform vec3 LightPosition;
|
||||
uniform float LightRadius;
|
||||
uniform vec3 LightSpecular;
|
||||
uniform vec3 LightDiffuse;
|
||||
|
||||
in VertexData
|
||||
{
|
||||
vec3 Position;
|
||||
vec3 Normal;
|
||||
vec3 Tangent;
|
||||
vec3 BiTangent;
|
||||
vec2 TextureCoord;
|
||||
vec4 DiffuseColor;
|
||||
vec4 SpecularColor;
|
||||
vec4 BoneIndices1;
|
||||
vec4 BoneIndices2;
|
||||
vec4 BoneWeights1;
|
||||
vec4 BoneWeights2;
|
||||
} Input;
|
||||
|
||||
out vec4 frag_Diffuse;
|
||||
|
||||
vec4 phong(vec3 position, vec3 normal, vec3 specular, float specularExponent)
|
||||
{
|
||||
// Diffuse
|
||||
vec3 lightPos = vec3(V * vec4(LightPosition, 1.0));
|
||||
vec3 distanceToLight = lightPos - position;
|
||||
vec3 directionToLight = normalize(distanceToLight);
|
||||
float dotProd = dot(directionToLight, normal);
|
||||
dotProd = max(dotProd, 0.0);
|
||||
vec3 Idiffuse = LightDiffuse * dotProd;
|
||||
|
||||
// Specular
|
||||
//vec3 reflection = reflect(-directionToLight, normal);
|
||||
vec3 surfaceToViewer = normalize(-position);
|
||||
vec3 halfWay = normalize(surfaceToViewer + directionToLight);
|
||||
float dotSpecular = max(dot(halfWay, normal), 0.0);
|
||||
float specularFactor = pow(dotSpecular, specularExponent);
|
||||
vec3 Ispecular = specular * LightSpecular * specularFactor;
|
||||
|
||||
//Attenuation
|
||||
float dist = distance(lightPos, position);
|
||||
//float attenuation = 1.0 - pow(dist / LightRadius, 2);
|
||||
float attenuation = pow(max(0.0f, 1.0 - (dist / LightRadius)), 2);
|
||||
|
||||
return vec4((Idiffuse + Ispecular) * attenuation, 1.0);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 normalTexel = texture(NormalMap, Input.TextureCoord);
|
||||
mat3 TBN = mat3(Input.Tangent, Input.BiTangent, Input.Normal);
|
||||
vec3 normal = normalize(vec4(TBN * normalTexel.xyz, 0.0).xyz);
|
||||
|
||||
vec4 specularTexel = texture(SpecularMap, Input.TextureCoord);
|
||||
|
||||
vec4 diffuseTexel = texture(DiffuseTexture, Input.TextureCoord);
|
||||
vec4 La = vec4(0.3, 0.3, 0.3, 1.0);
|
||||
vec4 light = phong(Input.Position, normalize(normal), specularTexel.rgb, specularTexel.a);
|
||||
//frag_Diffuse = light;
|
||||
frag_Diffuse = diffuseTexel;
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
This file is part of Daydream Engine.
|
||||
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
|
||||
|
||||
Daydream Engine is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Daydream Engine is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#version 440
|
||||
|
||||
uniform mat4 MVP;
|
||||
uniform mat4 M;
|
||||
uniform mat4 V;
|
||||
uniform mat4 P;
|
||||
uniform mat4 Bones[100];
|
||||
|
||||
layout (location = 0) in vec3 Position;
|
||||
layout (location = 1) in vec3 Normal;
|
||||
layout (location = 2) in vec3 Tangent;
|
||||
layout (location = 3) in vec3 BiTangent;
|
||||
layout (location = 4) in vec2 TextureCoord;
|
||||
layout (location = 5) in vec4 DiffuseColor;
|
||||
layout (location = 6) in vec4 SpecularColor;
|
||||
layout (location = 7) in vec4 BoneIndices1;
|
||||
layout (location = 8) in vec4 BoneIndices2;
|
||||
layout (location = 9) in vec4 BoneWeights1;
|
||||
layout (location = 10) in vec4 BoneWeights2;
|
||||
|
||||
out VertexData
|
||||
{
|
||||
vec3 Position;
|
||||
vec3 Normal;
|
||||
vec3 Tangent;
|
||||
vec3 BiTangent;
|
||||
vec2 TextureCoord;
|
||||
vec4 DiffuseColor;
|
||||
vec4 SpecularColor;
|
||||
vec4 BoneIndices1;
|
||||
vec4 BoneIndices2;
|
||||
vec4 BoneWeights1;
|
||||
vec4 BoneWeights2;
|
||||
} Output;
|
||||
|
||||
void main()
|
||||
{
|
||||
mat4 boneTransform = mat4(1);
|
||||
if (length(BoneWeights1 + BoneWeights2) > 0) {
|
||||
boneTransform = BoneWeights1[0] * Bones[int(BoneIndices1[0])]
|
||||
+ BoneWeights1[1] * Bones[int(BoneIndices1[1])]
|
||||
+ BoneWeights1[2] * Bones[int(BoneIndices1[2])]
|
||||
+ BoneWeights1[3] * Bones[int(BoneIndices1[3])]
|
||||
+ BoneWeights2[0] * Bones[int(BoneIndices2[0])]
|
||||
+ BoneWeights2[1] * Bones[int(BoneIndices2[1])]
|
||||
+ BoneWeights2[2] * Bones[int(BoneIndices2[2])]
|
||||
+ BoneWeights2[3] * Bones[int(BoneIndices2[3])];
|
||||
}
|
||||
|
||||
//gl_Position = MVP * boneTransform * vec4(Position, 1.0);
|
||||
gl_Position = MVP * vec4(Position, 1.0);
|
||||
|
||||
//TODO: Make sure that boneTransform works here.
|
||||
Output.Position = (V * M * boneTransform * vec4(Position, 1.0)).xyz;
|
||||
Output.Normal = (inverse(transpose(V * M)) * boneTransform * vec4(Normal, 0.0)).xyz;
|
||||
Output.Tangent = Tangent;
|
||||
Output.BiTangent = BiTangent;
|
||||
Output.TextureCoord = TextureCoord;
|
||||
Output.DiffuseColor = DiffuseColor;
|
||||
Output.SpecularColor = SpecularColor;
|
||||
Output.BoneIndices1 = BoneIndices1;
|
||||
Output.BoneIndices2 = BoneIndices2;
|
||||
Output.BoneWeights1 = BoneWeights1;
|
||||
Output.BoneWeights2 = BoneWeights2;
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
This file is part of Daydream Engine.
|
||||
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
|
||||
|
||||
Daydream Engine is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Daydream Engine is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#version 440
|
||||
|
||||
uniform vec2 dir;
|
||||
uniform float res;
|
||||
uniform float radius;
|
||||
|
||||
layout (binding=0) uniform sampler2D WaterTexture;
|
||||
|
||||
in VertexData
|
||||
{
|
||||
vec3 Position;
|
||||
vec2 TextureCoord;
|
||||
} Input;
|
||||
|
||||
out vec4 frag_Diffuse;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 WaterTexel = texture(WaterTexture, Input.TextureCoord);
|
||||
|
||||
vec4 sum = vec4(0.0);
|
||||
vec2 tc = Input.TextureCoord;
|
||||
|
||||
//How much blur, 1 = blur by one pixel.
|
||||
float blur = radius/res;
|
||||
|
||||
float hstep = dir.x;
|
||||
float vstep = dir.y;
|
||||
|
||||
float Threshhold = 0.1;
|
||||
|
||||
//apply filter using a 9 tap filter with predefined gaussian weights
|
||||
|
||||
sum += texture(WaterTexture, vec2(tc.x - 4.0*blur*hstep, tc.y - 4.0*blur*vstep)) * 0.0162162162;
|
||||
sum += texture(WaterTexture, vec2(tc.x - 3.0*blur*hstep, tc.y - 3.0*blur*vstep)) * 0.0540540541;
|
||||
sum += texture(WaterTexture, vec2(tc.x - 2.0*blur*hstep, tc.y - 2.0*blur*vstep)) * 0.1216216216;
|
||||
sum += texture(WaterTexture, vec2(tc.x - 1.0*blur*hstep, tc.y - 1.0*blur*vstep)) * 0.1945945946;
|
||||
|
||||
sum += texture(WaterTexture, vec2(tc.x, tc.y)) * 0.2270270270;
|
||||
|
||||
sum += texture(WaterTexture, vec2(tc.x + 1.0*blur*hstep, tc.y + 1.0*blur*vstep)) * 0.1945945946;
|
||||
sum += texture(WaterTexture, vec2(tc.x + 2.0*blur*hstep, tc.y + 2.0*blur*vstep)) * 0.1216216216;
|
||||
sum += texture(WaterTexture, vec2(tc.x + 3.0*blur*hstep, tc.y + 3.0*blur*vstep)) * 0.0540540541;
|
||||
sum += texture(WaterTexture, vec2(tc.x + 4.0*blur*hstep, tc.y + 4.0*blur*vstep)) * 0.0162162162;
|
||||
|
||||
float avgColor = sum.r + sum.g + sum.b;
|
||||
avgColor = avgColor/3;
|
||||
frag_Diffuse = vec4(sum.r, sum.g, sum.b, 1.0);
|
||||
if ( avgColor*dir.y > Threshhold ){
|
||||
frag_Diffuse = vec4(0.0, 0.3, 1.0, 1.0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
This file is part of Daydream Engine.
|
||||
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
|
||||
|
||||
Daydream Engine is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Daydream Engine is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#version 440
|
||||
|
||||
layout (location = 0) in vec3 Position;
|
||||
|
||||
out VertexData
|
||||
{
|
||||
vec3 Position;
|
||||
vec2 TextureCoord;
|
||||
} Output;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(Position, 1.0);
|
||||
Output.Position = Position;
|
||||
Output.TextureCoord = (vec2(Position) + 1) / 2;
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
This file is part of Daydream Engine.
|
||||
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
|
||||
|
||||
Daydream Engine is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Daydream Engine is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#version 440
|
||||
|
||||
layout (binding=0) uniform sampler2D DiffuseTexture;
|
||||
layout (binding=1) uniform sampler2D NormalMap;
|
||||
layout (binding=2) uniform sampler2D SpecularMap;
|
||||
|
||||
uniform mat4 MVP;
|
||||
uniform mat4 M;
|
||||
uniform mat4 V;
|
||||
uniform mat4 P;
|
||||
uniform vec3 LightPosition;
|
||||
uniform float LightRadius;
|
||||
uniform vec3 LightSpecular;
|
||||
uniform vec3 LightDiffuse;
|
||||
uniform vec4 Color;
|
||||
|
||||
in VertexData
|
||||
{
|
||||
vec3 Position;
|
||||
vec3 Normal;
|
||||
vec3 Tangent;
|
||||
vec3 BiTangent;
|
||||
vec2 TextureCoord;
|
||||
vec4 DiffuseColor;
|
||||
vec4 SpecularColor;
|
||||
vec4 BoneIndices1;
|
||||
vec4 BoneIndices2;
|
||||
vec4 BoneWeights1;
|
||||
vec4 BoneWeights2;
|
||||
} Input;
|
||||
|
||||
out vec4 frag_Diffuse;
|
||||
|
||||
vec4 phong(vec3 position, vec3 normal, vec3 specular, float specularExponent)
|
||||
{
|
||||
// Diffuse
|
||||
vec3 lightPos = vec3(V * vec4(LightPosition, 1.0));
|
||||
vec3 distanceToLight = lightPos - position;
|
||||
vec3 directionToLight = normalize(distanceToLight);
|
||||
float dotProd = dot(directionToLight, normal);
|
||||
dotProd = max(dotProd, 0.0);
|
||||
vec3 Idiffuse = LightDiffuse * dotProd;
|
||||
|
||||
// Specular
|
||||
//vec3 reflection = reflect(-directionToLight, normal);
|
||||
vec3 surfaceToViewer = normalize(-position);
|
||||
vec3 halfWay = normalize(surfaceToViewer + directionToLight);
|
||||
float dotSpecular = max(dot(halfWay, normal), 0.0);
|
||||
float specularFactor = pow(dotSpecular, specularExponent);
|
||||
vec3 Ispecular = specular * LightSpecular * specularFactor;
|
||||
|
||||
//Attenuation
|
||||
float dist = distance(lightPos, position);
|
||||
//float attenuation = 1.0 - pow(dist / LightRadius, 2);
|
||||
float attenuation = pow(max(0.0f, 1.0 - (dist / LightRadius)), 2);
|
||||
|
||||
return vec4((Idiffuse + Ispecular) * attenuation, 1.0);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 normalTexel = texture(NormalMap, Input.TextureCoord);
|
||||
mat3 TBN = mat3(Input.Tangent, Input.BiTangent, Input.Normal);
|
||||
vec3 normal = normalize(vec4(TBN * normalTexel.xyz, 0.0).xyz);
|
||||
|
||||
vec4 specularTexel = texture(SpecularMap, Input.TextureCoord);
|
||||
|
||||
vec4 diffuseTexel = texture(DiffuseTexture, Input.TextureCoord);
|
||||
vec4 La = vec4(0.3, 0.3, 0.3, 1.0);
|
||||
vec4 light = phong(Input.Position, normalize(normal), specularTexel.rgb, specularTexel.a);
|
||||
//frag_Diffuse = light;
|
||||
frag_Diffuse = diffuseTexel * Color;
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
This file is part of Daydream Engine.
|
||||
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
|
||||
|
||||
Daydream Engine is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Daydream Engine is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#version 440
|
||||
|
||||
uniform mat4 MVP;
|
||||
uniform mat4 M;
|
||||
uniform mat4 V;
|
||||
uniform mat4 P;
|
||||
uniform mat4 Bones[100];
|
||||
|
||||
layout (location = 0) in vec3 Position;
|
||||
layout (location = 1) in vec3 Normal;
|
||||
layout (location = 2) in vec3 Tangent;
|
||||
layout (location = 3) in vec3 BiTangent;
|
||||
layout (location = 4) in vec2 TextureCoord;
|
||||
layout (location = 5) in vec4 DiffuseColor;
|
||||
layout (location = 6) in vec4 SpecularColor;
|
||||
layout (location = 7) in vec4 BoneIndices1;
|
||||
layout (location = 8) in vec4 BoneIndices2;
|
||||
layout (location = 9) in vec4 BoneWeights1;
|
||||
layout (location = 10) in vec4 BoneWeights2;
|
||||
|
||||
out VertexData
|
||||
{
|
||||
vec3 Position;
|
||||
vec3 Normal;
|
||||
vec3 Tangent;
|
||||
vec3 BiTangent;
|
||||
vec2 TextureCoord;
|
||||
vec4 DiffuseColor;
|
||||
vec4 SpecularColor;
|
||||
vec4 BoneIndices1;
|
||||
vec4 BoneIndices2;
|
||||
vec4 BoneWeights1;
|
||||
vec4 BoneWeights2;
|
||||
} Output;
|
||||
|
||||
void main()
|
||||
{
|
||||
mat4 boneTransform = mat4(1);
|
||||
if (length(BoneWeights1 + BoneWeights2) > 0) {
|
||||
boneTransform = BoneWeights1[0] * Bones[int(BoneIndices1[0])]
|
||||
+ BoneWeights1[1] * Bones[int(BoneIndices1[1])]
|
||||
+ BoneWeights1[2] * Bones[int(BoneIndices1[2])]
|
||||
+ BoneWeights1[3] * Bones[int(BoneIndices1[3])]
|
||||
+ BoneWeights2[0] * Bones[int(BoneIndices2[0])]
|
||||
+ BoneWeights2[1] * Bones[int(BoneIndices2[1])]
|
||||
+ BoneWeights2[2] * Bones[int(BoneIndices2[2])]
|
||||
+ BoneWeights2[3] * Bones[int(BoneIndices2[3])];
|
||||
}
|
||||
|
||||
gl_Position = MVP * boneTransform * vec4(Position, 1.0);
|
||||
//gl_Position = MVP * vec4(Position, 1.0);
|
||||
|
||||
//TODO: Make sure that boneTransform works here.
|
||||
Output.Position = (V * M * boneTransform * vec4(Position, 1.0)).xyz;
|
||||
Output.Normal = (inverse(transpose(V * M)) * boneTransform * vec4(Normal, 0.0)).xyz;
|
||||
Output.Tangent = Tangent;
|
||||
Output.BiTangent = BiTangent;
|
||||
Output.TextureCoord = TextureCoord;
|
||||
Output.DiffuseColor = DiffuseColor;
|
||||
Output.SpecularColor = SpecularColor;
|
||||
Output.BoneIndices1 = BoneIndices1;
|
||||
Output.BoneIndices2 = BoneIndices2;
|
||||
Output.BoneWeights1 = BoneWeights1;
|
||||
Output.BoneWeights2 = BoneWeights2;
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
This file is part of Daydream Engine.
|
||||
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
|
||||
|
||||
Daydream Engine is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Daydream Engine is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#version 440
|
||||
|
||||
layout (binding=0) uniform sampler2D DiffuseTexture;
|
||||
layout (binding=1) uniform sampler2D NormalMap;
|
||||
layout (binding=2) uniform sampler2D SpecularMap;
|
||||
|
||||
uniform mat4 MVP;
|
||||
uniform mat4 M;
|
||||
uniform mat4 V;
|
||||
uniform mat4 P;
|
||||
uniform vec3 LightPosition;
|
||||
uniform float LightRadius;
|
||||
uniform vec3 LightSpecular;
|
||||
uniform vec3 LightDiffuse;
|
||||
|
||||
in VertexData
|
||||
{
|
||||
vec3 Position;
|
||||
vec3 Normal;
|
||||
vec3 Tangent;
|
||||
vec3 BiTangent;
|
||||
vec2 TextureCoord;
|
||||
vec4 DiffuseColor;
|
||||
vec4 SpecularColor;
|
||||
vec4 BoneIndices1;
|
||||
vec4 BoneIndices2;
|
||||
vec4 BoneWeights1;
|
||||
vec4 BoneWeights2;
|
||||
} Input;
|
||||
|
||||
out vec4 frag_Diffuse;
|
||||
|
||||
vec4 phong(vec3 position, vec3 normal, vec3 specular, float specularExponent)
|
||||
{
|
||||
// Diffuse
|
||||
vec3 lightPos = vec3(V * vec4(LightPosition, 1.0));
|
||||
vec3 distanceToLight = lightPos - position;
|
||||
vec3 directionToLight = normalize(distanceToLight);
|
||||
float dotProd = dot(directionToLight, normal);
|
||||
dotProd = max(dotProd, 0.0);
|
||||
vec3 Idiffuse = LightDiffuse * dotProd;
|
||||
|
||||
// Specular
|
||||
//vec3 reflection = reflect(-directionToLight, normal);
|
||||
vec3 surfaceToViewer = normalize(-position);
|
||||
vec3 halfWay = normalize(surfaceToViewer + directionToLight);
|
||||
float dotSpecular = max(dot(halfWay, normal), 0.0);
|
||||
float specularFactor = pow(dotSpecular, specularExponent);
|
||||
vec3 Ispecular = specular * LightSpecular * specularFactor;
|
||||
|
||||
//Attenuation
|
||||
float dist = distance(lightPos, position);
|
||||
//float attenuation = 1.0 - pow(dist / LightRadius, 2);
|
||||
float attenuation = pow(max(0.0f, 1.0 - (dist / LightRadius)), 2);
|
||||
|
||||
return vec4((Idiffuse + Ispecular) * attenuation, 1.0);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 normalTexel = texture(NormalMap, Input.TextureCoord);
|
||||
mat3 TBN = mat3(Input.Tangent, Input.BiTangent, Input.Normal);
|
||||
vec3 normal = normalize(vec4(TBN * normalTexel.xyz, 0.0).xyz);
|
||||
|
||||
vec4 specularTexel = texture(SpecularMap, Input.TextureCoord);
|
||||
|
||||
vec4 diffuseTexel = texture(DiffuseTexture, Input.TextureCoord);
|
||||
|
||||
//frag_Diffuse = phong(Input.Position, normalize(normal), specularTexel.rgb, specularTexel.a);
|
||||
frag_Diffuse = diffuseTexel;
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
This file is part of Daydream Engine.
|
||||
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
|
||||
|
||||
Daydream Engine is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Daydream Engine is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#version 440
|
||||
|
||||
uniform mat4 MVP;
|
||||
uniform mat4 M;
|
||||
uniform mat4 V;
|
||||
uniform mat4 P;
|
||||
uniform mat4 Bones[100];
|
||||
|
||||
layout (location = 0) in vec3 Position;
|
||||
layout (location = 1) in vec3 Normal;
|
||||
layout (location = 2) in vec3 Tangent;
|
||||
layout (location = 3) in vec3 BiTangent;
|
||||
layout (location = 4) in vec2 TextureCoord;
|
||||
layout (location = 5) in vec4 DiffuseColor;
|
||||
layout (location = 6) in vec4 SpecularColor;
|
||||
layout (location = 7) in vec4 BoneIndices1;
|
||||
layout (location = 8) in vec4 BoneIndices2;
|
||||
layout (location = 9) in vec4 BoneWeights1;
|
||||
layout (location = 10) in vec4 BoneWeights2;
|
||||
|
||||
out VertexData
|
||||
{
|
||||
vec3 Position;
|
||||
vec3 Normal;
|
||||
vec3 Tangent;
|
||||
vec3 BiTangent;
|
||||
vec2 TextureCoord;
|
||||
vec4 DiffuseColor;
|
||||
vec4 SpecularColor;
|
||||
vec4 BoneIndices1;
|
||||
vec4 BoneIndices2;
|
||||
vec4 BoneWeights1;
|
||||
vec4 BoneWeights2;
|
||||
} Output;
|
||||
|
||||
void main()
|
||||
{
|
||||
mat4 boneTransform = mat4(1);
|
||||
if (length(BoneWeights1 + BoneWeights2) > 0) {
|
||||
boneTransform = BoneWeights1[0] * Bones[int(BoneIndices1[0])]
|
||||
+ BoneWeights1[1] * Bones[int(BoneIndices1[1])]
|
||||
+ BoneWeights1[2] * Bones[int(BoneIndices1[2])]
|
||||
+ BoneWeights1[3] * Bones[int(BoneIndices1[3])]
|
||||
+ BoneWeights2[0] * Bones[int(BoneIndices2[0])]
|
||||
+ BoneWeights2[1] * Bones[int(BoneIndices2[1])]
|
||||
+ BoneWeights2[2] * Bones[int(BoneIndices2[2])]
|
||||
+ BoneWeights2[3] * Bones[int(BoneIndices2[3])];
|
||||
}
|
||||
|
||||
//gl_Position = MVP * boneTransform * vec4(Position, 1.0);
|
||||
gl_Position = MVP * vec4(Position, 1.0);
|
||||
|
||||
//TODO: Make sure that boneTransform works here.
|
||||
Output.Position = (V * M * boneTransform * vec4(Position, 1.0)).xyz;
|
||||
Output.Normal = (inverse(transpose(V * M)) * boneTransform * vec4(Normal, 0.0)).xyz;
|
||||
Output.Tangent = Tangent;
|
||||
Output.BiTangent = BiTangent;
|
||||
Output.TextureCoord = TextureCoord;
|
||||
Output.DiffuseColor = DiffuseColor;
|
||||
Output.SpecularColor = SpecularColor;
|
||||
Output.BoneIndices1 = BoneIndices1;
|
||||
Output.BoneIndices2 = BoneIndices2;
|
||||
Output.BoneWeights1 = BoneWeights1;
|
||||
Output.BoneWeights2 = BoneWeights2;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
This file is part of Daydream Engine.
|
||||
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
|
||||
|
||||
Daydream Engine is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Daydream Engine is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#version 440
|
||||
|
||||
layout (binding=0) uniform sampler2D DiffuseTexture;
|
||||
|
||||
uniform vec4 Color;
|
||||
|
||||
in vec2 TextureCoord;
|
||||
|
||||
out vec4 FragmentColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragmentColor = texture(DiffuseTexture, TextureCoord) * Color;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
This file is part of Daydream Engine.
|
||||
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
|
||||
|
||||
Daydream Engine is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Daydream Engine is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#version 440
|
||||
|
||||
layout (location = 0) in vec3 Position;
|
||||
|
||||
out vec2 TextureCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(Position, 1.0);
|
||||
TextureCoord = (vec2(Position) + 1.0) / 2.0;
|
||||
}
|
||||
Reference in New Issue
Block a user