1#include "Sea/SeaManager.h"
4#include "Utils/Utils.h"
6#include "Data/ProjectData.h"
7#include "Data/ApplicationState.h"
14 model =
new Model(
"Sea");
15 model->SetupMeshOnGPU();
16 model->mesh->GeneratePlane(256, 120);
17 model->mesh->RecalculateNormals();
26 std::string vertexShaderSource = ReadShaderSourceFile(GetExecutableDir() + PATH_SEPARATOR
"Data" PATH_SEPARATOR
"shaders" PATH_SEPARATOR
"water" PATH_SEPARATOR
"vert.glsl", &tmp);
27 std::string fragmentShaderSource = ReadShaderSourceFile(GetExecutableDir() + PATH_SEPARATOR
"Data" PATH_SEPARATOR
"shaders" PATH_SEPARATOR
"water" PATH_SEPARATOR
"frag.glsl", &tmp);
28 std::string geometryShaderSource = ReadShaderSourceFile(GetExecutableDir() + PATH_SEPARATOR
"Data" PATH_SEPARATOR
"shaders" PATH_SEPARATOR
"water" PATH_SEPARATOR
"geom.glsl", &tmp);
29 shader =
new Shader(vertexShaderSource, fragmentShaderSource, geometryShaderSource);
30 dudvMap =
new Texture2D(GetExecutableDir() + PATH_SEPARATOR
"Data" PATH_SEPARATOR
"textures" PATH_SEPARATOR
"water_dudv.png");
31 normalMap =
new Texture2D(GetExecutableDir() + PATH_SEPARATOR
"Data" PATH_SEPARATOR
"textures" PATH_SEPARATOR
"water_normal.png");
34SeaManager::~SeaManager()
59 alpha = data[
"alpha"];
60 distrotionStrength = data[
"distrotionStrength"];
61 distrotionScale = data[
"distrotionScale"];
62 reflectivity = data[
"reflectivity"];
63 level = data[
"level"];
64 waveSpeed = data[
"waveSpeed"];
65 enabled = data[
"enabled"];
66 color[0] = data[
"color"][
"r"];
67 color[1] = data[
"color"][
"g"];
68 color[2] = data[
"color"][
"b"];
75 dudvMap =
new Texture2D(appState->projectManager->GetResourcePath() + PATH_SEPARATOR + appState->projectManager->GetAsset(data[
"dudvMap"]));
82 normalMap =
new Texture2D(appState->projectManager->GetResourcePath() + PATH_SEPARATOR + appState->projectManager->GetAsset(data[
"normalMap"]));
88 data[
"type"] =
"Sea Settings";
89 data[
"alpha"] = alpha;
90 data[
"distrotionStrength"] = distrotionStrength;
91 data[
"distrotionScale"] = distrotionScale;
92 data[
"reflectivity"] = reflectivity;
93 data[
"level"] = level;
94 data[
"waveSpeed"] = waveSpeed;
95 data[
"enabled"] = enabled;
97 jcolor[
"r"] = color[0];
98 jcolor[
"g"] = color[1];
99 jcolor[
"b"] = color[2];
100 data[
"color"] = jcolor;
101 data[
"dudvMap"] = appState->projectManager->SaveTexture(dudvMap);
102 data[
"normalMap"] = appState->projectManager->SaveTexture(normalMap);
106void SeaManager::Render(
Camera &camera,
LightManager *lights,
void *reflectionTexture,
float time)
109 shader->SetTime(&time);
110 shader->SetUniformf(
"_SeaAlpha", alpha);
111 shader->SetUniformf(
"_SeaDistScale", distrotionScale);
112 shader->SetUniformf(
"_SeaDistStrength", distrotionStrength);
113 shader->SetUniformf(
"_SeaReflectivity", reflectivity);
114 shader->SetUniformf(
"_SeaLevel", level);
115 shader->SetUniformf(
"_SeaWaveSpeed", waveSpeed);
117 glBindTexture(GL_TEXTURE_2D, (GLuint)((uintptr_t)reflectionTexture));
118 shader->SetUniformi(
"_ReflectionTexture", 7);
125 shader->SetUniformi(
"_DuDvMap", 8);
132 shader->SetUniformi(
"_NormalMap", 9);
133 model->position.y = level;
134 model->scale.x = scale;
135 model->scale.z = scale;
137 shader->SetUniform3f(
"_SeaColor", color);
138 glm::mat4 mpv = camera.pv * model->modelMatrix;
140 shader->SetLightCol(lights->color);
141 shader->SetLightPos(lights->position);
145void SeaManager::ShowSettings(
bool *pOpen)
149 ImGui::Begin(
"Sea Setings", pOpen);
150 ImGui::Checkbox(
"Sea Enabled", &enabled);
151 ImGui::DragFloat(
"Sea Level", &level, 0.1f);
152 ImGui::Text(
"Sea Color");
153 ImGui::ColorEdit3(
"##seaColor", color);
154 ImGui::DragFloat(
"Alpha", &alpha, 0.01f, 0, 1);
155 ImGui::DragFloat(
"Scale", &scale, 0.1f);
156 ImGui::DragFloat(
"Reflectvity", &reflectivity, 0.01f, 0, 1);
157 ImGui::DragFloat(
"Distortion Strength", &distrotionStrength, 0.001f, 0, 1);
158 ImGui::DragFloat(
"Distortion Scale", &distrotionScale, 0.001f, 0, 1);
159 ImGui::DragFloat(
"Wave Speed", &waveSpeed, 0.01f, 0, 1);
160 ImGui::Text(
"DuDv Map");
163 if (ImGui::ImageButton((ImTextureID)dudvMap->GetRendererID(), ImVec2(50, 50)))
165 LoadTexture(dudvMap);
168 ImGui::Text(
"Normal Map");
171 if (ImGui::ImageButton((ImTextureID)normalMap->GetRendererID(), ImVec2(50, 50)))
173 LoadTexture(normalMap);
a class to store JSON values