Skip to content

Commit 80090cd

Browse files
committed
Add function MatrixPerspectiveVFovLH and MatrixPerspectiveHFovLH
1 parent 09fd3b5 commit 80090cd

File tree

5 files changed

+69
-1
lines changed

5 files changed

+69
-1
lines changed

src/SHADERed/Objects/FunctionVariableManager.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,23 @@ namespace ed {
167167
matrix = glm::perspectiveFov(45.0f, view[0], view[1], z[0], z[1]);
168168
} break;
169169

170+
case FunctionShaderVariable::MatrixPerspectiveVFovLH: {
171+
float fov = *LoadFloat(var->Arguments, 0);
172+
float* view = LoadFloat(var->Arguments, 1);
173+
float* z = LoadFloat(var->Arguments, 3);
174+
175+
matrix = glm::perspective(fov, view[0] / view[1], z[0], z[1]);
176+
} break;
177+
178+
case FunctionShaderVariable::MatrixPerspectiveHFovLH: {
179+
float* view = LoadFloat(var->Arguments, 1);
180+
float aspect = view[0] / view[1];
181+
float fov = *LoadFloat(var->Arguments, 0) / aspect;
182+
float* z = LoadFloat(var->Arguments, 3);
183+
184+
matrix = glm::perspective(fov, aspect, z[0], z[1]);
185+
} break;
186+
170187
case FunctionShaderVariable::MatrixRotationAxis: {
171188
float* axis = LoadFloat(var->Arguments, 0);
172189
float angle = *LoadFloat(var->Arguments, 3);
@@ -297,6 +314,14 @@ namespace ed {
297314
*LoadFloat(var->Arguments, 2) = 0.1f;
298315
*LoadFloat(var->Arguments, 3) = 100.0f;
299316
break;
317+
case FunctionShaderVariable::MatrixPerspectiveVFovLH:
318+
case FunctionShaderVariable::MatrixPerspectiveHFovLH:
319+
*LoadFloat(var->Arguments, 0) = glm::half_pi<float>();
320+
*LoadFloat(var->Arguments, 1) = 800;
321+
*LoadFloat(var->Arguments, 2) = 600;
322+
*LoadFloat(var->Arguments, 3) = 0.1f;
323+
*LoadFloat(var->Arguments, 4) = 100.0f;
324+
break;
300325
case FunctionShaderVariable::MatrixRotationAxis:
301326
*LoadFloat(var->Arguments, 0) = 1;
302327
break;
@@ -324,6 +349,8 @@ namespace ed {
324349
case FunctionShaderVariable::MatrixOrthographicLH: return 4;
325350
case FunctionShaderVariable::MatrixPerspectiveFovLH: return 4;
326351
case FunctionShaderVariable::MatrixPerspectiveLH: return 4;
352+
case FunctionShaderVariable::MatrixPerspectiveVFovLH: return 5;
353+
case FunctionShaderVariable::MatrixPerspectiveHFovLH: return 5;
327354
case FunctionShaderVariable::MatrixRotationAxis: return 4;
328355
case FunctionShaderVariable::MatrixRotationNormal: return 4;
329356
case FunctionShaderVariable::MatrixRotationRollPitchYaw: return 3;

src/SHADERed/Objects/Names.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ const char* FUNCTION_NAMES[] = {
101101
"MatrixOrthographicLH",
102102
"MatrixPerspectiveFovLH",
103103
"MatrixPerspectiveLH",
104+
"MatrixPerspectiveVFovLH",
105+
"MatrixPerspectiveHFovLH",
104106
"MatrixRotationAxis",
105107
"MatrixRotationNormal",
106108
"MatrixRotationRollPitchYaw",

src/SHADERed/Objects/Names.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ extern const char* TOPOLOGY_ITEM_NAMES[11];
55
extern const char* SYSTEM_VARIABLE_NAMES[22];
66
extern const char* VARIABLE_TYPE_NAMES[15];
77
extern const char* VARIABLE_TYPE_NAMES_GLSL[15];
8-
extern const char* FUNCTION_NAMES[22];
8+
extern const char* FUNCTION_NAMES[24];
99
extern const char* GEOMETRY_NAMES[7];
1010
extern const char* PIPELINE_ITEM_NAMES[8];
1111
extern const char* BLEND_NAMES[20];

src/SHADERed/Objects/ShaderVariable.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ namespace ed {
5353
MatrixOrthographicLH,
5454
MatrixPerspectiveFovLH,
5555
MatrixPerspectiveLH,
56+
MatrixPerspectiveVFovLH,
57+
MatrixPerspectiveHFovLH,
5658
MatrixRotationAxis,
5759
MatrixRotationNormal,
5860
MatrixRotationRollPitchYaw,

src/SHADERed/UI/Tools/VariableValueEdit.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,43 @@ namespace ed {
472472
ImGui::NextColumn();
473473
} break;
474474

475+
case FunctionShaderVariable::MatrixPerspectiveVFovLH:
476+
case FunctionShaderVariable::MatrixPerspectiveHFovLH: {
477+
ImGui::Text("FOV:");
478+
ImGui::NextColumn();
479+
480+
ImGui::PushItemWidth(-1);
481+
float fov = *FunctionVariableManager::LoadFloat(m_var->Arguments, 0);
482+
if (ImGui::SliderAngle(("##fovAngle" + std::string(m_var->Name)).c_str(), &fov, 0, 180))
483+
ret = true;
484+
*FunctionVariableManager::LoadFloat(m_var->Arguments, 0) = fov;
485+
ImGui::NextColumn();
486+
487+
ImGui::Text("View size:");
488+
ImGui::NextColumn();
489+
490+
ImGui::PushItemWidth(-1);
491+
if (ImGui::DragFloat2(("##viewSize" + std::string(m_var->Name)).c_str(), FunctionVariableManager::LoadFloat(m_var->Arguments, 1), 0.01f))
492+
ret = true;
493+
ImGui::NextColumn();
494+
495+
ImGui::Text("Near Z:");
496+
ImGui::NextColumn();
497+
498+
ImGui::PushItemWidth(-1);
499+
if (ImGui::DragFloat(("##nearZ" + std::string(m_var->Name)).c_str(), FunctionVariableManager::LoadFloat(m_var->Arguments, 3), 0.01f))
500+
ret = true;
501+
ImGui::NextColumn();
502+
503+
ImGui::Text("Far Z:");
504+
ImGui::NextColumn();
505+
506+
ImGui::PushItemWidth(-1);
507+
if (ImGui::DragFloat(("##farZ" + std::string(m_var->Name)).c_str(), FunctionVariableManager::LoadFloat(m_var->Arguments, 4), 0.01f))
508+
ret = true;
509+
ImGui::NextColumn();
510+
} break;
511+
475512
case FunctionShaderVariable::MatrixRotationAxis: {
476513
ImGui::Text("Axis:");
477514
ImGui::NextColumn();

0 commit comments

Comments
 (0)