rustengine/README.md

71 lines
2.3 KiB
Markdown

# Engine 3D
Scaffold de engine 3D em Rust usando SDL3 e OpenGL 3.3+.
- Terreno procedural com Perlin Noise (FBM multi-oitavas)
- Malha contínua triangulada
- Iluminação difusa + especular (Blinn-Phong) + névoa atmosférica
- Mar com ondas de Gerstner, reflexões Fresnel e transparência por profundidade
- Câmera FPS livre com mouse look
- Game loop com update (60Hz) e render desacoplados
## Dependências
| Crate | Uso |
|---|---|
| `sdl3` | Janela e contexto OpenGL |
| `glow` | Bindings OpenGL em Rust |
| `glam` | Álgebra linear 3D (Mat4, Vec3) |
| `noise` | Perlin Noise / FBM |
| `bytemuck` | Cast seguro de slices para bytes |
**Requer SDL3 instalado no sistema:**
```bash
# Fedora
sudo dnf install SDL3-devel
# Ubuntu/Debian
sudo apt install libsdl3-dev
```
## Compilar e rodar
```bash
cargo run --release
```
## Controles
| Tecla | Ação |
|---|---|
| W / A / S / D | Mover câmera (frente/esq/trás/dir) |
| Space / Shift | Subir / Descer |
| Mouse | Olhar ao redor (FPS look — inicia capturado) |
| Tab | Alternar captura do mouse |
| ESC | Soltar mouse / Fechar |
## Estrutura
```
src/
├── main.rs # Inicialização SDL3 + game loop, 3-pass render
├── camera.rs # Câmera FPS (WASD, mouse look, view/projection)
├── input.rs # Polling eventos SDL3, estado teclas
├── terrain.rs # Heightmap Perlin FBM + geração de malha
├── water.rs # Malha do mar (plano no nível do mar, 256x256)
├── renderer.rs # VAO/VBO/EBO terreno+água, depth FBO, 3-pass pipeline
├── shader.rs # Compilação/link GLSL
└── shaders/
├── terrain.vert # Vertex shader terreno (MVP, normals)
├── terrain.frag # Fragment shader terreno (luz, névoa, gradiente por altura)
├── water.vert # Vertex shader água (5 ondas Gerstner, normal perturbada)
└── water.frag # Fragment shader água (Fresnel, specular, transparência por depth)
```
## Pipeline de renderização
1. **Terreno** — render opaco (escreve cor + depth)
2. **Blit depth** — copia depth buffer → FBO com depth texture
3. **Água** — render com alpha blending, depth-test on, depth-write off. Lê depth texture para calcular coluna d'água (raso = transparente, fundo = opaco)