Compare commits
No commits in common. "main" and "e5d4371a09725b18fedbf0826add77c8bc0f5fcb" have entirely different histories.
main
...
e5d4371a09
|
@ -360,7 +360,4 @@ MigrationBackup/
|
|||
.ionide/
|
||||
|
||||
# Fody - auto-generated XML schema
|
||||
FodyWeavers.xsd
|
||||
/Exp2/ClassDiagram.cd
|
||||
/ToyEngine/ClassDiagram1.cd
|
||||
/ToyEngine/ClassDiagram.cd
|
||||
FodyWeavers.xsd
|
|
@ -1,8 +0,0 @@
|
|||
#include <MainWindow.h>
|
||||
#include "DemoWorld.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
MainWindow::instance().initialize();
|
||||
return MainWindow::instance().exec(std::make_unique<DemoWorld>());
|
||||
}
|
|
@ -1,156 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>16.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectGuid>{02eea281-f0a1-4be3-b833-5a9b4150f6b0}</ProjectGuid>
|
||||
<RootNamespace>Demo</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
<LanguageStandard_C>stdc17</LanguageStandard_C>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)ToyEngine\include;$(SolutionDir)ToyEngine\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
<LanguageStandard_C>stdc17</LanguageStandard_C>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)ToyEngine\include;$(SolutionDir)ToyEngine\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
<LanguageStandard_C>stdc17</LanguageStandard_C>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)ToyEngine\include;$(SolutionDir)ToyEngine\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
<LanguageStandard_C>stdc17</LanguageStandard_C>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)ToyEngine\include;$(SolutionDir)ToyEngine\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Demo.cpp" />
|
||||
<ClCompile Include="DemoWorld.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ToyEngine\ToyEngine.vcxproj">
|
||||
<Project>{65d6ee2b-fffa-4ef6-8042-9ca7a0f8e67e}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="DemoWorld.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
|
@ -1,30 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="源文件">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="头文件">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="资源文件">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Demo.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="DemoWorld.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="DemoWorld.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -1,168 +0,0 @@
|
|||
#include "DemoWorld.h"
|
||||
#include <Particle.h>
|
||||
#include <RenderingSystem.h>
|
||||
|
||||
DemoWorld::DemoWorld()
|
||||
{
|
||||
light.lightDirection = glm::normalize(glm::vec3((cos(lightPitch) * cos(lightYaw)), (sin(lightPitch)), (cos(lightPitch) * sin(lightYaw))));
|
||||
light.radiance = 15.f * lightColor;
|
||||
|
||||
std::string modelFilePath;
|
||||
modelFilePath = "Models/vampire/vampire.gltf";
|
||||
|
||||
auto actor = std::make_shared<Actor>(modelFilePath);
|
||||
actor->setRotaion(glm::angleAxis(glm::radians(-90.f), glm::vec3(1, 0, 0)));
|
||||
auto actor2 = std::make_shared<Actor>(modelFilePath);
|
||||
actor2->setRotaion(glm::angleAxis(glm::radians(-90.f), glm::vec3(1, 0, 0)));
|
||||
actor2->setPosition({ 1,0,-1 });
|
||||
auto actor3 = std::make_shared<Actor>(modelFilePath);
|
||||
actor3->setRotaion(glm::angleAxis(glm::radians(-90.f), glm::vec3(1, 0, 0)));
|
||||
actor3->setPosition({ -1,0,-1 });
|
||||
auto sponza = std::make_shared<Actor>("Models\\Sponza\\Sponza.gltf");
|
||||
sponza->setScale(glm::vec3(2));
|
||||
auto shoot = std::make_shared<Actor>("Models\\shoot_gun\\scene.gltf");
|
||||
shoot->setPosition({ 0.25,6.8,7.8 });
|
||||
shoot->setRotaion(glm::angleAxis(glm::radians(90.f), glm::vec3(0, 1, 0)));
|
||||
shoot->setScale(glm::vec3(45));
|
||||
|
||||
throwPerson = std::make_shared<Actor>("Models\\grenade_throw\\grenade_throw.gltf");
|
||||
throwPerson->setPosition({ 0.25,6.8,-8.1 });
|
||||
//throwPerson->setRotaion(glm::angleAxis(glm::radians(90.f), glm::vec3(0, 1, 0)));
|
||||
throwPerson->setScale(glm::vec3{ 45 });
|
||||
|
||||
mk2 = std::make_shared<Particle>(10, "Models\\mk2-frag-grenade\\mk2-frag-grenade.gltf");
|
||||
mk2->setScale(glm::vec3(0.1));
|
||||
mk2->setPosition({ 0,-100,0 });
|
||||
|
||||
addActor(actor);
|
||||
addActor(actor2);
|
||||
addActor(actor3);
|
||||
addActor(sponza);
|
||||
addActor(shoot);
|
||||
addActor(throwPerson);
|
||||
addActor(mk2);
|
||||
|
||||
float boardMass = 10;
|
||||
glm::vec3 boardScale(0.01);
|
||||
auto boardFilePath = "Models\\pallet_wood\\pallet_wood.gltf";
|
||||
|
||||
|
||||
int particleCount = 5;
|
||||
for (int i = 0; i < particleCount; i++)
|
||||
{
|
||||
auto particle = std::make_shared<Particle>(boardMass, boardFilePath);
|
||||
particle->setPosition({ 0, 8, glm::mix(-3.1f,2.f,(double)i / (particleCount - 1)) });
|
||||
particle->setScale(boardScale);
|
||||
if (i == 0 || i == particleCount - 1)
|
||||
{
|
||||
particle->setFixed(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
particle->setEnableGravity(true);
|
||||
}
|
||||
particles.push_back(particle);
|
||||
addActor(particle);
|
||||
|
||||
if (i != 0)
|
||||
{
|
||||
float ks = 300, kd = 100;
|
||||
physicsManager.addSpring(particles[i - 1], particle, 0.005, ks, kd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DemoWorld::logicalTick(float deltaTime)
|
||||
{
|
||||
World::logicalTick(deltaTime);
|
||||
for (int i = 0; i < particles.size(); i++)
|
||||
{
|
||||
glm::vec3 d;
|
||||
if (i == 0)
|
||||
d = glm::normalize(particles[i + 1]->getPosition() - particles[i]->getPosition());
|
||||
else if (i == particles.size() - 1)
|
||||
d = glm::normalize(particles[i]->getPosition() - particles[i - 1]->getPosition());
|
||||
else
|
||||
{
|
||||
auto dL = particles[i + 1]->getPosition() - particles[i]->getPosition();
|
||||
auto dR = particles[i]->getPosition() - particles[i - 1]->getPosition();
|
||||
d = (glm::normalize(dL) + glm::normalize(dR)) / 2.f;
|
||||
}
|
||||
particles[i]->setRotaion(glm::rotation(glm::vec3(0, 0, 1), d));
|
||||
}
|
||||
|
||||
if (abs(throwPerson->getAnimatorCurrentTime() - 3.41f) < 1e-2f)
|
||||
{
|
||||
mk2->setPosition(throwPerson->getPosition() + glm::vec3(-0.5, 2.2, 0));
|
||||
mk2->setSpeed(glm::mat3_cast(throwPerson->getRotation() * glm::rotation(glm::vec3(1, 0, 0), glm::normalize(glm::vec3(0, 0.8, 1)/*方向*/))) * glm::vec3(8.3/*速度*/, 0, 0));
|
||||
//mk2->setSpeed(glm::mat3_cast(throwPerson->getRotation() * glm::rotation(glm::vec3(1, 0, 0), glm::normalize(glm::vec3(0, 2, 1)/*方向*/))) * glm::vec3(10/*速度*/, 0, 0));
|
||||
mk2->setEnableGravity(true);
|
||||
}
|
||||
|
||||
if (mk2->getPosition().y < 7.5f && mk2->getSpeed().y < 0)
|
||||
{
|
||||
particles[3]->setSpeed(particles[3]->getSpeed() + mk2->getSpeed() / 2.f);
|
||||
mk2->setEnableGravity(false);
|
||||
mk2->setSpeed(glm::vec3(0));
|
||||
mk2->setPosition({ 0,-100,0 });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void DemoWorld::rendererTick(float deltaTime)
|
||||
{
|
||||
World::rendererTick(deltaTime);
|
||||
}
|
||||
|
||||
void DemoWorld::cursorPosCallback(GLFWwindow* window, double xpos, double ypos)
|
||||
{
|
||||
static bool firstMouse = true;
|
||||
static float lastX;
|
||||
static float lastY;
|
||||
|
||||
float xoffset = xpos - lastX;
|
||||
float yoffset = lastY - ypos;
|
||||
|
||||
lastX = xpos;
|
||||
lastY = ypos;
|
||||
|
||||
if (firstMouse)
|
||||
{
|
||||
firstMouse = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_RIGHT) == GLFW_PRESS)
|
||||
camera.processMouseMovement(xoffset, yoffset);
|
||||
}
|
||||
|
||||
void DemoWorld::scrollCallback(GLFWwindow* window, double xoffset, double yoffset)
|
||||
{
|
||||
if (glfwGetKey(window, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS)
|
||||
lightPitch = glm::mod(lightPitch + yoffset / 100., glm::pi<double>());
|
||||
else if (glfwGetKey(window, GLFW_KEY_LEFT_ALT) == GLFW_PRESS)
|
||||
lightYaw = glm::mod(lightYaw + yoffset / 100., 2 * glm::pi<double>());
|
||||
else if (glfwGetKey(window, GLFW_KEY_R) == GLFW_PRESS)
|
||||
light.radiance = glm::clamp((light.radiance / lightColor).x + (float)yoffset, 0.f, 100.f) * lightColor;
|
||||
else if (glfwGetKey(window, GLFW_KEY_E) == GLFW_PRESS)
|
||||
RenderingSystem::instance().exposure = glm::clamp(RenderingSystem::instance().exposure + (float)yoffset*0.1f, 0.f, 2.f);
|
||||
else camera.processMouseScroll(yoffset);
|
||||
|
||||
light.lightDirection = glm::normalize(glm::vec3((cos(lightPitch) * cos(lightYaw)), (sin(lightPitch)), (cos(lightPitch) * sin(lightYaw))));
|
||||
}
|
||||
|
||||
void DemoWorld::processInput(GLFWwindow* window, float deltaTime)
|
||||
{
|
||||
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
||||
camera.processKeyboard(FORWARD, deltaTime);
|
||||
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
||||
camera.processKeyboard(BACKWARD, deltaTime);
|
||||
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS)
|
||||
camera.processKeyboard(LEFT, deltaTime);
|
||||
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)
|
||||
camera.processKeyboard(RIGHT, deltaTime);
|
||||
if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS)
|
||||
camera.processKeyboard(UP, deltaTime);
|
||||
if (glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS)
|
||||
camera.processKeyboard(DOWN, deltaTime);
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
#pragma once
|
||||
#include <World.h>
|
||||
|
||||
class DemoWorld : public World
|
||||
{
|
||||
public:
|
||||
DemoWorld();
|
||||
void logicalTick(float deltaTime) override;
|
||||
void rendererTick(float deltaTime) override;
|
||||
virtual void cursorPosCallback(GLFWwindow* window, double xpos, double ypos) override;
|
||||
virtual void scrollCallback(GLFWwindow* window, double xoffset, double yoffset) override;
|
||||
virtual void processInput(GLFWwindow* window, float deltaTime) override;
|
||||
|
||||
private:
|
||||
std::vector<std::shared_ptr<Particle>> particles;
|
||||
std::shared_ptr<Actor> throwPerson;
|
||||
std::shared_ptr<Particle> mk2;
|
||||
|
||||
glm::vec3 lightColor = glm::normalize(glm::vec3(0.7529, 0.7450, 0.6784));
|
||||
float lightYaw = glm::radians(80.f);
|
||||
float lightPitch = glm::radians(105.f);
|
||||
};
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
#version 450 core
|
||||
|
||||
layout (location = 4) out vec4 gDebug;
|
||||
|
||||
in vec2 TexCoords;
|
||||
in vec3 WorldPos;
|
||||
in vec3 Normal;
|
||||
|
||||
uniform vec3 color;
|
||||
|
||||
void main()
|
||||
{
|
||||
gDebug = vec4(color,1);
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
#version 330 core
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec3 aNormal;
|
||||
layout (location = 2) in vec2 aTexCoords;
|
||||
|
||||
out vec2 TexCoords;
|
||||
out vec3 WorldPos;
|
||||
out vec3 Normal;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
uniform mat4 projection;
|
||||
|
||||
void main()
|
||||
{
|
||||
TexCoords = aTexCoords;
|
||||
WorldPos = vec3(model * vec4(aPos, 1.0));
|
||||
Normal = mat3(model) * aNormal;
|
||||
|
||||
gl_Position = projection * view * vec4(WorldPos, 1.0);
|
||||
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
#version 450 core
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
in vec2 TexCoords;
|
||||
|
||||
uniform sampler2D gBaseColor;
|
||||
uniform sampler2D gDebug;
|
||||
uniform float exposure = 1;
|
||||
uniform bool showDebug = false;
|
||||
|
||||
vec3 ACESToneMapping(vec3 color)
|
||||
{
|
||||
const float A = 2.51;
|
||||
const float B = 0.03;
|
||||
const float C = 2.43;
|
||||
const float D = 0.59;
|
||||
const float E = 0.14;
|
||||
return (color * (A * color + B)) / (color * (C * color + D) + E);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 rgbm = texture(gBaseColor, TexCoords);
|
||||
vec4 debug = texture(gDebug, TexCoords);
|
||||
if(rgbm.a==0 && (showDebug ? debug.a==0 : true))
|
||||
{
|
||||
//FragColor = vec4(1,0,0,1);
|
||||
//return;
|
||||
discard;
|
||||
}
|
||||
vec3 color = 8 * rgbm.rgb * rgbm.a;
|
||||
|
||||
color *= exposure;
|
||||
color = ACESToneMapping(color);
|
||||
|
||||
//color = color / (color + vec3(1.0));
|
||||
color = pow(color, vec3(1.0/2.2));
|
||||
FragColor = vec4(color, 1.0);
|
||||
if(showDebug)
|
||||
FragColor = mix(FragColor, debug, debug.a);
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
#version 450 core
|
||||
uniform sampler2D texture_basecolor;
|
||||
uniform sampler2D texture_metallic_roughness;
|
||||
uniform sampler2D texture_normal;
|
||||
|
||||
uniform bool texture_basecolor_available = false;
|
||||
uniform bool texture_metallic_roughness_available = false;
|
||||
uniform bool texture_normal_available = false;
|
||||
|
||||
uniform vec3 baseColor;
|
||||
uniform vec2 metallicRoughness;
|
||||
|
||||
layout (location = 0) out vec4 gBaseColor;
|
||||
layout (location = 1) out vec3 gNormal;
|
||||
layout (location = 2) out vec3 gPosition;
|
||||
layout (location = 3) out vec2 gMetallicRoughness;
|
||||
layout (location = 4) out vec4 gDebug;
|
||||
|
||||
in vec2 TexCoords;
|
||||
in vec3 WorldPos;
|
||||
in vec3 Normal;
|
||||
|
||||
vec3 getNormalFromMap()
|
||||
{
|
||||
vec3 tangentNormal = texture(texture_normal, TexCoords).xyz * 2.0 - 1.0;
|
||||
|
||||
vec3 Q1 = dFdx(WorldPos);
|
||||
vec3 Q2 = dFdy(WorldPos);
|
||||
vec2 st1 = dFdx(TexCoords);
|
||||
vec2 st2 = dFdy(TexCoords);
|
||||
|
||||
vec3 N = normalize(Normal);
|
||||
vec3 T = normalize(Q1*st2.t - Q2*st1.t);
|
||||
vec3 B = -normalize(cross(N, T));
|
||||
mat3 TBN = mat3(T, B, N);
|
||||
|
||||
return normalize(TBN * tangentNormal);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
if(texture_basecolor_available)
|
||||
gBaseColor = texture(texture_basecolor, TexCoords);
|
||||
else
|
||||
gBaseColor = vec4(baseColor, 1);
|
||||
if(gBaseColor.a<0.4)
|
||||
discard;
|
||||
gPosition = WorldPos;
|
||||
if(texture_normal_available)
|
||||
gNormal = getNormalFromMap();
|
||||
else
|
||||
gNormal = Normal;
|
||||
if(!gl_FrontFacing)
|
||||
gNormal = -gNormal;
|
||||
if(texture_metallic_roughness_available)
|
||||
gMetallicRoughness = texture(texture_metallic_roughness, TexCoords).bg;
|
||||
else
|
||||
gMetallicRoughness = metallicRoughness;
|
||||
|
||||
gDebug = vec4(0);
|
||||
}
|
Before Width: | Height: | Size: 2.8 MiB |
Before Width: | Height: | Size: 2.4 MiB |
Before Width: | Height: | Size: 1.5 MiB |
Before Width: | Height: | Size: 35 MiB |
Before Width: | Height: | Size: 15 MiB |
Before Width: | Height: | Size: 48 MiB |
|
@ -1,820 +0,0 @@
|
|||
{
|
||||
"asset" : {
|
||||
"generator" : "Khronos glTF Blender I/O v3.4.50",
|
||||
"version" : "2.0"
|
||||
},
|
||||
"scene" : 0,
|
||||
"scenes" : [
|
||||
{
|
||||
"name" : "Scene",
|
||||
"nodes" : [
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
4,
|
||||
5,
|
||||
6,
|
||||
7,
|
||||
8
|
||||
]
|
||||
}
|
||||
],
|
||||
"nodes" : [
|
||||
{
|
||||
"mesh" : 0,
|
||||
"name" : "Body",
|
||||
"translation" : [
|
||||
0,
|
||||
-2.247850179672241,
|
||||
0
|
||||
]
|
||||
},
|
||||
{
|
||||
"mesh" : 1,
|
||||
"name" : "Fuze",
|
||||
"translation" : [
|
||||
0,
|
||||
-2.247850179672241,
|
||||
0
|
||||
]
|
||||
},
|
||||
{
|
||||
"mesh" : 2,
|
||||
"name" : "SafetyLever",
|
||||
"translation" : [
|
||||
0.6115021705627441,
|
||||
2.1325087547302246,
|
||||
0
|
||||
]
|
||||
},
|
||||
{
|
||||
"mesh" : 3,
|
||||
"name" : "SafetyRing",
|
||||
"translation" : [
|
||||
0.6115090847015381,
|
||||
2.1325178146362305,
|
||||
-0.6156752109527588
|
||||
]
|
||||
},
|
||||
{
|
||||
"mesh" : 4,
|
||||
"name" : "Seal",
|
||||
"translation" : [
|
||||
0,
|
||||
-2.247849941253662,
|
||||
0
|
||||
]
|
||||
},
|
||||
{
|
||||
"mesh" : 5,
|
||||
"name" : "SafetyPin",
|
||||
"translation" : [
|
||||
0.6115090847015381,
|
||||
2.1325180530548096,
|
||||
-0.6156752109527588
|
||||
]
|
||||
},
|
||||
{
|
||||
"mesh" : 6,
|
||||
"name" : "StrikerPin",
|
||||
"translation" : [
|
||||
0.47106197476387024,
|
||||
2.2471275329589844,
|
||||
0.000243160204263404
|
||||
]
|
||||
},
|
||||
{
|
||||
"mesh" : 7,
|
||||
"name" : "StrikerSpring",
|
||||
"translation" : [
|
||||
0.4710620045661926,
|
||||
2.2471275329589844,
|
||||
-0.041993532329797745
|
||||
]
|
||||
},
|
||||
{
|
||||
"mesh" : 8,
|
||||
"name" : "Striker",
|
||||
"translation" : [
|
||||
0.47106197476387024,
|
||||
2.2471275329589844,
|
||||
0.00024316018971148878
|
||||
]
|
||||
}
|
||||
],
|
||||
"materials" : [
|
||||
{
|
||||
"doubleSided" : true,
|
||||
"name" : "mat_Grenade",
|
||||
"normalTexture" : {
|
||||
"index" : 0
|
||||
},
|
||||
"pbrMetallicRoughness" : {
|
||||
"baseColorTexture" : {
|
||||
"index" : 1
|
||||
},
|
||||
"metallicRoughnessTexture" : {
|
||||
"index" : 2
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"meshes" : [
|
||||
{
|
||||
"name" : "grenadeBody_low",
|
||||
"primitives" : [
|
||||
{
|
||||
"attributes" : {
|
||||
"POSITION" : 0,
|
||||
"TEXCOORD_0" : 1,
|
||||
"NORMAL" : 2
|
||||
},
|
||||
"indices" : 3,
|
||||
"material" : 0
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name" : "grenadeHead_low",
|
||||
"primitives" : [
|
||||
{
|
||||
"attributes" : {
|
||||
"POSITION" : 4,
|
||||
"TEXCOORD_0" : 5,
|
||||
"NORMAL" : 6
|
||||
},
|
||||
"indices" : 7,
|
||||
"material" : 0
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name" : "grenadeCocking_low",
|
||||
"primitives" : [
|
||||
{
|
||||
"attributes" : {
|
||||
"POSITION" : 8,
|
||||
"TEXCOORD_0" : 9,
|
||||
"NORMAL" : 10
|
||||
},
|
||||
"indices" : 11,
|
||||
"material" : 0
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name" : "grenadePinspring_low",
|
||||
"primitives" : [
|
||||
{
|
||||
"attributes" : {
|
||||
"POSITION" : 12,
|
||||
"TEXCOORD_0" : 13,
|
||||
"NORMAL" : 14
|
||||
},
|
||||
"indices" : 15,
|
||||
"material" : 0
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name" : "grenadeSeal_low",
|
||||
"primitives" : [
|
||||
{
|
||||
"attributes" : {
|
||||
"POSITION" : 16,
|
||||
"TEXCOORD_0" : 17,
|
||||
"NORMAL" : 18
|
||||
},
|
||||
"indices" : 19,
|
||||
"material" : 0
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name" : "grenadePin_low",
|
||||
"primitives" : [
|
||||
{
|
||||
"attributes" : {
|
||||
"POSITION" : 20,
|
||||
"TEXCOORD_0" : 21,
|
||||
"NORMAL" : 22
|
||||
},
|
||||
"indices" : 23,
|
||||
"material" : 0
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name" : "grenadeSpringpin_low",
|
||||
"primitives" : [
|
||||
{
|
||||
"attributes" : {
|
||||
"POSITION" : 24,
|
||||
"TEXCOORD_0" : 25,
|
||||
"NORMAL" : 26
|
||||
},
|
||||
"indices" : 27,
|
||||
"material" : 0
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name" : "grenadeSpring_low",
|
||||
"primitives" : [
|
||||
{
|
||||
"attributes" : {
|
||||
"POSITION" : 28,
|
||||
"TEXCOORD_0" : 29,
|
||||
"NORMAL" : 30
|
||||
},
|
||||
"indices" : 31,
|
||||
"material" : 0
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name" : "grenadeHammer_low",
|
||||
"primitives" : [
|
||||
{
|
||||
"attributes" : {
|
||||
"POSITION" : 32,
|
||||
"TEXCOORD_0" : 33,
|
||||
"NORMAL" : 34
|
||||
},
|
||||
"indices" : 35,
|
||||
"material" : 0
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"textures" : [
|
||||
{
|
||||
"sampler" : 0,
|
||||
"source" : 0
|
||||
},
|
||||
{
|
||||
"sampler" : 0,
|
||||
"source" : 1
|
||||
},
|
||||
{
|
||||
"sampler" : 0,
|
||||
"source" : 2
|
||||
}
|
||||
],
|
||||
"images" : [
|
||||
{
|
||||
"mimeType" : "image/png",
|
||||
"name" : "Grenade_N",
|
||||
"uri" : "Grenade_N.png"
|
||||
},
|
||||
{
|
||||
"mimeType" : "image/png",
|
||||
"name" : "Grenade_B",
|
||||
"uri" : "Grenade_B.png"
|
||||
},
|
||||
{
|
||||
"mimeType" : "image/png",
|
||||
"name" : "Grenade_M-Grenade_R",
|
||||
"uri" : "Grenade_M-Grenade_R.png"
|
||||
}
|
||||
],
|
||||
"accessors" : [
|
||||
{
|
||||
"bufferView" : 0,
|
||||
"componentType" : 5126,
|
||||
"count" : 1300,
|
||||
"max" : [
|
||||
1.159013271331787,
|
||||
3.669426202774048,
|
||||
1.1590133905410767
|
||||
],
|
||||
"min" : [
|
||||
-1.1590133905410767,
|
||||
-1.9166386664437596e-06,
|
||||
-1.1590133905410767
|
||||
],
|
||||
"type" : "VEC3"
|
||||
},
|
||||
{
|
||||
"bufferView" : 1,
|
||||
"componentType" : 5126,
|
||||
"count" : 1300,
|
||||
"type" : "VEC2"
|
||||
},
|
||||
{
|
||||
"bufferView" : 2,
|
||||
"componentType" : 5126,
|
||||
"count" : 1300,
|
||||
"type" : "VEC3"
|
||||
},
|
||||
{
|
||||
"bufferView" : 3,
|
||||
"componentType" : 5123,
|
||||
"count" : 2952,
|
||||
"type" : "SCALAR"
|
||||
},
|
||||
{
|
||||
"bufferView" : 4,
|
||||
"componentType" : 5126,
|
||||
"count" : 482,
|
||||
"max" : [
|
||||
0.9789643883705139,
|
||||
4.635942459106445,
|
||||
0.5773466229438782
|
||||
],
|
||||
"min" : [
|
||||
-0.6583898067474365,
|
||||
3.731045961380005,
|
||||
-0.5773470997810364
|
||||
],
|
||||
"type" : "VEC3"
|
||||
},
|
||||
{
|
||||
"bufferView" : 5,
|
||||
"componentType" : 5126,
|
||||
"count" : 482,
|
||||
"type" : "VEC2"
|
||||
},
|
||||
{
|
||||
"bufferView" : 6,
|
||||
"componentType" : 5126,
|
||||
"count" : 482,
|
||||
"type" : "VEC3"
|
||||
},
|
||||
{
|
||||
"bufferView" : 7,
|
||||
"componentType" : 5123,
|
||||
"count" : 1356,
|
||||
"type" : "SCALAR"
|
||||
},
|
||||
{
|
||||
"bufferView" : 8,
|
||||
"componentType" : 5126,
|
||||
"count" : 606,
|
||||
"max" : [
|
||||
0.9795078635215759,
|
||||
0.3027413785457611,
|
||||
0.5291423201560974
|
||||
],
|
||||
"min" : [
|
||||
-1.3077030181884766,
|
||||
-3.9374680519104004,
|
||||
-0.529142439365387
|
||||
],
|
||||
"type" : "VEC3"
|
||||
},
|
||||
{
|
||||
"bufferView" : 9,
|
||||
"componentType" : 5126,
|
||||
"count" : 606,
|
||||
"type" : "VEC2"
|
||||
},
|
||||
{
|
||||
"bufferView" : 10,
|
||||
"componentType" : 5126,
|
||||
"count" : 606,
|
||||
"type" : "VEC3"
|
||||
},
|
||||
{
|
||||
"bufferView" : 11,
|
||||
"componentType" : 5123,
|
||||
"count" : 1668,
|
||||
"type" : "SCALAR"
|
||||
},
|
||||
{
|
||||
"bufferView" : 12,
|
||||
"componentType" : 5126,
|
||||
"count" : 268,
|
||||
"max" : [
|
||||
0.6482481360435486,
|
||||
0.046728670597076416,
|
||||
0.05197814851999283
|
||||
],
|
||||
"min" : [
|
||||
-0.682935357093811,
|
||||
-1.2822237014770508,
|
||||
-0.21923021972179413
|
||||
],
|
||||
"type" : "VEC3"
|
||||
},
|
||||
{
|
||||
"bufferView" : 13,
|
||||
"componentType" : 5126,
|
||||
"count" : 268,
|
||||
"type" : "VEC2"
|
||||
},
|
||||
{
|
||||
"bufferView" : 14,
|
||||
"componentType" : 5126,
|
||||
"count" : 268,
|
||||
"type" : "VEC3"
|
||||
},
|
||||
{
|
||||
"bufferView" : 15,
|
||||
"componentType" : 5123,
|
||||
"count" : 1188,
|
||||
"type" : "SCALAR"
|
||||
},
|
||||
{
|
||||
"bufferView" : 16,
|
||||
"componentType" : 5126,
|
||||
"count" : 34,
|
||||
"max" : [
|
||||
0.5341219902038574,
|
||||
3.730225086212158,
|
||||
0.5341217517852783
|
||||
],
|
||||
"min" : [
|
||||
-0.5341173410415649,
|
||||
3.669447422027588,
|
||||
-0.5341175198554993
|
||||
],
|
||||
"type" : "VEC3"
|
||||
},
|
||||
{
|
||||
"bufferView" : 17,
|
||||
"componentType" : 5126,
|
||||
"count" : 34,
|
||||
"type" : "VEC2"
|
||||
},
|
||||
{
|
||||
"bufferView" : 18,
|
||||
"componentType" : 5126,
|
||||
"count" : 34,
|
||||
"type" : "VEC3"
|
||||
},
|
||||
{
|
||||
"bufferView" : 19,
|
||||
"componentType" : 5123,
|
||||
"count" : 96,
|
||||
"type" : "SCALAR"
|
||||
},
|
||||
{
|
||||
"bufferView" : 20,
|
||||
"componentType" : 5126,
|
||||
"count" : 170,
|
||||
"max" : [
|
||||
0.02311806008219719,
|
||||
0.07415742427110672,
|
||||
1.2472240924835205
|
||||
],
|
||||
"min" : [
|
||||
-0.023298654705286026,
|
||||
-0.07137548178434372,
|
||||
-0.06658351421356201
|
||||
],
|
||||
"type" : "VEC3"
|
||||
},
|
||||
{
|
||||
"bufferView" : 21,
|
||||
"componentType" : 5126,
|
||||
"count" : 170,
|
||||
"type" : "VEC2"
|
||||
},
|
||||
{
|
||||
"bufferView" : 22,
|
||||
"componentType" : 5126,
|
||||
"count" : 170,
|
||||
"type" : "VEC3"
|
||||
},
|
||||
{
|
||||
"bufferView" : 23,
|
||||
"componentType" : 5123,
|
||||
"count" : 588,
|
||||
"type" : "SCALAR"
|
||||
},
|
||||
{
|
||||
"bufferView" : 24,
|
||||
"componentType" : 5126,
|
||||
"count" : 34,
|
||||
"max" : [
|
||||
0.06607207655906677,
|
||||
0.06607206910848618,
|
||||
0.5017820596694946
|
||||
],
|
||||
"min" : [
|
||||
-0.06607204675674438,
|
||||
-0.06607206910848618,
|
||||
-0.5017820596694946
|
||||
],
|
||||
"type" : "VEC3"
|
||||
},
|
||||
{
|
||||
"bufferView" : 25,
|
||||
"componentType" : 5126,
|
||||
"count" : 34,
|
||||
"type" : "VEC2"
|
||||
},
|
||||
{
|
||||
"bufferView" : 26,
|
||||
"componentType" : 5126,
|
||||
"count" : 34,
|
||||
"type" : "VEC3"
|
||||
},
|
||||
{
|
||||
"bufferView" : 27,
|
||||
"componentType" : 5123,
|
||||
"count" : 84,
|
||||
"type" : "SCALAR"
|
||||
},
|
||||
{
|
||||
"bufferView" : 28,
|
||||
"componentType" : 5126,
|
||||
"count" : 603,
|
||||
"max" : [
|
||||
0.10049010813236237,
|
||||
0.10046502202749252,
|
||||
0.2720564305782318
|
||||
],
|
||||
"min" : [
|
||||
-0.11457761377096176,
|
||||
-0.39153483510017395,
|
||||
-0.2632889151573181
|
||||
],
|
||||
"type" : "VEC3"
|
||||
},
|
||||
{
|
||||
"bufferView" : 29,
|
||||
"componentType" : 5126,
|
||||
"count" : 603,
|
||||
"type" : "VEC2"
|
||||
},
|
||||
{
|
||||
"bufferView" : 30,
|
||||
"componentType" : 5126,
|
||||
"count" : 603,
|
||||
"type" : "VEC3"
|
||||
},
|
||||
{
|
||||
"bufferView" : 31,
|
||||
"componentType" : 5123,
|
||||
"count" : 2292,
|
||||
"type" : "SCALAR"
|
||||
},
|
||||
{
|
||||
"bufferView" : 32,
|
||||
"componentType" : 5126,
|
||||
"count" : 74,
|
||||
"max" : [
|
||||
0.08392742276191711,
|
||||
0.12473973631858826,
|
||||
0.15915289521217346
|
||||
],
|
||||
"min" : [
|
||||
-0.6397569179534912,
|
||||
-0.26187893748283386,
|
||||
-0.1591528356075287
|
||||
],
|
||||
"type" : "VEC3"
|
||||
},
|
||||
{
|
||||
"bufferView" : 33,
|
||||
"componentType" : 5126,
|
||||
"count" : 74,
|
||||
"type" : "VEC2"
|
||||
},
|
||||
{
|
||||
"bufferView" : 34,
|
||||
"componentType" : 5126,
|
||||
"count" : 74,
|
||||
"type" : "VEC3"
|
||||
},
|
||||
{
|
||||
"bufferView" : 35,
|
||||
"componentType" : 5123,
|
||||
"count" : 180,
|
||||
"type" : "SCALAR"
|
||||
}
|
||||
],
|
||||
"bufferViews" : [
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteLength" : 15600,
|
||||
"byteOffset" : 0,
|
||||
"target" : 34962
|
||||
},
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteLength" : 10400,
|
||||
"byteOffset" : 15600,
|
||||
"target" : 34962
|
||||
},
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteLength" : 15600,
|
||||
"byteOffset" : 26000,
|
||||
"target" : 34962
|
||||
},
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteLength" : 5904,
|
||||
"byteOffset" : 41600,
|
||||
"target" : 34963
|
||||
},
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteLength" : 5784,
|
||||
"byteOffset" : 47504,
|
||||
"target" : 34962
|
||||
},
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteLength" : 3856,
|
||||
"byteOffset" : 53288,
|
||||
"target" : 34962
|
||||
},
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteLength" : 5784,
|
||||
"byteOffset" : 57144,
|
||||
"target" : 34962
|
||||
},
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteLength" : 2712,
|
||||
"byteOffset" : 62928,
|
||||
"target" : 34963
|
||||
},
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteLength" : 7272,
|
||||
"byteOffset" : 65640,
|
||||
"target" : 34962
|
||||
},
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteLength" : 4848,
|
||||
"byteOffset" : 72912,
|
||||
"target" : 34962
|
||||
},
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteLength" : 7272,
|
||||
"byteOffset" : 77760,
|
||||
"target" : 34962
|
||||
},
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteLength" : 3336,
|
||||
"byteOffset" : 85032,
|
||||
"target" : 34963
|
||||
},
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteLength" : 3216,
|
||||
"byteOffset" : 88368,
|
||||
"target" : 34962
|
||||
},
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteLength" : 2144,
|
||||
"byteOffset" : 91584,
|
||||
"target" : 34962
|
||||
},
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteLength" : 3216,
|
||||
"byteOffset" : 93728,
|
||||
"target" : 34962
|
||||
},
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteLength" : 2376,
|
||||
"byteOffset" : 96944,
|
||||
"target" : 34963
|
||||
},
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteLength" : 408,
|
||||
"byteOffset" : 99320,
|
||||
"target" : 34962
|
||||
},
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteLength" : 272,
|
||||
"byteOffset" : 99728,
|
||||
"target" : 34962
|
||||
},
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteLength" : 408,
|
||||
"byteOffset" : 100000,
|
||||
"target" : 34962
|
||||
},
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteLength" : 192,
|
||||
"byteOffset" : 100408,
|
||||
"target" : 34963
|
||||
},
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteLength" : 2040,
|
||||
"byteOffset" : 100600,
|
||||
"target" : 34962
|
||||
},
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteLength" : 1360,
|
||||
"byteOffset" : 102640,
|
||||
"target" : 34962
|
||||
},
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteLength" : 2040,
|
||||
"byteOffset" : 104000,
|
||||
"target" : 34962
|
||||
},
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteLength" : 1176,
|
||||
"byteOffset" : 106040,
|
||||
"target" : 34963
|
||||
},
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteLength" : 408,
|
||||
"byteOffset" : 107216,
|
||||
"target" : 34962
|
||||
},
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteLength" : 272,
|
||||
"byteOffset" : 107624,
|
||||
"target" : 34962
|
||||
},
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteLength" : 408,
|
||||
"byteOffset" : 107896,
|
||||
"target" : 34962
|
||||
},
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteLength" : 168,
|
||||
"byteOffset" : 108304,
|
||||
"target" : 34963
|
||||
},
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteLength" : 7236,
|
||||
"byteOffset" : 108472,
|
||||
"target" : 34962
|
||||
},
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteLength" : 4824,
|
||||
"byteOffset" : 115708,
|
||||
"target" : 34962
|
||||
},
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteLength" : 7236,
|
||||
"byteOffset" : 120532,
|
||||
"target" : 34962
|
||||
},
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteLength" : 4584,
|
||||
"byteOffset" : 127768,
|
||||
"target" : 34963
|
||||
},
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteLength" : 888,
|
||||
"byteOffset" : 132352,
|
||||
"target" : 34962
|
||||
},
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteLength" : 592,
|
||||
"byteOffset" : 133240,
|
||||
"target" : 34962
|
||||
},
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteLength" : 888,
|
||||
"byteOffset" : 133832,
|
||||
"target" : 34962
|
||||
},
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteLength" : 360,
|
||||
"byteOffset" : 134720,
|
||||
"target" : 34963
|
||||
}
|
||||
],
|
||||
"samplers" : [
|
||||
{
|
||||
"magFilter" : 9729,
|
||||
"minFilter" : 9987
|
||||
}
|
||||
],
|
||||
"buffers" : [
|
||||
{
|
||||
"byteLength" : 135080,
|
||||
"uri" : "mk2-frag-grenade.bin"
|
||||
}
|
||||
]
|
||||
}
|
Before Width: | Height: | Size: 1.7 MiB |
Before Width: | Height: | Size: 2.6 MiB |
Before Width: | Height: | Size: 4.2 MiB |
|
@ -1,220 +0,0 @@
|
|||
{
|
||||
"asset" : {
|
||||
"generator" : "Khronos glTF Blender I/O v3.4.50",
|
||||
"version" : "2.0"
|
||||
},
|
||||
"scene" : 0,
|
||||
"scenes" : [
|
||||
{
|
||||
"name" : "Scene",
|
||||
"nodes" : [
|
||||
5
|
||||
]
|
||||
}
|
||||
],
|
||||
"nodes" : [
|
||||
{
|
||||
"mesh" : 0,
|
||||
"name" : "\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd002_Material #106_0",
|
||||
"translation" : [
|
||||
-14.98544692993164,
|
||||
7.43948221206665,
|
||||
0.0004016915918327868
|
||||
]
|
||||
},
|
||||
{
|
||||
"children" : [
|
||||
0
|
||||
],
|
||||
"name" : "Object_4"
|
||||
},
|
||||
{
|
||||
"children" : [
|
||||
1
|
||||
],
|
||||
"name" : "\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd002",
|
||||
"rotation" : [
|
||||
-0.501552939414978,
|
||||
0.49844127893447876,
|
||||
0.49844223260879517,
|
||||
0.5015538930892944
|
||||
],
|
||||
"scale" : [
|
||||
1.9006390571594238,
|
||||
1.4436899423599243,
|
||||
0.13420099020004272
|
||||
]
|
||||
},
|
||||
{
|
||||
"children" : [
|
||||
2
|
||||
],
|
||||
"name" : "RootNode"
|
||||
},
|
||||
{
|
||||
"children" : [
|
||||
3
|
||||
],
|
||||
"name" : "145a44e480864eafa947fceb6548e111.fbx",
|
||||
"rotation" : [
|
||||
0.70710688829422,
|
||||
0,
|
||||
0,
|
||||
0.7071066498756409
|
||||
]
|
||||
},
|
||||
{
|
||||
"children" : [
|
||||
4
|
||||
],
|
||||
"name" : "Sketchfab_model",
|
||||
"rotation" : [
|
||||
-0.70710688829422,
|
||||
0,
|
||||
0,
|
||||
0.7071066498756409
|
||||
]
|
||||
}
|
||||
],
|
||||
"materials" : [
|
||||
{
|
||||
"doubleSided" : true,
|
||||
"name" : "Material_106",
|
||||
"normalTexture" : {
|
||||
"index" : 0
|
||||
},
|
||||
"occlusionTexture" : {
|
||||
"index" : 1
|
||||
},
|
||||
"pbrMetallicRoughness" : {
|
||||
"baseColorTexture" : {
|
||||
"index" : 2
|
||||
},
|
||||
"metallicRoughnessTexture" : {
|
||||
"index" : 1
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"meshes" : [
|
||||
{
|
||||
"name" : "\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd002_Material #106_0",
|
||||
"primitives" : [
|
||||
{
|
||||
"attributes" : {
|
||||
"POSITION" : 0,
|
||||
"TEXCOORD_0" : 1,
|
||||
"NORMAL" : 2
|
||||
},
|
||||
"indices" : 3,
|
||||
"material" : 0
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"textures" : [
|
||||
{
|
||||
"sampler" : 0,
|
||||
"source" : 0
|
||||
},
|
||||
{
|
||||
"sampler" : 0,
|
||||
"source" : 1
|
||||
},
|
||||
{
|
||||
"sampler" : 0,
|
||||
"source" : 2
|
||||
}
|
||||
],
|
||||
"images" : [
|
||||
{
|
||||
"mimeType" : "image/png",
|
||||
"name" : "Material_106_normal",
|
||||
"uri" : "Material_106_normal.png"
|
||||
},
|
||||
{
|
||||
"mimeType" : "image/png",
|
||||
"name" : "Material_106_metallicRoughness",
|
||||
"uri" : "Material_106_metallicRoughness.png"
|
||||
},
|
||||
{
|
||||
"mimeType" : "image/jpeg",
|
||||
"name" : "Material_106_baseColor",
|
||||
"uri" : "Material_106_baseColor.jpg"
|
||||
}
|
||||
],
|
||||
"accessors" : [
|
||||
{
|
||||
"bufferView" : 0,
|
||||
"componentType" : 5126,
|
||||
"count" : 478,
|
||||
"max" : [
|
||||
49.411319732666016,
|
||||
33.26576614379883,
|
||||
30.810150146484375
|
||||
],
|
||||
"min" : [
|
||||
-18.004470825195312,
|
||||
-50.72441864013672,
|
||||
-109.1097412109375
|
||||
],
|
||||
"type" : "VEC3"
|
||||
},
|
||||
{
|
||||
"bufferView" : 1,
|
||||
"componentType" : 5126,
|
||||
"count" : 478,
|
||||
"type" : "VEC2"
|
||||
},
|
||||
{
|
||||
"bufferView" : 2,
|
||||
"componentType" : 5126,
|
||||
"count" : 478,
|
||||
"type" : "VEC3"
|
||||
},
|
||||
{
|
||||
"bufferView" : 3,
|
||||
"componentType" : 5123,
|
||||
"count" : 540,
|
||||
"type" : "SCALAR"
|
||||
}
|
||||
],
|
||||
"bufferViews" : [
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteLength" : 5736,
|
||||
"byteOffset" : 0,
|
||||
"target" : 34962
|
||||
},
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteLength" : 3824,
|
||||
"byteOffset" : 5736,
|
||||
"target" : 34962
|
||||
},
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteLength" : 5736,
|
||||
"byteOffset" : 9560,
|
||||
"target" : 34962
|
||||
},
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteLength" : 1080,
|
||||
"byteOffset" : 15296,
|
||||
"target" : 34963
|
||||
}
|
||||
],
|
||||
"samplers" : [
|
||||
{
|
||||
"magFilter" : 9729,
|
||||
"minFilter" : 9987
|
||||
}
|
||||
],
|
||||
"buffers" : [
|
||||
{
|
||||
"byteLength" : 16376,
|
||||
"uri" : "pallet_wood.bin"
|
||||
}
|
||||
]
|
||||
}
|
Before Width: | Height: | Size: 976 KiB |
Before Width: | Height: | Size: 816 KiB |
Before Width: | Height: | Size: 282 KiB |
Before Width: | Height: | Size: 405 KiB |
Before Width: | Height: | Size: 440 KiB |
Before Width: | Height: | Size: 46 KiB |
Before Width: | Height: | Size: 499 KiB |
Before Width: | Height: | Size: 425 KiB |
Before Width: | Height: | Size: 28 KiB |
Before Width: | Height: | Size: 269 KiB |
Before Width: | Height: | Size: 120 KiB |
Before Width: | Height: | Size: 42 KiB |
Before Width: | Height: | Size: 530 KiB |
Before Width: | Height: | Size: 514 KiB |
Before Width: | Height: | Size: 51 KiB |
Before Width: | Height: | Size: 442 KiB |
Before Width: | Height: | Size: 441 KiB |
Before Width: | Height: | Size: 88 KiB |
Before Width: | Height: | Size: 425 KiB |
Before Width: | Height: | Size: 474 KiB |
Before Width: | Height: | Size: 40 KiB |
|
@ -1,116 +0,0 @@
|
|||
#version 450 core
|
||||
|
||||
layout(local_size_x = 8, local_size_y = 8) in;
|
||||
layout(rg16f, binding = 0) uniform image2D brdfLUT;
|
||||
|
||||
const float PI = 3.14159265359;
|
||||
// ----------------------------------------------------------------------------
|
||||
// http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html
|
||||
// efficient VanDerCorpus calculation.
|
||||
float RadicalInverse_VdC(uint bits)
|
||||
{
|
||||
bits = (bits << 16u) | (bits >> 16u);
|
||||
bits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u);
|
||||
bits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u);
|
||||
bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u);
|
||||
bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u);
|
||||
return float(bits) * 2.3283064365386963e-10; // / 0x100000000
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
vec2 Hammersley(uint i, uint N)
|
||||
{
|
||||
return vec2(float(i)/float(N), RadicalInverse_VdC(i));
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
vec3 ImportanceSampleGGX(vec2 Xi, vec3 N, float roughness)
|
||||
{
|
||||
float a = roughness*roughness;
|
||||
|
||||
float phi = 2.0 * PI * Xi.x;
|
||||
float cosTheta = sqrt((1.0 - Xi.y) / (1.0 + (a*a - 1.0) * Xi.y));
|
||||
float sinTheta = sqrt(1.0 - cosTheta*cosTheta);
|
||||
|
||||
// from spherical coordinates to cartesian coordinates - halfway vector
|
||||
vec3 H;
|
||||
H.x = cos(phi) * sinTheta;
|
||||
H.y = sin(phi) * sinTheta;
|
||||
H.z = cosTheta;
|
||||
|
||||
// from tangent-space H vector to world-space sample vector
|
||||
vec3 up = abs(N.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0);
|
||||
vec3 tangent = normalize(cross(up, N));
|
||||
vec3 bitangent = cross(N, tangent);
|
||||
|
||||
vec3 sampleVec = tangent * H.x + bitangent * H.y + N * H.z;
|
||||
return normalize(sampleVec);
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
float GeometrySchlickGGX(float NdotV, float roughness)
|
||||
{
|
||||
// note that we use a different k for IBL
|
||||
float a = roughness;
|
||||
float k = (a * a) / 2.0;
|
||||
|
||||
float nom = NdotV;
|
||||
float denom = NdotV * (1.0 - k) + k;
|
||||
|
||||
return nom / denom;
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness)
|
||||
{
|
||||
float NdotV = max(dot(N, V), 0.0);
|
||||
float NdotL = max(dot(N, L), 0.0);
|
||||
float ggx2 = GeometrySchlickGGX(NdotV, roughness);
|
||||
float ggx1 = GeometrySchlickGGX(NdotL, roughness);
|
||||
|
||||
return ggx1 * ggx2;
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
vec2 IntegrateBRDF(float NdotV, float roughness)
|
||||
{
|
||||
vec3 V;
|
||||
V.x = sqrt(1.0 - NdotV*NdotV);
|
||||
V.y = 0.0;
|
||||
V.z = NdotV;
|
||||
|
||||
float A = 0.0;
|
||||
float B = 0.0;
|
||||
|
||||
vec3 N = vec3(0.0, 0.0, 1.0);
|
||||
|
||||
const uint SAMPLE_COUNT = 1024u;
|
||||
for(uint i = 0u; i < SAMPLE_COUNT; ++i)
|
||||
{
|
||||
// generates a sample vector that's biased towards the
|
||||
// preferred alignment direction (importance sampling).
|
||||
vec2 Xi = Hammersley(i, SAMPLE_COUNT);
|
||||
vec3 H = ImportanceSampleGGX(Xi, N, roughness);
|
||||
vec3 L = normalize(2.0 * dot(V, H) * H - V);
|
||||
|
||||
float NdotL = max(L.z, 0.0);
|
||||
float NdotH = max(H.z, 0.0);
|
||||
float VdotH = max(dot(V, H), 0.0);
|
||||
|
||||
if(NdotL > 0.0)
|
||||
{
|
||||
float G = GeometrySmith(N, V, L, roughness);
|
||||
float G_Vis = (G * VdotH) / (NdotH * NdotV);
|
||||
float Fc = pow(1.0 - VdotH, 5.0);
|
||||
|
||||
A += (1.0 - Fc) * G_Vis;
|
||||
B += Fc * G_Vis;
|
||||
}
|
||||
}
|
||||
A /= float(SAMPLE_COUNT);
|
||||
B /= float(SAMPLE_COUNT);
|
||||
return vec2(A, B);
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
void main()
|
||||
{
|
||||
uvec2 pixelLocation = gl_GlobalInvocationID.xy;
|
||||
vec2 texCoords = (vec2(pixelLocation)+vec2(0.5))/vec2(imageSize(brdfLUT));
|
||||
vec2 integratedBRDF = IntegrateBRDF(texCoords.x, texCoords.y);
|
||||
imageStore(brdfLUT, ivec2(pixelLocation), vec4(integratedBRDF,0,0));
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
#version 450 core
|
||||
out vec4 FragColor;
|
||||
in vec3 WorldPos;
|
||||
|
||||
uniform sampler2D equirectangularMap;
|
||||
|
||||
const vec2 invAtan = vec2(0.1591, 0.3183);
|
||||
vec2 SampleSphericalMap(vec3 v)
|
||||
{
|
||||
vec2 uv = vec2(atan(v.z, v.x), asin(v.y));
|
||||
uv *= invAtan;
|
||||
uv += 0.5;
|
||||
return uv;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 uv = SampleSphericalMap(normalize(WorldPos));
|
||||
vec3 color = texture(equirectangularMap, uv).rgb;
|
||||
|
||||
FragColor = vec4(color, 1.0);
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
#version 450 core
|
||||
layout (location = 0) in vec3 aPos;
|
||||
|
||||
out vec3 WorldPos;
|
||||
|
||||
uniform mat4 projection;
|
||||
uniform mat4 view;
|
||||
|
||||
void main()
|
||||
{
|
||||
WorldPos = aPos;
|
||||
gl_Position = projection * view * vec4(WorldPos, 1.0);
|
||||
}
|
|
@ -1,107 +0,0 @@
|
|||
#version 450 core
|
||||
out vec4 FragColor;
|
||||
in vec3 WorldPos;
|
||||
|
||||
uniform samplerCube environmentMap;
|
||||
uniform float roughness;
|
||||
|
||||
const float PI = 3.14159265359;
|
||||
// ----------------------------------------------------------------------------
|
||||
float DistributionGGX(vec3 N, vec3 H, float roughness)
|
||||
{
|
||||
float a = roughness*roughness;
|
||||
float a2 = a*a;
|
||||
float NdotH = max(dot(N, H), 0.0);
|
||||
float NdotH2 = NdotH*NdotH;
|
||||
|
||||
float nom = a2;
|
||||
float denom = (NdotH2 * (a2 - 1.0) + 1.0);
|
||||
denom = PI * denom * denom;
|
||||
|
||||
return nom / denom;
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
// http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html
|
||||
// efficient VanDerCorpus calculation.
|
||||
float RadicalInverse_VdC(uint bits)
|
||||
{
|
||||
bits = (bits << 16u) | (bits >> 16u);
|
||||
bits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u);
|
||||
bits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u);
|
||||
bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u);
|
||||
bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u);
|
||||
return float(bits) * 2.3283064365386963e-10; // / 0x100000000
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
vec2 Hammersley(uint i, uint N)
|
||||
{
|
||||
return vec2(float(i)/float(N), RadicalInverse_VdC(i));
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
vec3 ImportanceSampleGGX(vec2 Xi, vec3 N, float roughness)
|
||||
{
|
||||
float a = roughness*roughness;
|
||||
|
||||
float phi = 2.0 * PI * Xi.x;
|
||||
float cosTheta = sqrt((1.0 - Xi.y) / (1.0 + (a*a - 1.0) * Xi.y));
|
||||
float sinTheta = sqrt(1.0 - cosTheta*cosTheta);
|
||||
|
||||
// from spherical coordinates to cartesian coordinates - halfway vector
|
||||
vec3 H;
|
||||
H.x = cos(phi) * sinTheta;
|
||||
H.y = sin(phi) * sinTheta;
|
||||
H.z = cosTheta;
|
||||
|
||||
// from tangent-space H vector to world-space sample vector
|
||||
vec3 up = abs(N.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0);
|
||||
vec3 tangent = normalize(cross(up, N));
|
||||
vec3 bitangent = cross(N, tangent);
|
||||
|
||||
vec3 sampleVec = tangent * H.x + bitangent * H.y + N * H.z;
|
||||
return normalize(sampleVec);
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
void main()
|
||||
{
|
||||
vec3 N = normalize(WorldPos);
|
||||
|
||||
// make the simplyfying assumption that V equals R equals the normal
|
||||
vec3 R = N;
|
||||
vec3 V = R;
|
||||
|
||||
const uint SAMPLE_COUNT = 1024u;
|
||||
vec3 prefilteredColor = vec3(0.0);
|
||||
float totalWeight = 0.0;
|
||||
|
||||
for(uint i = 0u; i < SAMPLE_COUNT; ++i)
|
||||
{
|
||||
// generates a sample vector that's biased towards the preferred alignment direction (importance sampling).
|
||||
vec2 Xi = Hammersley(i, SAMPLE_COUNT);
|
||||
vec3 H = ImportanceSampleGGX(Xi, N, roughness);
|
||||
vec3 L = normalize(2.0 * dot(V, H) * H - V);
|
||||
|
||||
float NdotL = max(dot(N, L), 0.0);
|
||||
if(NdotL > 0.0)
|
||||
{
|
||||
// sample from the environment's mip level based on roughness/pdf
|
||||
float D = DistributionGGX(N, H, roughness);
|
||||
float NdotH = max(dot(N, H), 0.0);
|
||||
float HdotV = max(dot(H, V), 0.0);
|
||||
float pdf = D * NdotH / (4.0 * HdotV) + 0.0001;
|
||||
|
||||
//float resolution = 512.0; // resolution of source cubemap (per face)
|
||||
float resolution = float(textureSize(environmentMap,0).x); // resolution of source cubemap (per face)
|
||||
float saTexel = 4.0 * PI / (6.0 * resolution * resolution);
|
||||
float saSample = 1.0 / (float(SAMPLE_COUNT) * pdf + 0.0001);
|
||||
|
||||
float mipLevel = roughness == 0.0 ? 0.0 : 0.5 * log2(saSample / saTexel);
|
||||
|
||||
prefilteredColor += textureLod(environmentMap, L, mipLevel).rgb * NdotL;
|
||||
totalWeight += NdotL;
|
||||
}
|
||||
}
|
||||
|
||||
prefilteredColor = prefilteredColor / totalWeight;
|
||||
|
||||
FragColor = vec4(prefilteredColor, 1.0);
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
#version 450 core
|
||||
|
||||
layout (location = 4) out vec4 gDebug;
|
||||
|
||||
in vec2 TexCoords;
|
||||
in vec3 WorldPos;
|
||||
in vec3 Normal;
|
||||
|
||||
uniform vec3 color;
|
||||
|
||||
void main()
|
||||
{
|
||||
gDebug = vec4(color,1);
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
#version 330 core
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec3 aNormal;
|
||||
layout (location = 2) in vec2 aTexCoords;
|
||||
|
||||
out vec2 TexCoords;
|
||||
out vec3 WorldPos;
|
||||
out vec3 Normal;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
uniform mat4 projection;
|
||||
|
||||
void main()
|
||||
{
|
||||
TexCoords = aTexCoords;
|
||||
WorldPos = vec3(model * vec4(aPos, 1.0));
|
||||
Normal = mat3(model) * aNormal;
|
||||
|
||||
gl_Position = projection * view * vec4(WorldPos, 1.0);
|
||||
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
#version 450 core
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec2 aTexCoords;
|
||||
|
||||
out vec2 TexCoords;
|
||||
|
||||
void main()
|
||||
{
|
||||
TexCoords = aTexCoords;
|
||||
gl_Position = vec4(aPos, 1.0);
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
#version 450 core
|
||||
out vec4 FragColor;
|
||||
in vec3 WorldPos;
|
||||
|
||||
uniform samplerCube environmentMap;
|
||||
|
||||
const float PI = 3.14159265359;
|
||||
|
||||
void main()
|
||||
{
|
||||
// The world vector acts as the normal of a tangent surface
|
||||
// from the origin, aligned to WorldPos. Given this normal, calculate all
|
||||
// incoming radiance of the environment. The result of this radiance
|
||||
// is the radiance of light coming from -Normal direction, which is what
|
||||
// we use in the PBR shader to sample irradiance.
|
||||
vec3 N = normalize(WorldPos);
|
||||
|
||||
vec3 irradiance = vec3(0.0);
|
||||
|
||||
// tangent space calculation from origin point
|
||||
vec3 up = vec3(0.0, 1.0, 0.0);
|
||||
vec3 right = normalize(cross(up, N));
|
||||
up = normalize(cross(N, right));
|
||||
|
||||
float sampleDelta = 0.025;
|
||||
float nrSamples = 0.0;
|
||||
for(float phi = 0.0; phi < 2.0 * PI; phi += sampleDelta)
|
||||
{
|
||||
for(float theta = 0.0; theta < 0.5 * PI; theta += sampleDelta)
|
||||
{
|
||||
// spherical to cartesian (in tangent space)
|
||||
vec3 tangentSample = vec3(sin(theta) * cos(phi), sin(theta) * sin(phi), cos(theta));
|
||||
// tangent space to world
|
||||
vec3 sampleVec = tangentSample.x * right + tangentSample.y * up + tangentSample.z * N;
|
||||
|
||||
irradiance += texture(environmentMap, sampleVec).rgb * cos(theta) * sin(theta);
|
||||
nrSamples++;
|
||||
}
|
||||
}
|
||||
irradiance = PI * irradiance * (1.0 / float(nrSamples));
|
||||
|
||||
FragColor = vec4(irradiance, 1.0);
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
#version 450 core
|
||||
uniform sampler2D texture_basecolor;
|
||||
uniform sampler2D texture_metallic_roughness;
|
||||
uniform sampler2D texture_normal;
|
||||
|
||||
uniform bool texture_basecolor_available = false;
|
||||
uniform bool texture_metallic_roughness_available = false;
|
||||
uniform bool texture_normal_available = false;
|
||||
|
||||
uniform vec3 baseColor;
|
||||
uniform vec2 metallicRoughness;
|
||||
|
||||
layout (location = 0) out vec4 gBaseColor;
|
||||
layout (location = 1) out vec3 gNormal;
|
||||
layout (location = 2) out vec3 gPosition;
|
||||
layout (location = 3) out vec2 gMetallicRoughness;
|
||||
layout (location = 4) out vec4 gDebug;
|
||||
|
||||
in vec2 TexCoords;
|
||||
in vec3 WorldPos;
|
||||
in vec3 Normal;
|
||||
|
||||
vec3 getNormalFromMap()
|
||||
{
|
||||
vec3 tangentNormal = texture(texture_normal, TexCoords).xyz * 2.0 - 1.0;
|
||||
|
||||
vec3 Q1 = dFdx(WorldPos);
|
||||
vec3 Q2 = dFdy(WorldPos);
|
||||
vec2 st1 = dFdx(TexCoords);
|
||||
vec2 st2 = dFdy(TexCoords);
|
||||
|
||||
vec3 N = normalize(Normal);
|
||||
vec3 T = normalize(Q1*st2.t - Q2*st1.t);
|
||||
vec3 B = -normalize(cross(N, T));
|
||||
mat3 TBN = mat3(T, B, N);
|
||||
|
||||
return normalize(TBN * tangentNormal);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
if(texture_basecolor_available)
|
||||
gBaseColor = texture(texture_basecolor, TexCoords);
|
||||
else
|
||||
gBaseColor = vec4(baseColor, 1);
|
||||
if(gBaseColor.a<0.4)
|
||||
discard;
|
||||
gPosition = WorldPos;
|
||||
if(texture_normal_available)
|
||||
gNormal = getNormalFromMap();
|
||||
else
|
||||
gNormal = Normal;
|
||||
if(!gl_FrontFacing)
|
||||
gNormal = -gNormal;
|
||||
if(texture_metallic_roughness_available)
|
||||
gMetallicRoughness = texture(texture_metallic_roughness, TexCoords).bg;
|
||||
else
|
||||
gMetallicRoughness = metallicRoughness;
|
||||
|
||||
gDebug = vec4(0);
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
#version 450 core
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec3 aNormal;
|
||||
layout (location = 2) in vec2 aTexCoords;
|
||||
layout (location = 3) in ivec4 boneIds;
|
||||
layout (location = 4) in vec4 weights;
|
||||
|
||||
out vec2 TexCoords;
|
||||
out vec3 WorldPos;
|
||||
out vec3 Normal;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
uniform mat4 projection;
|
||||
|
||||
const int MAX_BONES = 100;
|
||||
const int MAX_BONE_INFLUENCE = 4;
|
||||
layout (std140, binding = 1) uniform FinalBonesMatrices
|
||||
{
|
||||
mat4 finalBonesMatrices[MAX_BONES];
|
||||
};
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 totalPosition = vec4(0.0f);
|
||||
vec3 totalNormal = vec3(0);
|
||||
int boneCount = 0;
|
||||
for(int i = 0 ; i < MAX_BONE_INFLUENCE ; i++)
|
||||
{
|
||||
if(boneIds[i] == -1)
|
||||
continue;
|
||||
if(boneIds[i] >= MAX_BONES)
|
||||
{
|
||||
totalPosition = vec4(aPos,1.0f);
|
||||
break;
|
||||
}
|
||||
boneCount++;
|
||||
vec4 localPosition = finalBonesMatrices[boneIds[i]] * vec4(aPos,1.0f);
|
||||
totalPosition += localPosition * weights[i];
|
||||
vec3 localNormal = mat3(finalBonesMatrices[boneIds[i]]) * aNormal;
|
||||
totalNormal += localNormal * weights[i];
|
||||
}
|
||||
|
||||
if(boneCount == 0)
|
||||
{
|
||||
totalPosition = vec4(aPos, 1);
|
||||
totalNormal = vec3(aNormal);
|
||||
}
|
||||
|
||||
TexCoords = aTexCoords;
|
||||
WorldPos = vec3(model * totalPosition);
|
||||
Normal = mat3(model) * totalNormal;
|
||||
|
||||
gl_Position = projection * view * vec4(WorldPos, 1.0);
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
#version 450 core
|
||||
|
||||
uniform sampler2D texture_basecolor;
|
||||
|
||||
in vec2 TexCoords;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 baseColor = texture(texture_basecolor, TexCoords);
|
||||
if(baseColor.a<0.4)
|
||||
discard;
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
#version 450 core
|
||||
|
||||
layout(triangles, invocations = 5) in;
|
||||
layout(triangle_strip, max_vertices = 3) out;
|
||||
|
||||
layout (std140, binding = 0) uniform LightSpaceMatrices
|
||||
{
|
||||
mat4 lightSpaceMatrices[16];
|
||||
};
|
||||
|
||||
in vec2 vTexCoords[];
|
||||
out vec2 TexCoords;
|
||||
|
||||
void main()
|
||||
{
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
TexCoords = vTexCoords[i];
|
||||
gl_Position = lightSpaceMatrices[gl_InvocationID] * gl_in[i].gl_Position;
|
||||
gl_Layer = gl_InvocationID;
|
||||
EmitVertex();
|
||||
}
|
||||
EndPrimitive();
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
#version 450 core
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec3 aNormal;
|
||||
layout (location = 2) in vec2 aTexCoords;
|
||||
layout (location = 3) in ivec4 boneIds;
|
||||
layout (location = 4) in vec4 weights;
|
||||
|
||||
out vec2 vTexCoords;
|
||||
|
||||
uniform mat4 model;
|
||||
|
||||
const int MAX_BONES = 100;
|
||||
const int MAX_BONE_INFLUENCE = 4;
|
||||
layout (std140, binding = 1) uniform FinalBonesMatrices
|
||||
{
|
||||
mat4 finalBonesMatrices[MAX_BONES];
|
||||
};
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 totalPosition = vec4(0.0f);
|
||||
vec3 totalNormal = vec3(0);
|
||||
int boneCount = 0;
|
||||
for(int i = 0 ; i < MAX_BONE_INFLUENCE ; i++)
|
||||
{
|
||||
if(boneIds[i] == -1)
|
||||
continue;
|
||||
if(boneIds[i] >= MAX_BONES)
|
||||
{
|
||||
totalPosition = vec4(aPos,1.0f);
|
||||
break;
|
||||
}
|
||||
boneCount++;
|
||||
vec4 localPosition = finalBonesMatrices[boneIds[i]] * vec4(aPos,1.0f);
|
||||
totalPosition += localPosition * weights[i];
|
||||
vec3 localNormal = mat3(finalBonesMatrices[boneIds[i]]) * aNormal;
|
||||
totalNormal += localNormal * weights[i];
|
||||
}
|
||||
|
||||
if(boneCount == 0)
|
||||
{
|
||||
totalPosition = vec4(aPos, 1);
|
||||
totalNormal = vec3(aNormal);
|
||||
}
|
||||
|
||||
vTexCoords = aTexCoords;
|
||||
gl_Position = model * totalPosition;
|
||||
}
|
|
@ -1,241 +0,0 @@
|
|||
#version 450 core
|
||||
|
||||
layout (local_size_x = 8, local_size_y = 8) in;
|
||||
|
||||
layout(rgba8, binding = 0) uniform image2D gBaseColor;
|
||||
uniform sampler2D gNormal;
|
||||
uniform sampler2D gPosition;
|
||||
uniform sampler2D gMetallicRoughness;
|
||||
uniform sampler2DArray gShadowMap;
|
||||
|
||||
uniform samplerCube irradianceMap;
|
||||
uniform samplerCube prefilterMap;
|
||||
uniform sampler2D brdfLUT;
|
||||
|
||||
layout (std140, binding = 0) uniform LightSpaceMatrices
|
||||
{
|
||||
mat4 lightSpaceMatrices[16];
|
||||
};
|
||||
uniform mat4 view;
|
||||
uniform float farPlane;
|
||||
uniform float shadowCascadePlaneDistances[16];
|
||||
uniform float shadowBiases[16];
|
||||
uniform int shadowCascadeCount;
|
||||
uniform float shadowBlendRatio;
|
||||
|
||||
uniform vec3 mainLightDirection;
|
||||
uniform vec3 mainLightRadiance;
|
||||
|
||||
uniform vec3 camPos;
|
||||
|
||||
const float PI = 3.14159265359;
|
||||
|
||||
float DistributionGGX(vec3 N, vec3 H, float roughness)
|
||||
{
|
||||
float a = roughness*roughness;
|
||||
float a2 = a*a;
|
||||
float NdotH = max(dot(N, H), 0.0);
|
||||
float NdotH2 = NdotH*NdotH;
|
||||
|
||||
float nom = a2;
|
||||
float denom = (NdotH2 * (a2 - 1.0) + 1.0);
|
||||
denom = PI * denom * denom;
|
||||
|
||||
return nom / denom;
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
float GeometrySchlickGGX(float NdotV, float roughness)
|
||||
{
|
||||
float r = (roughness + 1.0);
|
||||
float k = (r*r) / 8.0;
|
||||
|
||||
float nom = NdotV;
|
||||
float denom = NdotV * (1.0 - k) + k;
|
||||
|
||||
return nom / denom;
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness)
|
||||
{
|
||||
float NdotV = max(dot(N, V), 0.0);
|
||||
float NdotL = max(dot(N, L), 0.0);
|
||||
float ggx2 = GeometrySchlickGGX(NdotV, roughness);
|
||||
float ggx1 = GeometrySchlickGGX(NdotL, roughness);
|
||||
|
||||
return ggx1 * ggx2;
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
vec3 fresnelSchlick(float cosTheta, vec3 F0)
|
||||
{
|
||||
return F0 + (1.0 - F0) * pow(1.0 - cosTheta, 5.0);
|
||||
}
|
||||
vec3 fresnelSchlickRoughness(float cosTheta, vec3 F0, float roughness)
|
||||
{
|
||||
return F0 + (max(vec3(1.0 - roughness), F0) - F0) * pow(1.0 - cosTheta, 5.0);
|
||||
}
|
||||
|
||||
vec3 ambientLighting(vec3 N, vec3 V, vec3 F0, vec3 albedo, float metallic, float roughness, float ao)
|
||||
{
|
||||
// ambient lighting (we now use IBL as the ambient term)
|
||||
vec3 F = fresnelSchlickRoughness(clamp(dot(N, V),0.,1.), F0, roughness);
|
||||
|
||||
vec3 kS = F;
|
||||
vec3 kD = 1.0 - kS;
|
||||
kD *= 1.0 - metallic;
|
||||
|
||||
vec3 irradiance = texture(irradianceMap, N).rgb;
|
||||
vec3 diffuse = irradiance * albedo;
|
||||
|
||||
// sample both the pre-filter map and the BRDF lut and combine them together as per the Split-Sum approximation to get the IBL specular part.
|
||||
const float MAX_REFLECTION_LOD = 4.0;
|
||||
vec3 R = reflect(-V, N);
|
||||
vec3 prefilteredColor = textureLod(prefilterMap, R, roughness * MAX_REFLECTION_LOD).rgb;
|
||||
vec2 brdf = texture(brdfLUT, vec2(clamp(dot(N, V),0.,1.), roughness)).rg;
|
||||
vec3 specular = prefilteredColor * (F * brdf.x + brdf.y);
|
||||
|
||||
return (kD * diffuse + specular) * ao;
|
||||
}
|
||||
|
||||
|
||||
const int pcfRadius = 3;
|
||||
float getShadowFromLayer(vec3 fragPosWorldSpace, vec3 normal,int layer)
|
||||
{
|
||||
float normalBias = 1.2*4. /** (1+pcfRadius)*/ * shadowBiases[layer]*max((1.0 - dot(normal, mainLightDirection)), 0.1)/textureSize(gShadowMap, 0).x;
|
||||
normalBias = max(normalBias, 0.05);
|
||||
vec4 fragPosLightSpace = lightSpaceMatrices[layer] * vec4(fragPosWorldSpace+normal*normalBias, 1.0);
|
||||
// perform perspective divide
|
||||
vec3 projCoords = fragPosLightSpace.xyz / fragPosLightSpace.w;
|
||||
// transform to [0,1] range
|
||||
projCoords = projCoords * 0.5 + 0.5;
|
||||
|
||||
// get depth of current fragment from light's perspective
|
||||
float currentDepth = projCoords.z;
|
||||
|
||||
// keep the shadow at 0.0 when outside the far_plane region of the light's frustum.
|
||||
if (currentDepth > 1.0)
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
// PCF
|
||||
float shadow = 0.0;
|
||||
vec2 texelSize = 1.0 / vec2(textureSize(gShadowMap, 0));
|
||||
for(int x = -pcfRadius; x <= pcfRadius; ++x)
|
||||
{
|
||||
for(int y = -pcfRadius; y <= pcfRadius; ++y)
|
||||
{
|
||||
float pcfDepth = texture(gShadowMap, vec3(projCoords.xy + vec2(x, y) * texelSize, layer)).r;
|
||||
shadow += currentDepth > pcfDepth ? 1.0 : 0.0;
|
||||
}
|
||||
}
|
||||
shadow /= (2*pcfRadius+1)*(2*pcfRadius+1);
|
||||
return shadow;
|
||||
}
|
||||
|
||||
float ShadowCalculation(vec3 fragPosWorldSpace, vec3 normal, out int layer)
|
||||
{
|
||||
// select cascade layer
|
||||
vec4 fragPosViewSpace = view * vec4(fragPosWorldSpace, 1.0);
|
||||
float depthValue = abs(fragPosViewSpace.z);
|
||||
|
||||
layer = -1;
|
||||
for (int i = 0; i < shadowCascadeCount; ++i)
|
||||
{
|
||||
if (depthValue < shadowCascadePlaneDistances[i])
|
||||
{
|
||||
layer = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// if (layer == -1)
|
||||
// {
|
||||
// layer = shadowCascadeCount;
|
||||
// }
|
||||
|
||||
float shadow = getShadowFromLayer(fragPosWorldSpace,normal,layer);
|
||||
|
||||
|
||||
float nextLayerBeginDepth = layer==0? (1-shadowBlendRatio)*shadowCascadePlaneDistances[layer]
|
||||
:(1-shadowBlendRatio)*shadowCascadePlaneDistances[layer]+shadowBlendRatio*shadowCascadePlaneDistances[layer-1];
|
||||
if(depthValue > nextLayerBeginDepth)
|
||||
{
|
||||
float shadowNext = getShadowFromLayer(fragPosWorldSpace,normal,layer+1);
|
||||
shadow = mix(shadow,shadowNext, (depthValue-nextLayerBeginDepth)/(shadowCascadePlaneDistances[layer]-nextLayerBeginDepth));
|
||||
}
|
||||
return shadow;
|
||||
}
|
||||
|
||||
|
||||
|
||||
vec4 encodeRGBM(vec3 color)
|
||||
{
|
||||
if(dot(color,color)==0)
|
||||
return vec4(0,0,0,1);
|
||||
vec4 rgbm;
|
||||
float range = 8;
|
||||
color /= range;
|
||||
rgbm.a = clamp(max(max(color.r, color.g), max(color.b, 1e-6)), 0.0, 1.0);
|
||||
rgbm.a = ceil(rgbm.a * 255.0) / 255.0;
|
||||
rgbm.rgb = color / rgbm.a;
|
||||
return rgbm;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 pixelLocation = ivec2(gl_GlobalInvocationID.xy);
|
||||
|
||||
|
||||
//vec3 albedo = pow(texelFetch(gBaseColor, pixelLocation, 0).rgb, vec3(2.2));
|
||||
vec3 albedo = pow(imageLoad(gBaseColor, pixelLocation).rgb, vec3(2.2));
|
||||
float metallic = texelFetch(gMetallicRoughness, pixelLocation, 0).r;
|
||||
float roughness = texelFetch(gMetallicRoughness, pixelLocation, 0).g;
|
||||
|
||||
vec3 worldPos = texelFetch(gPosition, pixelLocation,0).xyz;
|
||||
vec3 normal = texelFetch(gNormal, pixelLocation,0).xyz;
|
||||
|
||||
if(normal==vec3(0))
|
||||
{
|
||||
//vec3 color = mainLightRadiance;
|
||||
//imageStore(gBaseColor, pixelLocation, vec4(color, 1.0));
|
||||
imageStore(gBaseColor, pixelLocation, vec4(0));
|
||||
return;
|
||||
}
|
||||
normal = normalize(normal);
|
||||
|
||||
vec3 V = normalize(camPos - worldPos);
|
||||
|
||||
vec3 F0 = vec3(0.04);
|
||||
F0 = mix(F0, albedo, metallic);
|
||||
|
||||
// calculate light radiance
|
||||
vec3 L = normalize(mainLightDirection);
|
||||
vec3 H = normalize(V + L);
|
||||
//float distance = length(lightPositions[i] - WorldPos);
|
||||
//float attenuation = 1.0 / (distance * distance);
|
||||
vec3 radiance = mainLightRadiance ;//* attenuation;
|
||||
|
||||
// cook-torrance brdf
|
||||
float NDF = DistributionGGX(normal, H, roughness);
|
||||
float G = GeometrySmith(normal, V, L, roughness);
|
||||
vec3 F = fresnelSchlick(clamp(dot(H, V),0.,1.), F0);
|
||||
//F = clamp(F,vec3(0),vec3(1));
|
||||
|
||||
vec3 kS = F;
|
||||
vec3 kD = vec3(1.0) - kS;
|
||||
kD *= 1.0 - metallic;
|
||||
|
||||
vec3 nominator = NDF * G * F;
|
||||
float denominator = 4.0 * max(dot(normal, V), 0.0) * max(dot(normal, L), 0.0) + 0.001;
|
||||
vec3 specular = nominator / denominator;
|
||||
|
||||
float NdotL = max(dot(normal, L), 0.0);
|
||||
vec3 Lo = (kD * albedo / PI + specular) * radiance * NdotL;
|
||||
|
||||
vec3 ambient = ambientLighting(normal, V, F0, albedo, metallic, roughness, 1);
|
||||
|
||||
int debugLayer;
|
||||
float shadow = ShadowCalculation(worldPos, normal, debugLayer);
|
||||
|
||||
vec3 color = (1-shadow)*Lo + ambient;
|
||||
imageStore(gBaseColor, pixelLocation, encodeRGBM(color));
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
#version 450 core
|
||||
|
||||
layout (location = 0) out vec4 gBaseColor;
|
||||
layout (location = 1) out vec3 gNormal;
|
||||
layout (location = 2) out vec3 gPosition;
|
||||
layout (location = 3) out vec2 gMetallicRoughness;
|
||||
|
||||
in vec2 TexCoords;
|
||||
in vec3 WorldPos;
|
||||
in vec3 Normal;
|
||||
|
||||
// material parameters
|
||||
uniform vec3 albedo;
|
||||
uniform float metallic;
|
||||
uniform float roughness;
|
||||
|
||||
void main()
|
||||
{
|
||||
gBaseColor = vec4(albedo, 1);
|
||||
gPosition = WorldPos;
|
||||
gNormal = normalize(Normal);
|
||||
gMetallicRoughness = vec2(metallic,roughness);
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
#version 330 core
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec3 aNormal;
|
||||
layout (location = 2) in vec2 aTexCoords;
|
||||
|
||||
out vec2 TexCoords;
|
||||
out vec3 WorldPos;
|
||||
out vec3 Normal;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
uniform mat4 projection;
|
||||
|
||||
void main()
|
||||
{
|
||||
TexCoords = aTexCoords;
|
||||
WorldPos = vec3(model * vec4(aPos, 1.0));
|
||||
Normal = mat3(model) * aNormal;
|
||||
|
||||
gl_Position = projection * view * vec4(WorldPos, 1.0);
|
||||
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
#version 450 core
|
||||
out vec4 FragColor;
|
||||
in vec3 WorldPos;
|
||||
|
||||
uniform samplerCube environmentMap;
|
||||
uniform float exposure = 1;
|
||||
|
||||
vec3 ACESToneMapping(vec3 color)
|
||||
{
|
||||
const float A = 2.51;
|
||||
const float B = 0.03;
|
||||
const float C = 2.43;
|
||||
const float D = 0.59;
|
||||
const float E = 0.14;
|
||||
return (color * (A * color + B)) / (color * (C * color + D) + E);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 color = texture(environmentMap, WorldPos).rgb;
|
||||
|
||||
// HDR tonemap
|
||||
//envColor = envColor / (envColor + vec3(1.0));
|
||||
|
||||
color *= exposure;
|
||||
color = ACESToneMapping(color);
|
||||
|
||||
// gamma correct
|
||||
color = pow(color, vec3(1.0/2.2));
|
||||
|
||||
FragColor = vec4(color, 1.0);
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
#version 450 core
|
||||
layout (location = 0) in vec3 aPos;
|
||||
|
||||
uniform mat4 projection;
|
||||
uniform mat4 view;
|
||||
|
||||
out vec3 WorldPos;
|
||||
|
||||
void main()
|
||||
{
|
||||
WorldPos = aPos;
|
||||
|
||||
mat4 rotView = mat4(mat3(view));
|
||||
vec4 clipPos = projection * rotView * vec4(WorldPos, 1.0);
|
||||
|
||||
gl_Position = clipPos.xyww;
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
#include <MainWindow.h>
|
||||
#include "ModelWorld.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
MainWindow::instance().initialize();
|
||||
return MainWindow::instance().exec(std::make_unique<ModelWorld>());
|
||||
}
|
|
@ -1,156 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>16.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectGuid>{8013f6a0-c953-415b-a48d-f425e63ead09}</ProjectGuid>
|
||||
<RootNamespace>Exp1</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)ToyEngine\include;$(SolutionDir)ToyEngine\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
<LanguageStandard_C>stdc17</LanguageStandard_C>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)ToyEngine\include;$(SolutionDir)ToyEngine\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
<LanguageStandard_C>stdc17</LanguageStandard_C>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)ToyEngine\include;$(SolutionDir)ToyEngine\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
<LanguageStandard_C>stdc17</LanguageStandard_C>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)ToyEngine\include;$(SolutionDir)ToyEngine\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
<LanguageStandard_C>stdc17</LanguageStandard_C>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Exp1.cpp" />
|
||||
<ClCompile Include="ModelWorld.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ToyEngine\ToyEngine.vcxproj">
|
||||
<Project>{65d6ee2b-fffa-4ef6-8042-9ca7a0f8e67e}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="ModelWorld.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
|
@ -1,30 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="源文件">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="头文件">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="资源文件">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Exp1.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ModelWorld.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="ModelWorld.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -1,58 +0,0 @@
|
|||
#include "ModelWorld.h"
|
||||
#include <RenderingSystem.h>
|
||||
|
||||
ModelWorld::ModelWorld()
|
||||
{
|
||||
light.lightDirection = glm::normalize(glm::vec3((cos(lightPitch) * cos(lightYaw)), (sin(lightPitch)), (cos(lightPitch) * sin(lightYaw))));
|
||||
light.radiance = 3.f * lightColor;
|
||||
RenderingSystem::instance().exposure = 0.45f;
|
||||
|
||||
model = std::make_shared<Actor>("Models/David_Brown_25D_tractor_SF/David_Brown_25D_tractor_SF.obj");
|
||||
model->setPosition({ 0,0,0 });
|
||||
addActor(model);
|
||||
|
||||
camera.Position = { 0,10,20 };
|
||||
}
|
||||
|
||||
void ModelWorld::cursorPosCallback(GLFWwindow* window, double xpos, double ypos)
|
||||
{
|
||||
static bool firstMouse = true;
|
||||
static float lastX;
|
||||
static float lastY;
|
||||
|
||||
float xoffset = xpos - lastX;
|
||||
float yoffset = lastY - ypos;
|
||||
|
||||
lastX = xpos;
|
||||
lastY = ypos;
|
||||
|
||||
if (firstMouse)
|
||||
{
|
||||
firstMouse = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_RIGHT) == GLFW_PRESS)
|
||||
camera.processMouseMovement(xoffset, yoffset);
|
||||
}
|
||||
|
||||
void ModelWorld::scrollCallback(GLFWwindow* window, double xoffset, double yoffset)
|
||||
{
|
||||
camera.processMouseScroll(yoffset);
|
||||
}
|
||||
|
||||
void ModelWorld::processInput(GLFWwindow* window, float deltaTime)
|
||||
{
|
||||
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
||||
camera.processKeyboard(FORWARD, deltaTime);
|
||||
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
||||
camera.processKeyboard(BACKWARD, deltaTime);
|
||||
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS)
|
||||
camera.processKeyboard(LEFT, deltaTime);
|
||||
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)
|
||||
camera.processKeyboard(RIGHT, deltaTime);
|
||||
if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS)
|
||||
camera.processKeyboard(UP, deltaTime);
|
||||
if (glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS)
|
||||
camera.processKeyboard(DOWN, deltaTime);
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
#pragma once
|
||||
#include <World.h>
|
||||
|
||||
class ModelWorld : public World
|
||||
{
|
||||
public:
|
||||
ModelWorld();
|
||||
virtual void cursorPosCallback(GLFWwindow* window, double xpos, double ypos) override;
|
||||
virtual void scrollCallback(GLFWwindow* window, double xoffset, double yoffset) override;
|
||||
virtual void processInput(GLFWwindow* window, float deltaTime) override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<Actor> model;
|
||||
|
||||
glm::vec3 lightColor = glm::normalize(glm::vec3(0.7529, 0.7450, 0.6784));
|
||||
float lightYaw = glm::radians(80.f);
|
||||
float lightPitch = glm::radians(105.f);
|
||||
};
|
||||
|
Before Width: | Height: | Size: 4.3 MiB |
|
@ -1,14 +0,0 @@
|
|||
# Blender MTL File: 'None'
|
||||
# Material Count: 1
|
||||
|
||||
newmtl David_Brown_25D_tractor
|
||||
Ns 0.000000
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 1.000000 1.000000 1.000000
|
||||
Ks 0.000000 0.000000 0.000000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.450000
|
||||
d 1.000000
|
||||
illum 1
|
||||
map_Bump david_brown_25d_tractor_Normal Map from Mesh.jpg
|
||||
map_Kd David_Brown_25D_tractor.jpg
|
Before Width: | Height: | Size: 378 KiB |
|
@ -1,116 +0,0 @@
|
|||
#version 450 core
|
||||
|
||||
layout(local_size_x = 8, local_size_y = 8) in;
|
||||
layout(rg16f, binding = 0) uniform image2D brdfLUT;
|
||||
|
||||
const float PI = 3.14159265359;
|
||||
// ----------------------------------------------------------------------------
|
||||
// http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html
|
||||
// efficient VanDerCorpus calculation.
|
||||
float RadicalInverse_VdC(uint bits)
|
||||
{
|
||||
bits = (bits << 16u) | (bits >> 16u);
|
||||
bits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u);
|
||||
bits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u);
|
||||
bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u);
|
||||
bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u);
|
||||
return float(bits) * 2.3283064365386963e-10; // / 0x100000000
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
vec2 Hammersley(uint i, uint N)
|
||||
{
|
||||
return vec2(float(i)/float(N), RadicalInverse_VdC(i));
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
vec3 ImportanceSampleGGX(vec2 Xi, vec3 N, float roughness)
|
||||
{
|
||||
float a = roughness*roughness;
|
||||
|
||||
float phi = 2.0 * PI * Xi.x;
|
||||
float cosTheta = sqrt((1.0 - Xi.y) / (1.0 + (a*a - 1.0) * Xi.y));
|
||||
float sinTheta = sqrt(1.0 - cosTheta*cosTheta);
|
||||
|
||||
// from spherical coordinates to cartesian coordinates - halfway vector
|
||||
vec3 H;
|
||||
H.x = cos(phi) * sinTheta;
|
||||
H.y = sin(phi) * sinTheta;
|
||||
H.z = cosTheta;
|
||||
|
||||
// from tangent-space H vector to world-space sample vector
|
||||
vec3 up = abs(N.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0);
|
||||
vec3 tangent = normalize(cross(up, N));
|
||||
vec3 bitangent = cross(N, tangent);
|
||||
|
||||
vec3 sampleVec = tangent * H.x + bitangent * H.y + N * H.z;
|
||||
return normalize(sampleVec);
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
float GeometrySchlickGGX(float NdotV, float roughness)
|
||||
{
|
||||
// note that we use a different k for IBL
|
||||
float a = roughness;
|
||||
float k = (a * a) / 2.0;
|
||||
|
||||
float nom = NdotV;
|
||||
float denom = NdotV * (1.0 - k) + k;
|
||||
|
||||
return nom / denom;
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness)
|
||||
{
|
||||
float NdotV = max(dot(N, V), 0.0);
|
||||
float NdotL = max(dot(N, L), 0.0);
|
||||
float ggx2 = GeometrySchlickGGX(NdotV, roughness);
|
||||
float ggx1 = GeometrySchlickGGX(NdotL, roughness);
|
||||
|
||||
return ggx1 * ggx2;
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
vec2 IntegrateBRDF(float NdotV, float roughness)
|
||||
{
|
||||
vec3 V;
|
||||
V.x = sqrt(1.0 - NdotV*NdotV);
|
||||
V.y = 0.0;
|
||||
V.z = NdotV;
|
||||
|
||||
float A = 0.0;
|
||||
float B = 0.0;
|
||||
|
||||
vec3 N = vec3(0.0, 0.0, 1.0);
|
||||
|
||||
const uint SAMPLE_COUNT = 1024u;
|
||||
for(uint i = 0u; i < SAMPLE_COUNT; ++i)
|
||||
{
|
||||
// generates a sample vector that's biased towards the
|
||||
// preferred alignment direction (importance sampling).
|
||||
vec2 Xi = Hammersley(i, SAMPLE_COUNT);
|
||||
vec3 H = ImportanceSampleGGX(Xi, N, roughness);
|
||||
vec3 L = normalize(2.0 * dot(V, H) * H - V);
|
||||
|
||||
float NdotL = max(L.z, 0.0);
|
||||
float NdotH = max(H.z, 0.0);
|
||||
float VdotH = max(dot(V, H), 0.0);
|
||||
|
||||
if(NdotL > 0.0)
|
||||
{
|
||||
float G = GeometrySmith(N, V, L, roughness);
|
||||
float G_Vis = (G * VdotH) / (NdotH * NdotV);
|
||||
float Fc = pow(1.0 - VdotH, 5.0);
|
||||
|
||||
A += (1.0 - Fc) * G_Vis;
|
||||
B += Fc * G_Vis;
|
||||
}
|
||||
}
|
||||
A /= float(SAMPLE_COUNT);
|
||||
B /= float(SAMPLE_COUNT);
|
||||
return vec2(A, B);
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
void main()
|
||||
{
|
||||
uvec2 pixelLocation = gl_GlobalInvocationID.xy;
|
||||
vec2 texCoords = (vec2(pixelLocation)+vec2(0.5))/vec2(imageSize(brdfLUT));
|
||||
vec2 integratedBRDF = IntegrateBRDF(texCoords.x, texCoords.y);
|
||||
imageStore(brdfLUT, ivec2(pixelLocation), vec4(integratedBRDF,0,0));
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
#version 450 core
|
||||
out vec4 FragColor;
|
||||
in vec3 WorldPos;
|
||||
|
||||
uniform sampler2D equirectangularMap;
|
||||
|
||||
const vec2 invAtan = vec2(0.1591, 0.3183);
|
||||
vec2 SampleSphericalMap(vec3 v)
|
||||
{
|
||||
vec2 uv = vec2(atan(v.z, v.x), asin(v.y));
|
||||
uv *= invAtan;
|
||||
uv += 0.5;
|
||||
return uv;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 uv = SampleSphericalMap(normalize(WorldPos));
|
||||
vec3 color = texture(equirectangularMap, uv).rgb;
|
||||
|
||||
FragColor = vec4(color, 1.0);
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
#version 450 core
|
||||
layout (location = 0) in vec3 aPos;
|
||||
|
||||
out vec3 WorldPos;
|
||||
|
||||
uniform mat4 projection;
|
||||
uniform mat4 view;
|
||||
|
||||
void main()
|
||||
{
|
||||
WorldPos = aPos;
|
||||
gl_Position = projection * view * vec4(WorldPos, 1.0);
|
||||
}
|
|
@ -1,107 +0,0 @@
|
|||
#version 450 core
|
||||
out vec4 FragColor;
|
||||
in vec3 WorldPos;
|
||||
|
||||
uniform samplerCube environmentMap;
|
||||
uniform float roughness;
|
||||
|
||||
const float PI = 3.14159265359;
|
||||
// ----------------------------------------------------------------------------
|
||||
float DistributionGGX(vec3 N, vec3 H, float roughness)
|
||||
{
|
||||
float a = roughness*roughness;
|
||||
float a2 = a*a;
|
||||
float NdotH = max(dot(N, H), 0.0);
|
||||
float NdotH2 = NdotH*NdotH;
|
||||
|
||||
float nom = a2;
|
||||
float denom = (NdotH2 * (a2 - 1.0) + 1.0);
|
||||
denom = PI * denom * denom;
|
||||
|
||||
return nom / denom;
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
// http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html
|
||||
// efficient VanDerCorpus calculation.
|
||||
float RadicalInverse_VdC(uint bits)
|
||||
{
|
||||
bits = (bits << 16u) | (bits >> 16u);
|
||||
bits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u);
|
||||
bits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u);
|
||||
bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u);
|
||||
bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u);
|
||||
return float(bits) * 2.3283064365386963e-10; // / 0x100000000
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
vec2 Hammersley(uint i, uint N)
|
||||
{
|
||||
return vec2(float(i)/float(N), RadicalInverse_VdC(i));
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
vec3 ImportanceSampleGGX(vec2 Xi, vec3 N, float roughness)
|
||||
{
|
||||
float a = roughness*roughness;
|
||||
|
||||
float phi = 2.0 * PI * Xi.x;
|
||||
float cosTheta = sqrt((1.0 - Xi.y) / (1.0 + (a*a - 1.0) * Xi.y));
|
||||
float sinTheta = sqrt(1.0 - cosTheta*cosTheta);
|
||||
|
||||
// from spherical coordinates to cartesian coordinates - halfway vector
|
||||
vec3 H;
|
||||
H.x = cos(phi) * sinTheta;
|
||||
H.y = sin(phi) * sinTheta;
|
||||
H.z = cosTheta;
|
||||
|
||||
// from tangent-space H vector to world-space sample vector
|
||||
vec3 up = abs(N.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0);
|
||||
vec3 tangent = normalize(cross(up, N));
|
||||
vec3 bitangent = cross(N, tangent);
|
||||
|
||||
vec3 sampleVec = tangent * H.x + bitangent * H.y + N * H.z;
|
||||
return normalize(sampleVec);
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
void main()
|
||||
{
|
||||
vec3 N = normalize(WorldPos);
|
||||
|
||||
// make the simplyfying assumption that V equals R equals the normal
|
||||
vec3 R = N;
|
||||
vec3 V = R;
|
||||
|
||||
const uint SAMPLE_COUNT = 1024u;
|
||||
vec3 prefilteredColor = vec3(0.0);
|
||||
float totalWeight = 0.0;
|
||||
|
||||
for(uint i = 0u; i < SAMPLE_COUNT; ++i)
|
||||
{
|
||||
// generates a sample vector that's biased towards the preferred alignment direction (importance sampling).
|
||||
vec2 Xi = Hammersley(i, SAMPLE_COUNT);
|
||||
vec3 H = ImportanceSampleGGX(Xi, N, roughness);
|
||||
vec3 L = normalize(2.0 * dot(V, H) * H - V);
|
||||
|
||||
float NdotL = max(dot(N, L), 0.0);
|
||||
if(NdotL > 0.0)
|
||||
{
|
||||
// sample from the environment's mip level based on roughness/pdf
|
||||
float D = DistributionGGX(N, H, roughness);
|
||||
float NdotH = max(dot(N, H), 0.0);
|
||||
float HdotV = max(dot(H, V), 0.0);
|
||||
float pdf = D * NdotH / (4.0 * HdotV) + 0.0001;
|
||||
|
||||
//float resolution = 512.0; // resolution of source cubemap (per face)
|
||||
float resolution = float(textureSize(environmentMap,0).x); // resolution of source cubemap (per face)
|
||||
float saTexel = 4.0 * PI / (6.0 * resolution * resolution);
|
||||
float saSample = 1.0 / (float(SAMPLE_COUNT) * pdf + 0.0001);
|
||||
|
||||
float mipLevel = roughness == 0.0 ? 0.0 : 0.5 * log2(saSample / saTexel);
|
||||
|
||||
prefilteredColor += textureLod(environmentMap, L, mipLevel).rgb * NdotL;
|
||||
totalWeight += NdotL;
|
||||
}
|
||||
}
|
||||
|
||||
prefilteredColor = prefilteredColor / totalWeight;
|
||||
|
||||
FragColor = vec4(prefilteredColor, 1.0);
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
#version 450 core
|
||||
|
||||
layout (location = 4) out vec4 gDebug;
|
||||
|
||||
in vec2 TexCoords;
|
||||
in vec3 WorldPos;
|
||||
in vec3 Normal;
|
||||
|
||||
uniform vec3 color;
|
||||
|
||||
void main()
|
||||
{
|
||||
gDebug = vec4(color,1);
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
#version 330 core
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec3 aNormal;
|
||||
layout (location = 2) in vec2 aTexCoords;
|
||||
|
||||
out vec2 TexCoords;
|
||||
out vec3 WorldPos;
|
||||
out vec3 Normal;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
uniform mat4 projection;
|
||||
|
||||
void main()
|
||||
{
|
||||
TexCoords = aTexCoords;
|
||||
WorldPos = vec3(model * vec4(aPos, 1.0));
|
||||
Normal = mat3(model) * aNormal;
|
||||
|
||||
gl_Position = projection * view * vec4(WorldPos, 1.0);
|
||||
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
#version 450 core
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
in vec2 TexCoords;
|
||||
|
||||
uniform sampler2D gBaseColor;
|
||||
uniform sampler2D gDebug;
|
||||
uniform float exposure = 1;
|
||||
uniform bool showDebug = false;
|
||||
|
||||
vec3 ACESToneMapping(vec3 color)
|
||||
{
|
||||
const float A = 2.51;
|
||||
const float B = 0.03;
|
||||
const float C = 2.43;
|
||||
const float D = 0.59;
|
||||
const float E = 0.14;
|
||||
return (color * (A * color + B)) / (color * (C * color + D) + E);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 rgbm = texture(gBaseColor, TexCoords);
|
||||
vec4 debug = texture(gDebug, TexCoords);
|
||||
if(rgbm.a==0 && (showDebug ? debug.a==0 : true))
|
||||
{
|
||||
//FragColor = vec4(1,0,0,1);
|
||||
//return;
|
||||
discard;
|
||||
}
|
||||
vec3 color = 8 * rgbm.rgb * rgbm.a;
|
||||
|
||||
color *= exposure;
|
||||
color = ACESToneMapping(color);
|
||||
|
||||
//color = color / (color + vec3(1.0));
|
||||
color = pow(color, vec3(1.0/2.2));
|
||||
FragColor = vec4(color, 1.0);
|
||||
if(showDebug)
|
||||
FragColor = mix(FragColor, debug, debug.a);
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
#version 450 core
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec2 aTexCoords;
|
||||
|
||||
out vec2 TexCoords;
|
||||
|
||||
void main()
|
||||
{
|
||||
TexCoords = aTexCoords;
|
||||
gl_Position = vec4(aPos, 1.0);
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
#version 450 core
|
||||
out vec4 FragColor;
|
||||
in vec3 WorldPos;
|
||||
|
||||
uniform samplerCube environmentMap;
|
||||
|
||||
const float PI = 3.14159265359;
|
||||
|
||||
void main()
|
||||
{
|
||||
// The world vector acts as the normal of a tangent surface
|
||||
// from the origin, aligned to WorldPos. Given this normal, calculate all
|
||||
// incoming radiance of the environment. The result of this radiance
|
||||
// is the radiance of light coming from -Normal direction, which is what
|
||||
// we use in the PBR shader to sample irradiance.
|
||||
vec3 N = normalize(WorldPos);
|
||||
|
||||
vec3 irradiance = vec3(0.0);
|
||||
|
||||
// tangent space calculation from origin point
|
||||
vec3 up = vec3(0.0, 1.0, 0.0);
|
||||
vec3 right = normalize(cross(up, N));
|
||||
up = normalize(cross(N, right));
|
||||
|
||||
float sampleDelta = 0.025;
|
||||
float nrSamples = 0.0;
|
||||
for(float phi = 0.0; phi < 2.0 * PI; phi += sampleDelta)
|
||||
{
|
||||
for(float theta = 0.0; theta < 0.5 * PI; theta += sampleDelta)
|
||||
{
|
||||
// spherical to cartesian (in tangent space)
|
||||
vec3 tangentSample = vec3(sin(theta) * cos(phi), sin(theta) * sin(phi), cos(theta));
|
||||
// tangent space to world
|
||||
vec3 sampleVec = tangentSample.x * right + tangentSample.y * up + tangentSample.z * N;
|
||||
|
||||
irradiance += texture(environmentMap, sampleVec).rgb * cos(theta) * sin(theta);
|
||||
nrSamples++;
|
||||
}
|
||||
}
|
||||
irradiance = PI * irradiance * (1.0 / float(nrSamples));
|
||||
|
||||
FragColor = vec4(irradiance, 1.0);
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
#version 450 core
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec3 aNormal;
|
||||
layout (location = 2) in vec2 aTexCoords;
|
||||
layout (location = 3) in ivec4 boneIds;
|
||||
layout (location = 4) in vec4 weights;
|
||||
|
||||
out vec2 TexCoords;
|
||||
out vec3 WorldPos;
|
||||
out vec3 Normal;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
uniform mat4 projection;
|
||||
|
||||
const int MAX_BONES = 100;
|
||||
const int MAX_BONE_INFLUENCE = 4;
|
||||
layout (std140, binding = 1) uniform FinalBonesMatrices
|
||||
{
|
||||
mat4 finalBonesMatrices[MAX_BONES];
|
||||
};
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 totalPosition = vec4(0.0f);
|
||||
vec3 totalNormal = vec3(0);
|
||||
int boneCount = 0;
|
||||
for(int i = 0 ; i < MAX_BONE_INFLUENCE ; i++)
|
||||
{
|
||||
if(boneIds[i] == -1)
|
||||
continue;
|
||||
if(boneIds[i] >= MAX_BONES)
|
||||
{
|
||||
totalPosition = vec4(aPos,1.0f);
|
||||
break;
|
||||
}
|
||||
boneCount++;
|
||||
vec4 localPosition = finalBonesMatrices[boneIds[i]] * vec4(aPos,1.0f);
|
||||
totalPosition += localPosition * weights[i];
|
||||
vec3 localNormal = mat3(finalBonesMatrices[boneIds[i]]) * aNormal;
|
||||
totalNormal += localNormal * weights[i];
|
||||
}
|
||||
|
||||
if(boneCount == 0)
|
||||
{
|
||||
totalPosition = vec4(aPos, 1);
|
||||
totalNormal = vec3(aNormal);
|
||||
}
|
||||
|
||||
TexCoords = aTexCoords;
|
||||
WorldPos = vec3(model * totalPosition);
|
||||
Normal = mat3(model) * totalNormal;
|
||||
|
||||
gl_Position = projection * view * vec4(WorldPos, 1.0);
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
#version 450 core
|
||||
|
||||
uniform sampler2D texture_basecolor;
|
||||
|
||||
in vec2 TexCoords;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 baseColor = texture(texture_basecolor, TexCoords);
|
||||
if(baseColor.a<0.4)
|
||||
discard;
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
#version 450 core
|
||||
|
||||
layout(triangles, invocations = 5) in;
|
||||
layout(triangle_strip, max_vertices = 3) out;
|
||||
|
||||
layout (std140, binding = 0) uniform LightSpaceMatrices
|
||||
{
|
||||
mat4 lightSpaceMatrices[16];
|
||||
};
|
||||
|
||||
in vec2 vTexCoords[];
|
||||
out vec2 TexCoords;
|
||||
|
||||
void main()
|
||||
{
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
TexCoords = vTexCoords[i];
|
||||
gl_Position = lightSpaceMatrices[gl_InvocationID] * gl_in[i].gl_Position;
|
||||
gl_Layer = gl_InvocationID;
|
||||
EmitVertex();
|
||||
}
|
||||
EndPrimitive();
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
#version 450 core
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec3 aNormal;
|
||||
layout (location = 2) in vec2 aTexCoords;
|
||||
layout (location = 3) in ivec4 boneIds;
|
||||
layout (location = 4) in vec4 weights;
|
||||
|
||||
out vec2 vTexCoords;
|
||||
|
||||
uniform mat4 model;
|
||||
|
||||
const int MAX_BONES = 100;
|
||||
const int MAX_BONE_INFLUENCE = 4;
|
||||
layout (std140, binding = 1) uniform FinalBonesMatrices
|
||||
{
|
||||
mat4 finalBonesMatrices[MAX_BONES];
|
||||
};
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 totalPosition = vec4(0.0f);
|
||||
vec3 totalNormal = vec3(0);
|
||||
int boneCount = 0;
|
||||
for(int i = 0 ; i < MAX_BONE_INFLUENCE ; i++)
|
||||
{
|
||||
if(boneIds[i] == -1)
|
||||
continue;
|
||||
if(boneIds[i] >= MAX_BONES)
|
||||
{
|
||||
totalPosition = vec4(aPos,1.0f);
|
||||
break;
|
||||
}
|
||||
boneCount++;
|
||||
vec4 localPosition = finalBonesMatrices[boneIds[i]] * vec4(aPos,1.0f);
|
||||
totalPosition += localPosition * weights[i];
|
||||
vec3 localNormal = mat3(finalBonesMatrices[boneIds[i]]) * aNormal;
|
||||
totalNormal += localNormal * weights[i];
|
||||
}
|
||||
|
||||
if(boneCount == 0)
|
||||
{
|
||||
totalPosition = vec4(aPos, 1);
|
||||
totalNormal = vec3(aNormal);
|
||||
}
|
||||
|
||||
vTexCoords = aTexCoords;
|
||||
gl_Position = model * totalPosition;
|
||||
}
|
|
@ -1,241 +0,0 @@
|
|||
#version 450 core
|
||||
|
||||
layout (local_size_x = 8, local_size_y = 8) in;
|
||||
|
||||
layout(rgba8, binding = 0) uniform image2D gBaseColor;
|
||||
uniform sampler2D gNormal;
|
||||
uniform sampler2D gPosition;
|
||||
uniform sampler2D gMetallicRoughness;
|
||||
uniform sampler2DArray gShadowMap;
|
||||
|
||||
uniform samplerCube irradianceMap;
|
||||
uniform samplerCube prefilterMap;
|
||||
uniform sampler2D brdfLUT;
|
||||
|
||||
layout (std140, binding = 0) uniform LightSpaceMatrices
|
||||
{
|
||||
mat4 lightSpaceMatrices[16];
|
||||
};
|
||||
uniform mat4 view;
|
||||
uniform float farPlane;
|
||||
uniform float shadowCascadePlaneDistances[16];
|
||||
uniform float shadowBiases[16];
|
||||
uniform int shadowCascadeCount;
|
||||
uniform float shadowBlendRatio;
|
||||
|
||||
uniform vec3 mainLightDirection;
|
||||
uniform vec3 mainLightRadiance;
|
||||
|
||||
uniform vec3 camPos;
|
||||
|
||||
const float PI = 3.14159265359;
|
||||
|
||||
float DistributionGGX(vec3 N, vec3 H, float roughness)
|
||||
{
|
||||
float a = roughness*roughness;
|
||||
float a2 = a*a;
|
||||
float NdotH = max(dot(N, H), 0.0);
|
||||
float NdotH2 = NdotH*NdotH;
|
||||
|
||||
float nom = a2;
|
||||
float denom = (NdotH2 * (a2 - 1.0) + 1.0);
|
||||
denom = PI * denom * denom;
|
||||
|
||||
return nom / denom;
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
float GeometrySchlickGGX(float NdotV, float roughness)
|
||||
{
|
||||
float r = (roughness + 1.0);
|
||||
float k = (r*r) / 8.0;
|
||||
|
||||
float nom = NdotV;
|
||||
float denom = NdotV * (1.0 - k) + k;
|
||||
|
||||
return nom / denom;
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness)
|
||||
{
|
||||
float NdotV = max(dot(N, V), 0.0);
|
||||
float NdotL = max(dot(N, L), 0.0);
|
||||
float ggx2 = GeometrySchlickGGX(NdotV, roughness);
|
||||
float ggx1 = GeometrySchlickGGX(NdotL, roughness);
|
||||
|
||||
return ggx1 * ggx2;
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
vec3 fresnelSchlick(float cosTheta, vec3 F0)
|
||||
{
|
||||
return F0 + (1.0 - F0) * pow(1.0 - cosTheta, 5.0);
|
||||
}
|
||||
vec3 fresnelSchlickRoughness(float cosTheta, vec3 F0, float roughness)
|
||||
{
|
||||
return F0 + (max(vec3(1.0 - roughness), F0) - F0) * pow(1.0 - cosTheta, 5.0);
|
||||
}
|
||||
|
||||
vec3 ambientLighting(vec3 N, vec3 V, vec3 F0, vec3 albedo, float metallic, float roughness, float ao)
|
||||
{
|
||||
// ambient lighting (we now use IBL as the ambient term)
|
||||
vec3 F = fresnelSchlickRoughness(clamp(dot(N, V),0.,1.), F0, roughness);
|
||||
|
||||
vec3 kS = F;
|
||||
vec3 kD = 1.0 - kS;
|
||||
kD *= 1.0 - metallic;
|
||||
|
||||
vec3 irradiance = texture(irradianceMap, N).rgb;
|
||||
vec3 diffuse = irradiance * albedo;
|
||||
|
||||
// sample both the pre-filter map and the BRDF lut and combine them together as per the Split-Sum approximation to get the IBL specular part.
|
||||
const float MAX_REFLECTION_LOD = 4.0;
|
||||
vec3 R = reflect(-V, N);
|
||||
vec3 prefilteredColor = textureLod(prefilterMap, R, roughness * MAX_REFLECTION_LOD).rgb;
|
||||
vec2 brdf = texture(brdfLUT, vec2(clamp(dot(N, V),0.,1.), roughness)).rg;
|
||||
vec3 specular = prefilteredColor * (F * brdf.x + brdf.y);
|
||||
|
||||
return (kD * diffuse + specular) * ao;
|
||||
}
|
||||
|
||||
|
||||
const int pcfRadius = 3;
|
||||
float getShadowFromLayer(vec3 fragPosWorldSpace, vec3 normal,int layer)
|
||||
{
|
||||
float normalBias = 1.2*4. /** (1+pcfRadius)*/ * shadowBiases[layer]*max((1.0 - dot(normal, mainLightDirection)), 0.1)/textureSize(gShadowMap, 0).x;
|
||||
normalBias = max(normalBias, 0.05);
|
||||
vec4 fragPosLightSpace = lightSpaceMatrices[layer] * vec4(fragPosWorldSpace+normal*normalBias, 1.0);
|
||||
// perform perspective divide
|
||||
vec3 projCoords = fragPosLightSpace.xyz / fragPosLightSpace.w;
|
||||
// transform to [0,1] range
|
||||
projCoords = projCoords * 0.5 + 0.5;
|
||||
|
||||
// get depth of current fragment from light's perspective
|
||||
float currentDepth = projCoords.z;
|
||||
|
||||
// keep the shadow at 0.0 when outside the far_plane region of the light's frustum.
|
||||
if (currentDepth > 1.0)
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
// PCF
|
||||
float shadow = 0.0;
|
||||
vec2 texelSize = 1.0 / vec2(textureSize(gShadowMap, 0));
|
||||
for(int x = -pcfRadius; x <= pcfRadius; ++x)
|
||||
{
|
||||
for(int y = -pcfRadius; y <= pcfRadius; ++y)
|
||||
{
|
||||
float pcfDepth = texture(gShadowMap, vec3(projCoords.xy + vec2(x, y) * texelSize, layer)).r;
|
||||
shadow += currentDepth > pcfDepth ? 1.0 : 0.0;
|
||||
}
|
||||
}
|
||||
shadow /= (2*pcfRadius+1)*(2*pcfRadius+1);
|
||||
return shadow;
|
||||
}
|
||||
|
||||
float ShadowCalculation(vec3 fragPosWorldSpace, vec3 normal, out int layer)
|
||||
{
|
||||
// select cascade layer
|
||||
vec4 fragPosViewSpace = view * vec4(fragPosWorldSpace, 1.0);
|
||||
float depthValue = abs(fragPosViewSpace.z);
|
||||
|
||||
layer = -1;
|
||||
for (int i = 0; i < shadowCascadeCount; ++i)
|
||||
{
|
||||
if (depthValue < shadowCascadePlaneDistances[i])
|
||||
{
|
||||
layer = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// if (layer == -1)
|
||||
// {
|
||||
// layer = shadowCascadeCount;
|
||||
// }
|
||||
|
||||
float shadow = getShadowFromLayer(fragPosWorldSpace,normal,layer);
|
||||
|
||||
|
||||
float nextLayerBeginDepth = layer==0? (1-shadowBlendRatio)*shadowCascadePlaneDistances[layer]
|
||||
:(1-shadowBlendRatio)*shadowCascadePlaneDistances[layer]+shadowBlendRatio*shadowCascadePlaneDistances[layer-1];
|
||||
if(depthValue > nextLayerBeginDepth)
|
||||
{
|
||||
float shadowNext = getShadowFromLayer(fragPosWorldSpace,normal,layer+1);
|
||||
shadow = mix(shadow,shadowNext, (depthValue-nextLayerBeginDepth)/(shadowCascadePlaneDistances[layer]-nextLayerBeginDepth));
|
||||
}
|
||||
return shadow;
|
||||
}
|
||||
|
||||
|
||||
|
||||
vec4 encodeRGBM(vec3 color)
|
||||
{
|
||||
if(dot(color,color)==0)
|
||||
return vec4(0,0,0,1);
|
||||
vec4 rgbm;
|
||||
float range = 8;
|
||||
color /= range;
|
||||
rgbm.a = clamp(max(max(color.r, color.g), max(color.b, 1e-6)), 0.0, 1.0);
|
||||
rgbm.a = ceil(rgbm.a * 255.0) / 255.0;
|
||||
rgbm.rgb = color / rgbm.a;
|
||||
return rgbm;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 pixelLocation = ivec2(gl_GlobalInvocationID.xy);
|
||||
|
||||
|
||||
//vec3 albedo = pow(texelFetch(gBaseColor, pixelLocation, 0).rgb, vec3(2.2));
|
||||
vec3 albedo = pow(imageLoad(gBaseColor, pixelLocation).rgb, vec3(2.2));
|
||||
float metallic = texelFetch(gMetallicRoughness, pixelLocation, 0).r;
|
||||
float roughness = texelFetch(gMetallicRoughness, pixelLocation, 0).g;
|
||||
|
||||
vec3 worldPos = texelFetch(gPosition, pixelLocation,0).xyz;
|
||||
vec3 normal = texelFetch(gNormal, pixelLocation,0).xyz;
|
||||
|
||||
if(normal==vec3(0))
|
||||
{
|
||||
//vec3 color = mainLightRadiance;
|
||||
//imageStore(gBaseColor, pixelLocation, vec4(color, 1.0));
|
||||
imageStore(gBaseColor, pixelLocation, vec4(0));
|
||||
return;
|
||||
}
|
||||
normal = normalize(normal);
|
||||
|
||||
vec3 V = normalize(camPos - worldPos);
|
||||
|
||||
vec3 F0 = vec3(0.04);
|
||||
F0 = mix(F0, albedo, metallic);
|
||||
|
||||
// calculate light radiance
|
||||
vec3 L = normalize(mainLightDirection);
|
||||
vec3 H = normalize(V + L);
|
||||
//float distance = length(lightPositions[i] - WorldPos);
|
||||
//float attenuation = 1.0 / (distance * distance);
|
||||
vec3 radiance = mainLightRadiance ;//* attenuation;
|
||||
|
||||
// cook-torrance brdf
|
||||
float NDF = DistributionGGX(normal, H, roughness);
|
||||
float G = GeometrySmith(normal, V, L, roughness);
|
||||
vec3 F = fresnelSchlick(clamp(dot(H, V),0.,1.), F0);
|
||||
//F = clamp(F,vec3(0),vec3(1));
|
||||
|
||||
vec3 kS = F;
|
||||
vec3 kD = vec3(1.0) - kS;
|
||||
kD *= 1.0 - metallic;
|
||||
|
||||
vec3 nominator = NDF * G * F;
|
||||
float denominator = 4.0 * max(dot(normal, V), 0.0) * max(dot(normal, L), 0.0) + 0.001;
|
||||
vec3 specular = nominator / denominator;
|
||||
|
||||
float NdotL = max(dot(normal, L), 0.0);
|
||||
vec3 Lo = (kD * albedo / PI + specular) * radiance * NdotL;
|
||||
|
||||
vec3 ambient = ambientLighting(normal, V, F0, albedo, metallic, roughness, 1);
|
||||
|
||||
int debugLayer;
|
||||
float shadow = ShadowCalculation(worldPos, normal, debugLayer);
|
||||
|
||||
vec3 color = (1-shadow)*Lo + ambient;
|
||||
imageStore(gBaseColor, pixelLocation, encodeRGBM(color));
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
#version 450 core
|
||||
|
||||
layout (location = 0) out vec4 gBaseColor;
|
||||
layout (location = 1) out vec3 gNormal;
|
||||
layout (location = 2) out vec3 gPosition;
|
||||
layout (location = 3) out vec2 gMetallicRoughness;
|
||||
|
||||
in vec2 TexCoords;
|
||||
in vec3 WorldPos;
|
||||
in vec3 Normal;
|
||||
|
||||
// material parameters
|
||||
uniform vec3 albedo;
|
||||
uniform float metallic;
|
||||
uniform float roughness;
|
||||
|
||||
void main()
|
||||
{
|
||||
gBaseColor = vec4(albedo, 1);
|
||||
gPosition = WorldPos;
|
||||
gNormal = normalize(Normal);
|
||||
gMetallicRoughness = vec2(metallic,roughness);
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
#version 330 core
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec3 aNormal;
|
||||
layout (location = 2) in vec2 aTexCoords;
|
||||
|
||||
out vec2 TexCoords;
|
||||
out vec3 WorldPos;
|
||||
out vec3 Normal;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
uniform mat4 projection;
|
||||
|
||||
void main()
|
||||
{
|
||||
TexCoords = aTexCoords;
|
||||
WorldPos = vec3(model * vec4(aPos, 1.0));
|
||||
Normal = mat3(model) * aNormal;
|
||||
|
||||
gl_Position = projection * view * vec4(WorldPos, 1.0);
|
||||
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
#version 450 core
|
||||
out vec4 FragColor;
|
||||
in vec3 WorldPos;
|
||||
|
||||
uniform samplerCube environmentMap;
|
||||
uniform float exposure = 1;
|
||||
|
||||
vec3 ACESToneMapping(vec3 color)
|
||||
{
|
||||
const float A = 2.51;
|
||||
const float B = 0.03;
|
||||
const float C = 2.43;
|
||||
const float D = 0.59;
|
||||
const float E = 0.14;
|
||||
return (color * (A * color + B)) / (color * (C * color + D) + E);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 color = texture(environmentMap, WorldPos).rgb;
|
||||
|
||||
// HDR tonemap
|
||||
//envColor = envColor / (envColor + vec3(1.0));
|
||||
|
||||
color *= exposure;
|
||||
color = ACESToneMapping(color);
|
||||
|
||||
// gamma correct
|
||||
color = pow(color, vec3(1.0/2.2));
|
||||
|
||||
FragColor = vec4(color, 1.0);
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
#version 450 core
|
||||
layout (location = 0) in vec3 aPos;
|
||||
|
||||
uniform mat4 projection;
|
||||
uniform mat4 view;
|
||||
|
||||
out vec3 WorldPos;
|
||||
|
||||
void main()
|
||||
{
|
||||
WorldPos = aPos;
|
||||
|
||||
mat4 rotView = mat4(mat3(view));
|
||||
vec4 clipPos = projection * rotView * vec4(WorldPos, 1.0);
|
||||
|
||||
gl_Position = clipPos.xyww;
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
#include <MainWindow.h>
|
||||
#include "ModelWorld.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
MainWindow::instance().initialize();
|
||||
return MainWindow::instance().exec(std::make_unique<ModelWorld>());
|
||||
}
|
|
@ -1,159 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>16.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectGuid>{98e424b3-5b57-4ac2-8a95-79ddbb3472d3}</ProjectGuid>
|
||||
<RootNamespace>Exp2</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)ToyEngine\include;$(SolutionDir)ToyEngine\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
<LanguageStandard_C>stdc17</LanguageStandard_C>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)ToyEngine\include;$(SolutionDir)ToyEngine\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
<LanguageStandard_C>stdc17</LanguageStandard_C>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)ToyEngine\include;$(SolutionDir)ToyEngine\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
<LanguageStandard_C>stdc17</LanguageStandard_C>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)ToyEngine\include;$(SolutionDir)ToyEngine\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
<LanguageStandard_C>stdc17</LanguageStandard_C>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Exp2.cpp" />
|
||||
<ClCompile Include="ModelWorld.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ToyEngine\ToyEngine.vcxproj">
|
||||
<Project>{65d6ee2b-fffa-4ef6-8042-9ca7a0f8e67e}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="ModelWorld.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="ClassDiagram.cd" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
|
@ -1,33 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="源文件">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="头文件">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="资源文件">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Exp2.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ModelWorld.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="ModelWorld.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="ClassDiagram.cd" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -1,76 +0,0 @@
|
|||
#include "ModelWorld.h"
|
||||
#include <RenderingSystem.h>
|
||||
|
||||
ModelWorld::ModelWorld()
|
||||
{
|
||||
light.lightDirection = glm::normalize(glm::vec3((cos(lightPitch) * cos(lightYaw)), (sin(lightPitch)), (cos(lightPitch) * sin(lightYaw))));
|
||||
light.radiance = 3.f * lightColor;
|
||||
RenderingSystem::instance().exposure = 0.45f;
|
||||
camera.Position = { 0,5,10 };
|
||||
|
||||
model = std::make_shared<Actor>("Models/David_Brown_25D_tractor_SF/David_Brown_25D_tractor_SF.obj");
|
||||
model->setPosition({ 0,0,0 });
|
||||
model->setScale(glm::vec3(0.5));
|
||||
addActor(model);
|
||||
}
|
||||
|
||||
void ModelWorld::cursorPosCallback(GLFWwindow* window, double xpos, double ypos)
|
||||
{
|
||||
static bool firstMouse = true;
|
||||
static float lastX;
|
||||
static float lastY;
|
||||
|
||||
float xoffset = xpos - lastX;
|
||||
float yoffset = lastY - ypos;
|
||||
|
||||
lastX = xpos;
|
||||
lastY = ypos;
|
||||
|
||||
if (firstMouse)
|
||||
{
|
||||
firstMouse = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_RIGHT) == GLFW_PRESS)
|
||||
camera.processMouseMovement(xoffset, yoffset);
|
||||
|
||||
if (glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS)
|
||||
{
|
||||
float speed = 0.2f;
|
||||
model->setRotaion(glm::rotate(glm::quat(1, 0, 0, 0),
|
||||
glm::radians(glm::length(glm::vec2(xoffset, yoffset)) * speed), glm::vec3(glm::vec2(-yoffset, xoffset), 0.0)) * model->getRotation());
|
||||
}
|
||||
}
|
||||
|
||||
void ModelWorld::scrollCallback(GLFWwindow* window, double xoffset, double yoffset)
|
||||
{
|
||||
camera.processMouseScroll(yoffset);
|
||||
}
|
||||
|
||||
void ModelWorld::processInput(GLFWwindow* window, float deltaTime)
|
||||
{
|
||||
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
||||
camera.processKeyboard(FORWARD, deltaTime);
|
||||
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
||||
camera.processKeyboard(BACKWARD, deltaTime);
|
||||
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS)
|
||||
camera.processKeyboard(LEFT, deltaTime);
|
||||
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)
|
||||
camera.processKeyboard(RIGHT, deltaTime);
|
||||
if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS)
|
||||
camera.processKeyboard(UP, deltaTime);
|
||||
if (glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS)
|
||||
camera.processKeyboard(DOWN, deltaTime);
|
||||
|
||||
float speed = 10;
|
||||
float d = speed * deltaTime;
|
||||
if (glfwGetKey(window, GLFW_KEY_UP) == GLFW_PRESS)
|
||||
model->setPosition(model->getPosition() + glm::vec3(0, 0, -d));
|
||||
if (glfwGetKey(window, GLFW_KEY_DOWN) == GLFW_PRESS)
|
||||
model->setPosition(model->getPosition() + glm::vec3(0, 0, d));
|
||||
if (glfwGetKey(window, GLFW_KEY_LEFT) == GLFW_PRESS)
|
||||
model->setPosition(model->getPosition() + glm::vec3(-d, 0, 0));
|
||||
if (glfwGetKey(window, GLFW_KEY_RIGHT) == GLFW_PRESS)
|
||||
model->setPosition(model->getPosition() + glm::vec3(d, 0, 0));
|
||||
}
|