Skip to content

Commit

Permalink
Cleanup shader class
Browse files Browse the repository at this point in the history
  • Loading branch information
saffronjam committed Nov 4, 2021
1 parent 7051c01 commit 60b8bd0
Show file tree
Hide file tree
Showing 27 changed files with 15,879 additions and 120 deletions.
6 changes: 1 addition & 5 deletions Editor/Source/Layers/EditorLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ void EditorLayer::OnAttach()
Ui::Gizmo(selected->Transform(), camera.View(), camera.Projection(), _gizmoControl);
return false;
};

_texture = Texture::Create("Assets/Textures/Milkyway/Milkyway_small.hdr");



App::Instance().Window().GainedFocus += []
{
for (auto& shader : ShaderStore::GetAll())
Expand Down Expand Up @@ -93,7 +90,6 @@ void EditorLayer::OnUi()
ImGui::End();

ImGui::Begin("Editor");
Ui::Image(*_texture);
if (ImGui::RadioButton("Translate", _gizmoControl == GizmoControl::Translate))
{
_gizmoControl = GizmoControl::Translate;
Expand Down
2 changes: 0 additions & 2 deletions Editor/Source/Layers/EditorLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,5 @@ class EditorLayer : public Layer
ViewportPanel _depthViewportPanel;

GizmoControl _gizmoControl = GizmoControl::Translate;

std::shared_ptr<Texture> _texture;
};
}
Binary file added Engine/Assets/Meshes/3d-model.fbx
Binary file not shown.
42 changes: 42 additions & 0 deletions Engine/Assets/Shaders/EquirectangularToCubeMap_c.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "Common_i.hlsl"


Texture2D equirectangularTex : register(t0);
RWTexture2DArray<float> cubemap : register(u0);

SamplerState equirectSampler : register(s0);

float3 GetCubeMapTexCoord(uint3 DTid)
{
float width;
float height;
float elements;
cubemap.GetDimensions(width, height, elements);

float2 st = DTid.xy / float2(width, height);
float2 uv = 2.0 * float2(st.x, 1.0 - st.y) - float2(1.0, 1.0);

float3 ret;
if (DTid.z == 0) ret = float3(1.0, uv.y, -uv.x);
else if (DTid.z == 1) ret = float3(-1.0, uv.y, uv.x);
else if (DTid.z == 2) ret = float3(uv.x, 1.0, -uv.y);
else if (DTid.z == 3) ret = float3(uv.x, -1.0, uv.y);
else if (DTid.z == 4) ret = float3(uv.x, uv.y, 1.0);
else if (DTid.z == 5) ret = float3(-uv.x, uv.y, -1.0);
return normalize(ret);
}

[numthreads(32, 32, 1)]
void main( uint3 DTid : SV_DispatchThreadID )
{
float3 cubeTC = GetCubeMapTexCoord(DTid);

// Calculate sampling coords for equirectangular texture
// https://en.wikipedia.org/wiki/Spherical_coordinate_system#Cartesian_coordinates
float phi = atan2(cubeTC.z, cubeTC.x);
float theta = acos(cubeTC.y);
float2 uv = float2(phi / (2.0 * Pi) + 0.5, theta / Pi);

float4 color = { 0.0, 0.0, 0.0, 0.0 };
cubemap[DTid] = color;
}
8 changes: 8 additions & 0 deletions Engine/Assets/Shaders/MeshShader_p.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ float3 CalculatePointLights(float3 F0, in PBR_Data pbrData, float3 pixelWorldPos
return gammaCorr;
}

const float2 invAtan = float2(0.1591, 0.3183);
float2 SampleSphericalMap(float3 v)
{
float2 uv = float2(atan2(v.z, v.x), asin(v.y));
uv *= invAtan;
uv += 0.5;
return uv;
}

float4 main(PsInput input) : SV_TARGET
{
Expand Down
15,472 changes: 15,472 additions & 0 deletions Engine/Assets/Textures/GrandCanyon_C_YumaPoint/GCanyon_C_YumaPoint_3k.hdr

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[Header]
ICOfile = "GCanyon_C_YumaPoint_Thumb.jpg"
PREVIEWfile = "GCanyon_C_YumaPoint_preview.jpg"
Name = "Grand Canyon C"
Author = "Blochi"
Location = "Grand Canyon"
Comment = "Bright daylight, high altitude, great for airplane renders"
GEOlat = 36.08038998435272
GEOlong = -112.22920417785645
Link = "http://www.hdrlabs.com/sibl/archive.html"
Date = "2008:11:28"
Time = "12:55:00"
Height = 100
North = 0.41

[Background]
BGfile = "GCanyon_C_YumaPoint_8k.jpg"
BGmap = 1
BGu = 0.000000
BGv = 0.000000
BGheight = 4000

[Enviroment]
EVfile = "GCanyon_C_YumaPoint_Env.hdr"
EVmap = 1
EVu = 0.000000
EVv = 0.000000
EVheight = 180
EVmulti = 1.000000
EVgamma = 1.600000

[Reflection]
REFfile = "GCanyon_C_YumaPoint_3k.hdr"
REFmap = 1
REFu = 0.000000
REFv = 0.000000
REFheight = 1600
REFmulti = 1.000000
REFgamma = 1.600000

[Sun]
SUNcolor = 250,247,235
SUNmulti = 1.000000
SUNu = 0.824000
SUNv = 0.376000

2 changes: 1 addition & 1 deletion Engine/Source/Saffron/Graphics/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void Model::OnDebugUi()
ImGui::Begin("Model");
for (auto& cont : _textures)
{
auto type = ModelTextureMapType::Roughness;
auto type = ModelTextureMapType::Albedo;
if (cont[type] != nullptr)
{
Ui::Image(*cont[type]);
Expand Down
1 change: 1 addition & 0 deletions Engine/Source/Saffron/Graphics/ModelStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ auto ModelStore::ImportMaterial(
matTexContainer.emplace(ModelTextureMapType::Albedo, Renderer::WhiteTexture());
}


// Normal map
const auto hasNormalMap = aiMaterial.GetTexture(aiTextureType_NORMALS, 0, &aiTexPath) == AI_SUCCESS;
bool normalMapFallback = !hasNormalMap;
Expand Down
6 changes: 5 additions & 1 deletion Engine/Source/Saffron/Graphics/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Scene::Scene() :
-3.0f,
0.0f
);

constexpr int nBalls = 5;
for (int i = 0; i < nBalls; i++)
{
Expand All @@ -30,7 +31,7 @@ Scene::Scene() :
MaterialDataCBuf{Colors::Red, 0.0f, 0.00f, 1.0f, 0.0f, false}
);
}

_cameraMesh = Model::Create("Sphere.fbx");

_pointLight.Position = Vector3{0.0f, 5.0f, 0.0f};
Expand All @@ -42,6 +43,9 @@ Scene::Scene() :
ViewportResized.Invoke(event);
return false;
};



}

void Scene::OnUpdate(TimeSpan ts)
Expand Down
Loading

0 comments on commit 60b8bd0

Please sign in to comment.