Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# It sets global settings and includes the sub-projects.
# ===================================================================
cmake_minimum_required(VERSION 3.22)
project(Prism VERSION 0.1.0 LANGUAGES CXX)
project(Prism VERSION 0.2.0 LANGUAGES CXX)

# Set the policy for FetchContent to use modern, safer behavior.
cmake_policy(SET CMP0135 NEW)
Expand All @@ -21,16 +21,30 @@ set(CMAKE_CXX_EXTENSIONS OFF)
set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries" FORCE)
option(PRISM_BUILD_DEMO "Build the Prism demo application" ON)

if (CMAKE_BUILD_TYPE STREQUAL "Debug")
message(STATUS "Building in Debug mode.")
set(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "Suffix for debug binaries" FORCE)
else()
set(CMAKE_DEBUG_POSTFIX "" CACHE STRING "Suffix for non-debug binaries" FORCE)
endif()

# Set a common output directory for all executables.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

# --- Sub-projects ---
add_subdirectory(src) # The Prism library
add_subdirectory(demo) # The demo application

if (PRISM_BUILD_DEMO)
message(STATUS "Building the Prism demo application.")
add_subdirectory(demo) # The demo application
else()
message(STATUS "Skipping the Prism demo application build.")
endif()

# --- Testing ---
enable_testing()
if(BUILD_TESTING)
message(STATUS "Building tests for the Prism library.")
# Fetch GoogleTest only when tests are enabled.
include(FetchContent)
FetchContent_Declare(
Expand Down
184 changes: 117 additions & 67 deletions demo/data/input/scene.yml
Original file line number Diff line number Diff line change
@@ -1,93 +1,143 @@
# -----------------------------------------------------------------
# Exemplo de Arquivo de Cena para o Renderizador Prism
# Este arquivo demonstra o uso de múltiplos objetos, materiais
# e transformações para criar uma cena complexa.
# Cena da Cornell Box Final - Com Esferas em Destaque (Avançadas)
# -----------------------------------------------------------------

# Definições reutilizáveis da cena, como materiais.
# Usamos âncoras (&) para definir um material e aliases (*) para reutilizá-lo.
ambient_light: [0.1, 0.1, 0.1]

# --- Definições de Materiais ---
definitions:
materials:
# Material fosco para o chão
chao_cinza: &material_chao
color: [0.8, 0.8, 0.8]
ka: [0.1, 0.1, 0.1] # Pouca reflexão ambiente
ks: [0.1, 0.1, 0.1] # Pouco brilho especular
# Materiais das paredes
parede_branca: &branco
color: [0.73, 0.73, 0.73]
ka: [0.73, 0.73, 0.73]
ks: [0.0, 0.0, 0.0]
ns: 10

# Material de plástico vermelho, com brilho moderado
plastico_vermelho: &material_esfera_vermelha
color: [1.0, 0.2, 0.2]
ka: [0.2, 0.05, 0.05]
ks: [0.7, 0.7, 0.7] # Brilho especular forte
ns: 128 # Expoente de brilho alto para um highlight pequeno e intenso
parede_vermelha: &vermelho
color: [0.65, 0.05, 0.05]
ka: [0.65, 0.05, 0.05]
ks: [0.0, 0.0, 0.0]
ns: 10

# Material metálico/refletivo para o cubo
metal_azul: &material_cubo_metalico
color: [0.2, 0.3, 1.0]
ka: [0.1, 0.1, 0.2]
ks: [0.9, 0.9, 0.9] # Reflexão especular muito alta
ns: 256
parede_verde: &verde
color: [0.12, 0.45, 0.15]
ka: [0.12, 0.45, 0.15]
ks: [0.0, 0.0, 0.0]
ns: 10

# Materiais para os objetos internos
bloco_azul: &azul
color: [0.1, 0.2, 0.8]
ka: [0.1, 0.2, 0.8]
ks: [0.3, 0.3, 0.3]
ns: 64

# Material de vidro para o triângulo
vidro_transparente: &material_vidro
color: [0.9, 0.9, 1.0] # Cor levemente azulada
ka: [0.1, 0.1, 0.1]
ks: [0.8, 0.8, 0.8]
ns: 200
ni: 1.5 # Índice de refração (típico para vidro)
d: 0.1 # Opacidade (valor 'd' baixo significa mais transparente)
bloco_laranja: &laranja
color: [0.9, 0.5, 0.1]
ka: [0.9, 0.5, 0.1]
ks: [0.2, 0.2, 0.2]
ns: 32

esfera_espelho: &espelho
color: [0.0, 0.0, 0.0]
ka: [0.0, 0.0, 0.0]
ks: [0.98, 0.98, 0.98]
ns: 2048

# -----------------------------------------------------------------
# Configurações da Câmera
# -----------------------------------------------------------------
esfera_vidro: &vidro
color: [1.0, 1.0, 1.0]
ka: [1.0, 1.0, 1.0]
ks: [0.1, 0.1, 0.1]
ns: 256
ni: 1.52
d: 0.05

# --- Configurações da Câmera ---
camera:
image_width: 960
image_height: 540
image_width: 800
image_height: 800
screen_distance: 1.5
viewport_width: 2.0
viewport_height: 1.125
lookfrom: [0, 2, 8] # Posição da câmera
lookat: [0, 0, 0] # Ponto para onde a câmera olha
vup: [0, 1, 0] # Vetor "para cima"
viewport_height: 2.0
lookfrom: [278, 278, -800]
lookat: [278, 278, 0]
vup: [0, 1, 0]

# -----------------------------------------------------------------
# Lista de Objetos na Cena
# -----------------------------------------------------------------
# --- Fontes de Luz ---
lights:
- name: Luz do Teto
position: [278, 548, 278]
color: [1.0, 1.0, 1.0]
- name: Flash da Câmera
position: [278, 278, -800]
color: [0.5, 0.5, 0.5]

# --- Objetos na Cena ---
objects:
# As 5 paredes da caixa
- name: Chão
type: plane
point_on_plane: [0, -1, 0] # Ponto que define a altura do plano
normal: [0, 1, 0] # Vetor normal aponta para cima
material: *material_chao # Reutiliza o material do chão definido acima

- name: Esfera Vermelha Principal
type: sphere
center: [-1.5, 0, 0]
radius: 1.0
material: *material_esfera_vermelha # Reutiliza o material de plástico
point_on_plane: [0, 0, 0]
normal: [0, 1, 0]
material: *branco
- name: Teto
type: plane
point_on_plane: [0, 555, 0]
normal: [0, -1, 0]
material: *branco
- name: Parede do Fundo
type: plane
point_on_plane: [0, 0, 555]
normal: [0, 0, -1]
material: *branco
- name: Parede Direita (Verde)
type: plane
point_on_plane: [555, 0, 0]
normal: [-1, 0, 0]
material: *verde
- name: Parede Esquerda (Vermelha)
type: plane
point_on_plane: [0, 0, 0]
normal: [1, 0, 0]
material: *vermelho

- name: Malha de Cubo Metálico
# Blocos com tamanho e posição originais
- name: Bloco Alto (Laranja)
type: mesh
path: "./cubo.obj" # Caminho para o arquivo .obj
material: *material_cubo_metalico # Reutiliza o material metálico
# Múltiplas transformações são aplicadas em ordem
path: "cubo.obj"
material: *laranja
transform:
- type: scaling
factors: [0.7, 0.7, 0.7] # Primeiro, diminui a escala do cubo
factors: [82.5, 165, 82.5]
- type: rotation
angle: 45 # Em graus (o parser converterá para radianos)
axis: [0, 1, 0] # Rotaciona em torno do eixo Y
angle: 18
axis: [0, 1, 0]
- type: translation
vector: [1.5, 0, -1] # Por último, move o cubo para sua posição final
vector: [180, 165, 250]

- name: Triângulo de Vidro
type: triangle
# Vértices definidos diretamente no arquivo de cena
p1: [-3, -1, -5]
p2: [3, -1, -5]
p3: [0, 4, -5]
material: *material_vidro # Reutiliza o material de vidro
- name: Bloco Baixo (Azul)
type: mesh
path: "cubo.obj"
material: *azul
transform:
- type: scaling
factors: [82.5, 82.5, 82.5]
- type: rotation
angle: -20
axis: [0, 1, 0]
- type: translation
vector: [0, 0, 2] # Move o triângulo um pouco para frente
vector: [370, 82.5, 150]

# ESFERAS COM POSIÇÃO AJUSTADA (AINDA MAIS PERTO)
- name: Esfera de Vidro
type: sphere
center: [380, 90, -140] # Z foi de 120 para 80
radius: 90
material: *vidro

- name: Esfera de Espelho
type: sphere
center: [180, 90, -200] # Z foi de 180 para 100
radius: 90
material: *espelho
23 changes: 23 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# manages its dependencies, and sets up installation rules.
# ===================================================================

message(STATUS "Configuring Prism Library (v${PROJECT_VERSION}).")

# --- Dependencies ---

include(FetchContent)
Expand All @@ -16,6 +18,8 @@ FetchContent_Declare(
)
FetchContent_MakeAvailable(yaml-cpp)

message(STATUS "Configuring yaml-cpp dependency: building SHARED library, tests/tools DISABLED.")

set(YAML_CPP_BUILD_CONTRIB OFF CACHE BOOL "Disable building yaml-cpp contrib tools" FORCE)
set(YAML_CPP_BUILD_TOOLS OFF CACHE BOOL "Disable building yaml-cpp parse tools" FORCE)
set(YAML_CPP_BUILD_TESTS OFF CACHE BOOL "Disable building yaml-cpp tests" FORCE)
Expand All @@ -31,11 +35,23 @@ option(PRISM_BUILD_CORE "Build the Core module (math, etc.)" ON)
option(PRISM_BUILD_OBJECTS "Build the Objects module (Sphere, Plane, Mesh, etc.)" ON)
option(PRISM_BUILD_SCENE "Build the Scene module (Scene, Camera)" ON)

# --- Dependecy Management ---

# The CORE module is essential for all other parts of the library.
if(NOT PRISM_BUILD_CORE)
message(FATAL_ERROR "PRISM_BUILD_CORE is a required module and cannot be disabled.")
endif()

# The OBJECTS module depends on the CORE module.
if(PRISM_BUILD_OBJECTS AND NOT PRISM_BUILD_CORE)
message(FATAL_ERROR "PRISM_BUILD_OBJECTS requires PRISM_BUILD_CORE to be enabled. Please enable PRISM_BUILD_CORE.")
endif()

# The SCENE module depends on the OBJECTS module.
if(PRISM_BUILD_SCENE AND NOT PRISM_BUILD_OBJECTS)
message(FATAL_ERROR "PRISM_BUILD_SCENE requires PRISM_BUILD_OBJECTS to be enabled. Please enable PRISM_BUILD_OBJECTS.")
endif()


# --- Build Source File Collection ---

Expand All @@ -44,19 +60,26 @@ set(PRISM_SOURCES "")

# Always add the core source files.
if(PRISM_BUILD_CORE)
message(STATUS "Prism Library: Core module ENABLED.")
file(GLOB CORE_SOURCES CONFIGURE_DEPENDS "src/core/*.cpp")
list(APPEND PRISM_SOURCES ${CORE_SOURCES})
endif()

# Conditionally add sources for the other modules.
if(PRISM_BUILD_OBJECTS)
message(STATUS "Prism Library: Objects module ENABLED.")
file(GLOB GEOMETRY_SOURCES CONFIGURE_DEPENDS "src/objects/*.cpp")
list(APPEND PRISM_SOURCES ${GEOMETRY_SOURCES})
else()
message(STATUS "Prism Library: Objects module DISABLED.")
endif()

if(PRISM_BUILD_SCENE)
message(STATUS "Prism Library: Scene module ENABLED.")
file(GLOB SCENE_SOURCES CONFIGURE_DEPENDS "src/scene/*.cpp")
list(APPEND PRISM_SOURCES ${SCENE_SOURCES})
else()
message(STATUS "Prism Library: Scene module DISABLED.")
endif()

# Add any remaining top-level source files (e.g., init.cpp)
Expand Down
12 changes: 12 additions & 0 deletions src/include/Prism/core/color.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ class PRISM_EXPORT Color {
*/
Color(const Color& other);

Color operator* (Color other) const;

Color operator* (double scalar) const;

Color operator+ (Color other) const;

Color operator+= (Color other);

Color& clamp();



double r; ///< Red component of the color (0.0 to 1.0)
double g; ///< Green component of the color (0.0 to 1.0)
double b; ///< Blue component of the color (0.0 to 1.0)
Expand Down
21 changes: 11 additions & 10 deletions src/include/Prism/core/material.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,26 @@ class PRISM_EXPORT Material {
* @brief
* Default constructor that initializes the material with default values.
* The default values are:
* - Color: Black (0, 0, 0)
* - Ambient reflectivity (ka): (0, 0, 0)
* - Color: white (1,1,1)
* - Ambient reflectivity (ka): (0.1, 0.1, 0.1)
* - Specular reflectivity (ks): (0, 0, 0)
* - Emissive color (ke): (0, 0, 0)
* - Shininess (ns): 0
* - Index of refraction (ni): 0
* - Transparency (d): 0
* - Shininess (ns): 1
* - Index of refraction (ni): 1
* - Transparency (d): 1
*/
Material(Color color = Color(), Vector3 ka = Vector3(), Vector3 ks = Vector3(),
Vector3 ke = Vector3(), double ns = 0, double ni = 0, double d = 0)
Material(Color color = Color(1, 1, 1), Color ka = Color(0.1, 0.1, 0.1),
Color ks = Color(0, 0, 0), Color ke = Color(0, 0, 0), double ns = 1.0, double ni = 1.0,
double d = 1.0)
: color(color), ka(ka), ks(ks), ke(ke), ns(ns), ni(ni), d(d) {
}

Color color; ///< The color of the material, typically used for diffuse reflection.
Vector3 ka; ///< Ambient reflectivity of the material, representing how much ambient light it
Color ka; ///< Ambient reflectivity of the material, representing how much ambient light it
///< reflects.
Vector3 ks; ///< Specular reflectivity of the material, representing how much specular light it
Color ks; ///< Specular reflectivity of the material, representing how much specular light it
///< reflects.
Vector3
Color
ke; ///< Emissive color of the material, representing light emitted by the material itself.
double ns; ///< Shininess factor of the material, affecting the size and intensity of specular
///< highlights.
Expand Down
6 changes: 6 additions & 0 deletions src/include/Prism/core/point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ class PRISM_EXPORT Point3 {
*/
bool operator==(const Point3& p) const;

/**
* @brief Negates the point.
* @return A new point that is the negation of this point.
*/
Point3 operator-() const;

/**
* @brief Gets a vector from this point to another point.
* @param p The point to get the vector to.
Expand Down
Loading