Subtraction and light vizualization
This commit is contained in:
parent
5bf1345de9
commit
8b08b92494
|
@ -28,7 +28,7 @@
|
|||
<ClCompile Include="imgui\imgui_widgets.cpp" />
|
||||
<ClCompile Include="src\Application.cpp" />
|
||||
<ClCompile Include="src\Camera.cpp" />
|
||||
<ClCompile Include="src\Primitive.cpp" />
|
||||
<ClCompile Include="src\Objects.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="imgui\.editorconfig" />
|
||||
|
@ -47,7 +47,7 @@
|
|||
<ClInclude Include="imgui\imstb_textedit.h" />
|
||||
<ClInclude Include="imgui\imstb_truetype.h" />
|
||||
<ClInclude Include="include\Camera.h" />
|
||||
<ClInclude Include="include\Primitive.h" />
|
||||
<ClInclude Include="include\Objects.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Text Include="imgui\LICENSE.txt" />
|
||||
|
|
|
@ -48,7 +48,7 @@
|
|||
<ClCompile Include="imgui\backends\imgui_impl_opengl3.cpp">
|
||||
<Filter>imgui</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Primitive.cpp">
|
||||
<ClCompile Include="src\Objects.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
|
@ -97,7 +97,7 @@
|
|||
<ClInclude Include="imgui\backends\imgui_impl_opengl3.h">
|
||||
<Filter>imgui</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\Primitive.h">
|
||||
<ClInclude Include="include\Objects.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
|
|
20
imgui.ini
20
imgui.ini
|
@ -1,5 +1,5 @@
|
|||
[Window][Debug##Default]
|
||||
Pos=677,496
|
||||
Pos=638,496
|
||||
Size=400,400
|
||||
Collapsed=1
|
||||
|
||||
|
@ -10,13 +10,13 @@ Collapsed=0
|
|||
|
||||
[Window][Primitives]
|
||||
Pos=0,19
|
||||
Size=1920,113
|
||||
Size=1920,103
|
||||
Collapsed=0
|
||||
DockId=0x00000001,0
|
||||
|
||||
[Window][Object Controls]
|
||||
Pos=1526,134
|
||||
Size=394,927
|
||||
Pos=1532,124
|
||||
Size=388,956
|
||||
Collapsed=0
|
||||
DockId=0x00000004,0
|
||||
|
||||
|
@ -26,7 +26,7 @@ Collapsed=0
|
|||
|
||||
[Window][DockSpace Demo]
|
||||
Pos=0,0
|
||||
Size=1920,1061
|
||||
Size=1920,1080
|
||||
Collapsed=0
|
||||
|
||||
[Window][Dear ImGui Demo]
|
||||
|
@ -35,9 +35,9 @@ Size=1553,966
|
|||
Collapsed=0
|
||||
|
||||
[Docking][Data]
|
||||
DockSpace ID=0x3BC79352 Window=0x4647B76E Pos=0,19 Size=1920,1042 Split=Y
|
||||
DockNode ID=0x00000001 Parent=0x3BC79352 SizeRef=1904,113 Selected=0x8CCBC963
|
||||
DockNode ID=0x00000002 Parent=0x3BC79352 SizeRef=1904,946 Split=X
|
||||
DockNode ID=0x00000003 Parent=0x00000002 SizeRef=1508,975 CentralNode=1
|
||||
DockNode ID=0x00000004 Parent=0x00000002 SizeRef=394,975 Selected=0x3B5216D2
|
||||
DockSpace ID=0x3BC79352 Window=0x4647B76E Pos=0,19 Size=1920,1061 Split=Y
|
||||
DockNode ID=0x00000001 Parent=0x3BC79352 SizeRef=1904,103 Selected=0x8CCBC963
|
||||
DockNode ID=0x00000002 Parent=0x3BC79352 SizeRef=1904,956 Split=X
|
||||
DockNode ID=0x00000003 Parent=0x00000002 SizeRef=1530,956 CentralNode=1
|
||||
DockNode ID=0x00000004 Parent=0x00000002 SizeRef=388,956 Selected=0x3B5216D2
|
||||
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
#pragma once
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
using namespace glm;
|
||||
|
||||
constexpr auto P_SPHERE = 0x00;
|
||||
constexpr auto P_TORUS = 0x01;
|
||||
constexpr auto P_CONE = 0x02;
|
||||
constexpr auto P_CUBE = 0x03;
|
||||
constexpr auto P_ROUNDED_CUBE = 0x04;
|
||||
constexpr auto P_CYLINDER = 0x05;
|
||||
|
||||
struct Primitive
|
||||
{
|
||||
vec4 position = vec4(0.0f, 0.0f, 0.0f, 1.0f); // 16 bytes
|
||||
vec4 diffuse_color = vec4(0.8f, 0.8f, 0.8f, 1.0f); // 16 bytes
|
||||
vec4 specular_color = vec4(1.0f, 1.0f, 1.0f, 1.0f); // 16 bytes
|
||||
vec4 ambient_color = vec4(0.2f, 0.2f, 0.2f, 1.0f); // 16 bytes
|
||||
|
||||
int specular_exponent = 40; // 4 bytes
|
||||
|
||||
unsigned int type = -1; // 4 bytes
|
||||
|
||||
float radius = -1.f; // 4 bytes
|
||||
float height = -1.f; // 4 bytes
|
||||
float inner_radius = -1.f; // 4 bytes
|
||||
float outer_radius = -1.f; // 4 bytes
|
||||
float size = -1.f; // 4 bytes
|
||||
|
||||
// Has to be a multiple of 32 bytes (96 in this case), currently only 92
|
||||
unsigned int dummy = 0;
|
||||
unsigned int subtract = 0;
|
||||
unsigned int dummy2 = 0;
|
||||
unsigned int dummy3 = 0;
|
||||
unsigned int dummy4 = 0;
|
||||
|
||||
Primitive();
|
||||
Primitive(unsigned int shape);
|
||||
~Primitive();
|
||||
};
|
|
@ -1,103 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
using namespace glm;
|
||||
|
||||
struct Primitive
|
||||
{
|
||||
private:
|
||||
vec3 m_ambientColor;
|
||||
vec3 m_diffuseColor;
|
||||
vec3 m_specularColor;
|
||||
vec3 m_position;
|
||||
|
||||
public:
|
||||
vec3& ambientColor() { return m_ambientColor; }
|
||||
const vec3& ambientColor() const { return m_ambientColor; }
|
||||
|
||||
vec3& diffuseColor() { return m_diffuseColor; }
|
||||
const vec3& diffuseColor() const { return m_diffuseColor; }
|
||||
|
||||
vec3& specularColor() { return m_specularColor; }
|
||||
const vec3& specularColor() const { return m_specularColor; }
|
||||
|
||||
vec3& position() { return m_position; }
|
||||
const vec3& position() const { return m_position; }
|
||||
};
|
||||
|
||||
struct Sphere : Primitive
|
||||
{
|
||||
private:
|
||||
float m_radius;
|
||||
|
||||
public:
|
||||
float& radius() { return m_radius; }
|
||||
const float& radius() const { return m_radius; }
|
||||
};
|
||||
|
||||
struct Torus : Primitive
|
||||
{
|
||||
private:
|
||||
float m_outerRadius;
|
||||
float m_innerRadius;
|
||||
|
||||
public:
|
||||
float& outerRadius() { return m_outerRadius; }
|
||||
const float& outerRadius() const { return m_outerRadius; }
|
||||
|
||||
float& innerRadius() { return m_innerRadius; }
|
||||
const float& innerRadius() const { return m_innerRadius; }
|
||||
};
|
||||
|
||||
struct Cube : Primitive
|
||||
{
|
||||
private:
|
||||
float m_size;
|
||||
|
||||
public:
|
||||
float& size() { return m_size; }
|
||||
const float& size() const { return m_size; }
|
||||
};
|
||||
|
||||
struct RoundedCube : Primitive
|
||||
{
|
||||
private:
|
||||
float m_size;
|
||||
float m_radius;
|
||||
|
||||
public:
|
||||
float& size() { return m_size; }
|
||||
const float& size() const { return m_size; }
|
||||
|
||||
float& radius() { return m_radius; }
|
||||
const float& radius() const { return m_radius; }
|
||||
};
|
||||
|
||||
struct Cylinder : Primitive
|
||||
{
|
||||
private:
|
||||
float m_height;
|
||||
float m_radius;
|
||||
|
||||
public:
|
||||
float& height() { return m_height; }
|
||||
const float& height() const { return m_height; }
|
||||
|
||||
float& radius() { return m_radius; }
|
||||
const float& radius() const { return m_radius; }
|
||||
};
|
||||
|
||||
struct Cone : Primitive
|
||||
{
|
||||
private:
|
||||
float m_height;
|
||||
float m_radius;
|
||||
|
||||
public:
|
||||
float& height() { return m_height; }
|
||||
const float& height() const { return m_height; }
|
||||
|
||||
float& radius() { return m_radius; }
|
||||
const float& radius() const { return m_radius; }
|
||||
};
|
|
@ -8,10 +8,6 @@ uniform vec3 cam_pos;
|
|||
uniform int window_width;
|
||||
uniform int window_height;
|
||||
|
||||
//uniform vec3 la;
|
||||
//uniform vec3 ld;
|
||||
//uniform vec3 ls;
|
||||
|
||||
uniform float smoothing;
|
||||
|
||||
const uint P_SPHERE = 0x00;
|
||||
|
@ -20,6 +16,8 @@ const uint P_CONE = 0x02;
|
|||
const uint P_CUBE = 0x03;
|
||||
const uint P_ROUNDED_CUBE = 0x04;
|
||||
|
||||
bool twoExists = false;
|
||||
|
||||
struct GLSLPrimitive
|
||||
{
|
||||
vec4 position;
|
||||
|
@ -37,6 +35,10 @@ struct GLSLPrimitive
|
|||
float outer_radius;
|
||||
float size;
|
||||
uint dummy;
|
||||
uint subtract;
|
||||
uint dummy2;
|
||||
uint dummy3;
|
||||
uint dummy4;
|
||||
};
|
||||
|
||||
struct GLSLLight
|
||||
|
@ -158,32 +160,61 @@ float smoothMaxSDF(float d1, float d2, float k)
|
|||
return min(d1, d2) - h * h * h * k * 1.0 / 6.0;
|
||||
}
|
||||
|
||||
void estimateSmoothNormals(vec3 p, float smoothness, float epsilon, inout vec3 normals, inout vec4 color)
|
||||
void estimateSmoothNormals(vec3 p, float smoothness, float epsilon, inout vec3 normals)
|
||||
{
|
||||
float d = sdf(p, primitives[0]);
|
||||
float d, nx, ny, nz;
|
||||
|
||||
for (int i = 0; i < primitives.length(); i++)
|
||||
{
|
||||
if (primitives[i].subtract == 1) continue;
|
||||
if (i == 0)
|
||||
{
|
||||
d = sdf(p, primitives[0]);
|
||||
nx = sdf(vec3(p.x + epsilon, p.y, p.z), primitives[0]);
|
||||
ny = sdf(vec3(p.x, p.y + epsilon, p.z), primitives[0]);
|
||||
nz = sdf(vec3(p.x, p.y, p.z + epsilon), primitives[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
d = smoothMinSDF(d, sdf(p, primitives[i]), smoothness);
|
||||
nx = smoothMinSDF(nx, sdf(vec3(p.x + epsilon, p.y, p.z), primitives[i]), smoothness);
|
||||
ny = smoothMinSDF(ny, sdf(vec3(p.x, p.y + epsilon, p.z), primitives[i]), smoothness);
|
||||
nz = smoothMinSDF(nz, sdf(vec3(p.x, p.y, p.z + epsilon), primitives[i]), smoothness);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < primitives.length(); i++)
|
||||
{
|
||||
if (primitives[i].subtract == 1)
|
||||
{
|
||||
d = max(d, -sdf(p, primitives[i]));
|
||||
nx = max(nx, -sdf(vec3(p.x + epsilon, p.y, p.z), primitives[i]));
|
||||
ny = max(ny, -sdf(vec3(p.x, p.y + epsilon, p.z), primitives[i]));
|
||||
nz = max(nz, -sdf(vec3(p.x, p.y, p.z + epsilon), primitives[i]));
|
||||
}
|
||||
}
|
||||
|
||||
nx -= d;
|
||||
ny -= d;
|
||||
nz -= d;
|
||||
|
||||
normals = normalize(vec3(nx, ny, nz));
|
||||
}
|
||||
|
||||
void estimateSmoothNormalsMax(vec3 p, float smoothness, float epsilon, inout vec3 normals)
|
||||
{
|
||||
float d = sdf(p, primitives[0]);
|
||||
float nx = sdf(vec3(p.x + epsilon, p.y, p.z), primitives[0]);
|
||||
float ny = sdf(vec3(p.x, p.y + epsilon, p.z), primitives[0]);
|
||||
float nz = sdf(vec3(p.x, p.y, p.z + epsilon), primitives[0]);
|
||||
|
||||
float blendFactor = clamp(0.5 + 0.5 * (sdf(p, primitives[0]) - sdf(p, primitives[1])) / smoothness, 0.0, 1.0);
|
||||
vec4 blendedColor = mix(primitives[0].diffuse_color, primitives[1].diffuse_color, blendFactor);
|
||||
|
||||
blendFactor = clamp(0.5 + 0.5 * (sdf(p, primitives[1]) - sdf(p, primitives[2])) / smoothness, 0.0, 1.0);
|
||||
vec4 blendedColor1 = mix(primitives[1].diffuse_color, primitives[2].diffuse_color, blendFactor);
|
||||
|
||||
blendFactor = clamp(0.5 + 0.5 * (sdf(p, primitives[2]) - sdf(p, primitives[0])) / smoothness, 0.0, 1.0);
|
||||
vec4 blendedColor2 = mix(primitives[2].diffuse_color, primitives[0].diffuse_color, blendFactor);
|
||||
|
||||
vec4 blendedColor3 = mix(blendedColor, blendedColor1, blendFactor);
|
||||
vec4 blendedColor4 = mix(blendedColor3, blendedColor2, blendFactor);
|
||||
|
||||
|
||||
for (int i = 1; i < primitives.length(); i++)
|
||||
for (int i = 0; i < primitives.length(); i++)
|
||||
{
|
||||
d = smoothMinSDF(d, sdf(p, primitives[i]), smoothness);
|
||||
nx = smoothMinSDF(nx, sdf(vec3(p.x + epsilon, p.y, p.z), primitives[i]), smoothness);
|
||||
ny = smoothMinSDF(ny, sdf(vec3(p.x, p.y + epsilon, p.z), primitives[i]), smoothness);
|
||||
nz = smoothMinSDF(nz, sdf(vec3(p.x, p.y, p.z + epsilon), primitives[i]), smoothness);
|
||||
d = smoothMaxSDF(d, sdf(p, primitives[i]), smoothness);
|
||||
nx = smoothMaxSDF(nx, sdf(vec3(p.x + epsilon, p.y, p.z), primitives[i]), smoothness);
|
||||
ny = smoothMaxSDF(ny, sdf(vec3(p.x, p.y + epsilon, p.z), primitives[i]), smoothness);
|
||||
nz = smoothMaxSDF(nz, sdf(vec3(p.x, p.y, p.z + epsilon), primitives[i]), smoothness);
|
||||
}
|
||||
nx -= d;
|
||||
ny -= d;
|
||||
|
@ -228,10 +259,36 @@ float weightFunction(float distance, float k, float epsilon)
|
|||
}
|
||||
}
|
||||
|
||||
vec4 renderLight(vec4 position) {
|
||||
vec4 newPosition = position;
|
||||
newPosition.x = position.y;
|
||||
newPosition.y = -position.x;
|
||||
vec4 matPos = P * V * M * newPosition;
|
||||
matPos /= matPos.w;
|
||||
vec2 screenPos = 2.0 * vec2(gl_FragCoord.x / window_width, gl_FragCoord.y / window_height) - 1.0;
|
||||
float aspectRatio = float(window_width) / float(window_height);
|
||||
screenPos.y /= aspectRatio;
|
||||
|
||||
vec2 centerScreenPos = matPos.xy;
|
||||
|
||||
float radius = 0.05 / length(newPosition.xyz - cam_pos);
|
||||
|
||||
vec4 color;
|
||||
if (length(screenPos - centerScreenPos) < radius && length(screenPos - centerScreenPos) > radius * 0.9) {
|
||||
color = vec4(1.0, 0.95, 0.6, 1.0);
|
||||
}
|
||||
else {
|
||||
color = vec4(0.0);
|
||||
}
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
vec3 normals;
|
||||
vec3 color = lights[0].ambient_color.rgb;
|
||||
vec4 color = vec4(0.0);
|
||||
vec4 lightColor = vec4(0.0);
|
||||
vec4 ray_pos = vec4(cam_pos, 1.0);
|
||||
float ray_dist = 0.0;
|
||||
float max_dist = 100.0;
|
||||
|
@ -260,9 +317,14 @@ void main(void)
|
|||
{
|
||||
steps++;
|
||||
float minDist = 999999.0;
|
||||
float maxDist = 0.0;
|
||||
|
||||
|
||||
for (int i = 0; i < primitives.length(); i++)
|
||||
{
|
||||
if (primitives[i].subtract == 1) {
|
||||
continue;
|
||||
}
|
||||
float dist = sdf(ray_pos.xyz, primitives[i]);
|
||||
float weight = weightFunction(dist, smoothing, epsilon);
|
||||
if (dist < sdf(ray_pos.xyz, primitives[closestIndex]))
|
||||
|
@ -270,6 +332,11 @@ void main(void)
|
|||
closestIndex = i;
|
||||
}
|
||||
minDist = smoothMinSDF(minDist, dist, k);
|
||||
//minDist = smoothMaxSDF(maxDist, dist, k);
|
||||
//minDist = max(-minDist, dist);
|
||||
//minDist = min(minDist, dist);
|
||||
/*if(i == 3)
|
||||
minDist = max(-minDist, dist);*/
|
||||
|
||||
accumulatedDiffuse += primitives[i].diffuse_color * weight;
|
||||
accumulatedSpecular += primitives[i].specular_color * weight;
|
||||
|
@ -278,7 +345,13 @@ void main(void)
|
|||
totalWeight += weight;
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < primitives.length(); i++)
|
||||
{
|
||||
if (primitives[i].subtract == 1) {
|
||||
float dist = sdf(ray_pos.xyz, primitives[i]);
|
||||
minDist = max(minDist, -dist);
|
||||
}
|
||||
}
|
||||
|
||||
if (minDist <= epsilon)
|
||||
{
|
||||
|
@ -297,14 +370,13 @@ void main(void)
|
|||
vec3 lw;
|
||||
ambient_color = vec4(accumulatedAmbient.rgb, 1.0);
|
||||
diffuse_color = vec4(accumulatedDiffuse.rgb, 1.0);
|
||||
estimateSmoothNormals(ray_pos.xyz, k, epsilon, normals);
|
||||
//normals = estimateNormals(ray_pos.xyz, primitives[closestIndex], 0.001);
|
||||
|
||||
for (int i = 0; i < lights.length(); i++)
|
||||
{
|
||||
ambient += lights[i].ambient_color * ambient_color;
|
||||
|
||||
//normals = estimateNormals(ray_pos.xyz, primitives[closestIndex], epsilon);
|
||||
estimateSmoothNormals(ray_pos.xyz, k, epsilon, normals, diffuse_color);
|
||||
|
||||
vec3 nw = normalize(normals);
|
||||
lw = normalize(lights[i].position.xyz - ray_pos.xyz);
|
||||
distLight = length(vec4(ray_pos.xyz - lights[i].position.xyz, 1.0));
|
||||
|
@ -318,7 +390,7 @@ void main(void)
|
|||
|
||||
specular += spec * accumulatedSpecular * lights[i].specular_color;
|
||||
|
||||
color = (ambient + (1.0 / (distLight * distLight) * (diffuse + specular))).xyz;
|
||||
color = ambient + (1.0 / (distLight * distLight) * (diffuse + specular));
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -327,5 +399,6 @@ void main(void)
|
|||
ray_dist += minDist;
|
||||
}
|
||||
|
||||
FragColor = vec4(color, 1.0);
|
||||
for (int i = 0; i < lights.length(); i++) lightColor += renderLight(lights[i].position);
|
||||
FragColor = mix(color, lightColor, lightColor.a);
|
||||
}
|
|
@ -16,35 +16,7 @@
|
|||
#include <glm/gtc/type_ptr.hpp>
|
||||
|
||||
#include <Camera.h>
|
||||
//#include <Primitive.h>
|
||||
|
||||
constexpr auto P_SPHERE = 0x00;
|
||||
constexpr auto P_TORUS = 0x01;
|
||||
constexpr auto P_CONE = 0x02;
|
||||
constexpr auto P_CUBE = 0x03;
|
||||
constexpr auto P_ROUNDED_CUBE = 0x04;
|
||||
constexpr auto P_CYLINDER = 0x05;
|
||||
|
||||
struct Primitive
|
||||
{
|
||||
glm::vec4 position = glm::vec4(0.0f, 0.0f, 0.0f, 1.0f); // 16 bytes
|
||||
glm::vec4 diffuse_color = glm::vec4(0.8f, 0.8f, 0.8f, 1.0f); // 16 bytes
|
||||
glm::vec4 specular_color = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f); // 16 bytes
|
||||
glm::vec4 ambient_color = glm::vec4(0.2f, 0.2f, 0.2f, 1.0f); // 16 bytes
|
||||
|
||||
int specular_exponent = 40; // 4 bytes
|
||||
|
||||
unsigned int type = -1; // 4 bytes
|
||||
|
||||
float radius = -1.f; // 4 bytes
|
||||
float height = -1.f; // 4 bytes
|
||||
float inner_radius = -1.f; // 4 bytes
|
||||
float outer_radius = -1.f; // 4 bytes
|
||||
float size = -1.f; // 4 bytes
|
||||
|
||||
// Has to be a multiple of 32 bytes (96 in this case), currently only 92
|
||||
unsigned int dummy = 0; // 4 bytes
|
||||
};
|
||||
#include <Objects.h>
|
||||
|
||||
struct Light
|
||||
{
|
||||
|
@ -123,15 +95,28 @@ static char* ReadShaderSource(const char* shaderFile)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void AddPrimitive(Primitive newPrim)
|
||||
void AddPrimitive(unsigned int primType)
|
||||
{
|
||||
Primitive newPrim(primType);
|
||||
for (int i = 0; i < scene::primitiveData.size(); i++)
|
||||
{
|
||||
if (newPrim.type == scene::primitiveData[i].type) newPrim.dummy++;
|
||||
if (primType == scene::primitiveData[i].type) newPrim.dummy++;
|
||||
}
|
||||
scene::primitiveData.push_back(newPrim);
|
||||
}
|
||||
|
||||
void RemovePrimitive(int *element)
|
||||
{
|
||||
//scene::primitiveData.erase(scene::primitiveData.begin() + *element);
|
||||
//element--;
|
||||
}
|
||||
|
||||
void AddLight()
|
||||
{
|
||||
Light newLight;
|
||||
scene::lightData.push_back(newLight);
|
||||
}
|
||||
|
||||
void InitPrimitive()
|
||||
{
|
||||
glGenBuffers(1, &scene::p_vbo);
|
||||
|
@ -314,43 +299,6 @@ void PrimGUI(unsigned int obj)
|
|||
ImGui::SliderInt("Specular Exponent", &scene::primitiveData[obj].specular_exponent, 1, 500);
|
||||
}
|
||||
|
||||
void AddSphere()
|
||||
{
|
||||
Primitive s;
|
||||
s.type = P_SPHERE;
|
||||
s.radius = 0.5f;
|
||||
AddPrimitive(s);
|
||||
}
|
||||
void AddTorus()
|
||||
{
|
||||
Primitive t;
|
||||
t.type = P_TORUS;
|
||||
t.outer_radius = 0.5f;
|
||||
t.inner_radius = 0.15f;
|
||||
AddPrimitive(t);
|
||||
}
|
||||
void AddCube()
|
||||
{
|
||||
Primitive c;
|
||||
c.type = P_CUBE;
|
||||
c.size = 0.5f;
|
||||
AddPrimitive(c);
|
||||
}
|
||||
void AddRoundedCube()
|
||||
{
|
||||
Primitive rc;
|
||||
rc.type = P_ROUNDED_CUBE;
|
||||
rc.size = 0.25f;
|
||||
rc.radius = 0.025f;
|
||||
AddPrimitive(rc);
|
||||
}
|
||||
|
||||
void AddPointLight()
|
||||
{
|
||||
Primitive pl;
|
||||
AddPrimitive(pl);
|
||||
}
|
||||
|
||||
//Draw the ImGui user interface
|
||||
void draw_gui(GLFWwindow* window)
|
||||
{
|
||||
|
@ -417,7 +365,14 @@ void draw_gui(GLFWwindow* window)
|
|||
|
||||
for (int i = 0; i < scene::primitiveData.size(); i++)
|
||||
{
|
||||
ImGui::RadioButton(GetName(scene::primitiveData[i]).c_str(), &scene::object, i);
|
||||
std::string checkbox = "Subtract " + GetName(scene::primitiveData[i]);
|
||||
ImGui::RadioButton(GetName(scene::primitiveData[i]).c_str(), &scene::object, i); ImGui::SameLine();
|
||||
if (ImGui::Button(checkbox.c_str()))
|
||||
{
|
||||
scene::primitiveData[i].subtract = 1 - scene::primitiveData[i].subtract;
|
||||
}
|
||||
//if (ImGui::Button("Delete Object")) RemovePrimitive(&scene::object);
|
||||
//scene::object--;
|
||||
}
|
||||
ImGui::Separator();
|
||||
|
||||
|
@ -427,34 +382,34 @@ void draw_gui(GLFWwindow* window)
|
|||
ImGui::Begin("Primitives");
|
||||
if (ImGui::Button("Sphere", ImVec2(ImGui::GetWindowSize().y * 0.5f, ImGui::GetWindowSize().y * 0.5f)))
|
||||
{
|
||||
AddSphere();
|
||||
AddPrimitive(P_SPHERE);
|
||||
scene::object = scene::primitiveData.size() - 1;
|
||||
InitPrimitive();
|
||||
}ImGui::SameLine();
|
||||
if (ImGui::Button("Torus", ImVec2(ImGui::GetWindowSize().y * 0.5f, ImGui::GetWindowSize().y * 0.5f)))
|
||||
{
|
||||
AddTorus();
|
||||
AddPrimitive(P_TORUS);
|
||||
scene::object = scene::primitiveData.size() - 1;
|
||||
InitPrimitive();
|
||||
}ImGui::SameLine();
|
||||
if (ImGui::Button("Cube", ImVec2(ImGui::GetWindowSize().y * 0.5f, ImGui::GetWindowSize().y * 0.5f)))
|
||||
{
|
||||
AddCube();
|
||||
AddPrimitive(P_CUBE);
|
||||
scene::object = scene::primitiveData.size() - 1;
|
||||
InitPrimitive();
|
||||
}ImGui::SameLine();
|
||||
if (ImGui::Button("Rounded Cube", ImVec2(ImGui::GetWindowSize().y * 0.5f, ImGui::GetWindowSize().y * 0.5f)))
|
||||
{
|
||||
AddRoundedCube();
|
||||
AddPrimitive(P_ROUNDED_CUBE);
|
||||
scene::object = scene::primitiveData.size() - 1;
|
||||
InitPrimitive();
|
||||
}ImGui::SameLine();
|
||||
}/*ImGui::SameLine();
|
||||
if (ImGui::Button("Point Light", ImVec2(ImGui::GetWindowSize().y * 0.5f, ImGui::GetWindowSize().y * 0.5f)))
|
||||
{
|
||||
AddPointLight();
|
||||
AddLight();
|
||||
scene::object = scene::primitiveData.size() - 1;
|
||||
InitPrimitive();
|
||||
}
|
||||
}*/
|
||||
ImGui::End();
|
||||
|
||||
//End ImGui Frame
|
||||
|
@ -465,6 +420,7 @@ void draw_gui(GLFWwindow* window)
|
|||
void idle()
|
||||
{
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_BLEND);
|
||||
}
|
||||
|
||||
void display(GLFWwindow* window)
|
||||
|
@ -514,11 +470,6 @@ void display(GLFWwindow* window)
|
|||
glUniform1f(smoothing_loc, scene::smoothing);
|
||||
}
|
||||
|
||||
glUniform3fv(glGetUniformLocation(scene::shader, "light_pos"), 1, glm::value_ptr(scene::Lp));
|
||||
glUniform3fv(glGetUniformLocation(scene::shader, "la"), 1, glm::value_ptr(scene::La));
|
||||
glUniform3fv(glGetUniformLocation(scene::shader, "ld"), 1, glm::value_ptr(scene::Ld));
|
||||
glUniform3fv(glGetUniformLocation(scene::shader, "ls"), 1, glm::value_ptr(scene::Ls));
|
||||
|
||||
UpdatePrimitive();
|
||||
|
||||
glBindVertexArray(VAO);
|
||||
|
@ -629,7 +580,7 @@ void init()
|
|||
scene::shader = CreateShader("shaders/parade_vs.glsl", "shaders/parade_fs.glsl");
|
||||
glUseProgram(scene::shader);
|
||||
|
||||
AddRoundedCube();
|
||||
AddPrimitive(P_ROUNDED_CUBE);
|
||||
|
||||
Light l;
|
||||
l.position = glm::vec4{ -sqrt(3.f) / 3.f, sqrt(3.f) / 3.f, -sqrt(3.f) / 3.f, 1.f };
|
||||
|
@ -640,10 +591,37 @@ void init()
|
|||
l2.diffuse_color = glm::vec4(255.f / 255.f, 183.f / 255.f, 3.f / 255.f, 1.f);
|
||||
scene::lightData.push_back(l2);
|
||||
Light l3;
|
||||
l3.position = glm::vec4{ 0.f, -1.f, 0.f, 1.f };
|
||||
l3.diffuse_color *= 0.5f;
|
||||
l3.position = glm::vec4{ ((double)rand() / (RAND_MAX)) * 2 - 1, ((double)rand() / (RAND_MAX)) * 2 - 1, ((double)rand() / (RAND_MAX)) * 2 - 1, 1.f };
|
||||
l3.diffuse_color = glm::vec4{ ((double)rand() / (RAND_MAX)), ((double)rand() / (RAND_MAX)), ((double)rand() / (RAND_MAX)), 1.f };
|
||||
scene::lightData.push_back(l3);
|
||||
|
||||
Light l4;
|
||||
l4.position = glm::vec4{ ((double)rand() / (RAND_MAX)) * 2 - 1, ((double)rand() / (RAND_MAX)) * 2 - 1, ((double)rand() / (RAND_MAX)) * 2 - 1, 1.f };
|
||||
l4.diffuse_color = glm::vec4{ ((double)rand() / (RAND_MAX)), ((double)rand() / (RAND_MAX)), ((double)rand() / (RAND_MAX)), 1.f };
|
||||
scene::lightData.push_back(l4);
|
||||
Light l5;
|
||||
l5.position = glm::vec4{ ((double)rand() / (RAND_MAX)) * 2 - 1, ((double)rand() / (RAND_MAX)) * 2 - 1, ((double)rand() / (RAND_MAX)) * 2 - 1, 1.f };
|
||||
l5.diffuse_color = glm::vec4{ ((double)rand() / (RAND_MAX)), ((double)rand() / (RAND_MAX)), ((double)rand() / (RAND_MAX)), 1.f };
|
||||
scene::lightData.push_back(l5);
|
||||
Light l6;
|
||||
l6.position = glm::vec4{ ((double)rand() / (RAND_MAX)) * 2 - 1, ((double)rand() / (RAND_MAX)) * 2 - 1, ((double)rand() / (RAND_MAX)) * 2 - 1, 1.f };
|
||||
l6.diffuse_color = glm::vec4{ ((double)rand() / (RAND_MAX)), ((double)rand() / (RAND_MAX)), ((double)rand() / (RAND_MAX)), 1.f };
|
||||
scene::lightData.push_back(l6);
|
||||
Light l7;
|
||||
l7.position = glm::vec4{ ((double)rand() / (RAND_MAX)) * 2 - 1, ((double)rand() / (RAND_MAX)) * 2 - 1, ((double)rand() / (RAND_MAX)) * 2 - 1, 1.f };
|
||||
l7.diffuse_color = glm::vec4{ ((double)rand() / (RAND_MAX)), ((double)rand() / (RAND_MAX)), ((double)rand() / (RAND_MAX)), 1.f };
|
||||
scene::lightData.push_back(l7);
|
||||
Light l8;
|
||||
l8.position = glm::vec4{ ((double)rand() / (RAND_MAX)) * 2 - 1, ((double)rand() / (RAND_MAX)) * 2 - 1, ((double)rand() / (RAND_MAX)) * 2 - 1, 1.f };
|
||||
l8.diffuse_color = glm::vec4{ ((double)rand() / (RAND_MAX)), ((double)rand() / (RAND_MAX)), ((double)rand() / (RAND_MAX)), 1.f };
|
||||
scene::lightData.push_back(l8);
|
||||
Light l9;
|
||||
l9.position = glm::vec4{ ((double)rand() / (RAND_MAX)) * 2 - 1, ((double)rand() / (RAND_MAX)) * 2 - 1, ((double)rand() / (RAND_MAX)) * 2 - 1, 1.f };
|
||||
l9.diffuse_color = glm::vec4{ ((double)rand() / (RAND_MAX)), ((double)rand() / (RAND_MAX)), ((double)rand() / (RAND_MAX)), 1.f };
|
||||
scene::lightData.push_back(l9);
|
||||
Light l10;
|
||||
l10.position = glm::vec4{ ((double)rand() / (RAND_MAX)) * 2 - 1, ((double)rand() / (RAND_MAX)) * 2 - 1, ((double)rand() / (RAND_MAX)) * 2 - 1, 1.f };
|
||||
l10.diffuse_color = glm::vec4{ ((double)rand() / (RAND_MAX)), ((double)rand() / (RAND_MAX)), ((double)rand() / (RAND_MAX)), 1.f };
|
||||
scene::lightData.push_back(l10);
|
||||
|
||||
InitCanvas();
|
||||
InitPrimitive();
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
#include "Objects.h"
|
||||
|
||||
Primitive::Primitive()
|
||||
{
|
||||
}
|
||||
|
||||
Primitive::Primitive(unsigned int primType)
|
||||
{
|
||||
switch (primType)
|
||||
{
|
||||
case P_SPHERE:
|
||||
{
|
||||
type = P_SPHERE;
|
||||
radius = 0.5f;
|
||||
break;
|
||||
}
|
||||
case P_TORUS:
|
||||
{
|
||||
type = P_TORUS;
|
||||
inner_radius = 0.15f;
|
||||
outer_radius = 0.5f;
|
||||
break;
|
||||
}
|
||||
case P_CONE:
|
||||
{
|
||||
type = P_CONE;
|
||||
height = 0.5f;
|
||||
radius = 0.15f;
|
||||
break;
|
||||
}
|
||||
case P_CUBE:
|
||||
{
|
||||
type = P_CUBE;
|
||||
size = 0.5f;
|
||||
break;
|
||||
}
|
||||
case P_ROUNDED_CUBE:
|
||||
{
|
||||
type = P_ROUNDED_CUBE;
|
||||
size = 0.25f;
|
||||
radius = 0.025f;
|
||||
break;
|
||||
}
|
||||
defualt:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Primitive::~Primitive() = default;
|
|
@ -1 +0,0 @@
|
|||
#include "Primitive.h"
|
Loading…
Reference in New Issue