demo skybox

This commit is contained in:
h4570
2022-08-02 13:20:12 +02:00
parent cdadb932b7
commit 5aae7cff7e
11 changed files with 131 additions and 15 deletions
+1
View File
@@ -1,5 +1,6 @@
------------ Tyra's v2.0 roadmap to publish on GitHub ------------ ------------ Tyra's v2.0 roadmap to publish on GitHub ------------
- [General] Allow to edit all data from mesh/texture - [General] Allow to edit all data from mesh/texture
- [General] USB test
- [General] Tyra version, render it on start - [General] Tyra version, render it on start
- [Renderer] Fog - [Renderer] Fog
- [Demo] Create cool demo which will show all features of Tyra - [Demo] Create cool demo which will show all features of Tyra
+2
View File
@@ -15,6 +15,7 @@
#include "./player/player.hpp" #include "./player/player.hpp"
#include "./renderer/game_renderer.hpp" #include "./renderer/game_renderer.hpp"
#include "./terrain/terrain.hpp" #include "./terrain/terrain.hpp"
#include "./skybox/skybox.hpp"
#include "./debug_object.hpp" #include "./debug_object.hpp"
namespace Demo { namespace Demo {
@@ -44,6 +45,7 @@ class GameState : public State<GlobalStateType> {
GameRenderer renderer; GameRenderer renderer;
Player* player; Player* player;
Terrain* terrain; Terrain* terrain;
Skybox* skybox;
DebugObject* dbgObj; DebugObject* dbgObj;
}; };
+41
View File
@@ -0,0 +1,41 @@
/*
# ______ ____ ___
# | \/ ____| |___|
# | | | \ | |
#-----------------------------------------------------------------------
# Copyright 2022, tyra - https://github.com/h4570/tyra
# Licenced under Apache License 2.0
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
*/
#pragma once
#include <renderer/3d/mesh/static/static_mesh.hpp>
#include <renderer/3d/pipeline/static/stapip_options.hpp>
#include "states/game/renderer/renderer_static_pair.hpp"
#include <renderer/renderer.hpp>
using Tyra::Renderer;
using Tyra::StaPipOptions;
using Tyra::StaticMesh;
using Tyra::TextureRepository;
using Tyra::Vec4;
namespace Demo {
class Skybox {
public:
Skybox(TextureRepository* repo);
~Skybox();
StaticMesh* mesh;
StaPipOptions* options;
RendererStaticPair* pair;
void update(const Vec4& playerPosition);
private:
void allocateOptions();
};
} // namespace Demo
+4 -3
View File
@@ -30,6 +30,7 @@ void GameState::onStart() {
player = new Player(engine); player = new Player(engine);
terrain = new Terrain(&engine->renderer.core.texture.repository); terrain = new Terrain(&engine->renderer.core.texture.repository);
skybox = new Skybox(&engine->renderer.core.texture.repository);
dbgObj = new DebugObject(&engine->renderer.core.texture.repository); dbgObj = new DebugObject(&engine->renderer.core.texture.repository);
initialized = true; initialized = true;
@@ -40,6 +41,7 @@ GlobalStateType GameState::onFinish() {
delete player; delete player;
delete terrain; delete terrain;
delete skybox;
delete dbgObj; delete dbgObj;
initialized = false; initialized = false;
@@ -54,10 +56,8 @@ void GameState::update() {
// TODO: Get next player position and calculate all stuf for NEXT position // TODO: Get next player position and calculate all stuf for NEXT position
// (not current!) // (not current!)
// TODO: Fix camera for heightmap
// TODO: Change map
// TODO: Implement collision // TODO: Implement collision
skybox->update(player->getPosition());
auto cameraInfo = player->getCameraInfo(); auto cameraInfo = player->getCameraInfo();
engine->renderer.beginFrame(cameraInfo); engine->renderer.beginFrame(cameraInfo);
@@ -68,6 +68,7 @@ void GameState::update() {
renderer.clear(); renderer.clear();
{ {
renderer.add(skybox->pair);
renderer.add(player->staticPairs); renderer.add(player->staticPairs);
renderer.add(player->dynamicPairs); renderer.add(player->dynamicPairs);
renderer.add(terrain->pair); renderer.add(terrain->pair);
+2 -1
View File
@@ -40,9 +40,10 @@ void Camera::update(const Vec4& playerPosition, const float& terrainHeight) {
} }
unitCircle.x = (sin(circleRotation) * lengthFromOrigin); unitCircle.x = (sin(circleRotation) * lengthFromOrigin);
unitCircle.y = height + playerPosition.y + terrainHeight; unitCircle.y = height;
unitCircle.z = (cos(circleRotation) * lengthFromOrigin); unitCircle.z = (cos(circleRotation) * lengthFromOrigin);
position = playerPosition;
lookAt = unitCircle + playerPosition; lookAt = unitCircle + playerPosition;
} }
+2 -1
View File
@@ -101,7 +101,8 @@ Weapon::~Weapon() {
void Weapon::allocateOptions() { void Weapon::allocateOptions() {
options = new StaPipOptions(); options = new StaPipOptions();
options->shadingType = Tyra::TyraShadingGouraud; options->textureMappingType = Tyra::TyraNearest;
options->shadingType = Tyra::TyraShadingFlat;
options->blendingEnabled = false; options->blendingEnabled = false;
options->fullClipChecks = false; options->fullClipChecks = false;
options->frustumCulling = Tyra::PipelineFrustumCulling_None; options->frustumCulling = Tyra::PipelineFrustumCulling_None;
+66
View File
@@ -0,0 +1,66 @@
/*
# ______ ____ ___
# | \/ ____| |___|
# | | | \ | |
#-----------------------------------------------------------------------
# Copyright 2022, tyra - https://github.com/h4570/tyra
# Licenced under Apache License 2.0
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
*/
#include "states/game/skybox/skybox.hpp"
#include <loaders/3d/tyrobj/tyrobj_loader.hpp>
#include <file/file_utils.hpp>
using Tyra::FileUtils;
using Tyra::TyrobjLoader;
namespace Demo {
Skybox::Skybox(TextureRepository* repo) {
TyrobjLoader loader;
auto* data = loader.load(FileUtils::fromCwd("game/models/skybox/skybox.obj"),
1, 400.0F, true);
data->normalsEnabled = false;
mesh = new StaticMesh(*data);
delete data;
mesh->scale.scaleX(2.0F);
mesh->scale.scaleZ(2.0F);
for (u32 i = 0; i < mesh->getMaterialsCount(); i++) {
auto* material = mesh->getMaterial(i);
material->print();
material->color.r = 16.0F;
material->color.g = 16.0F;
material->color.b = 16.0F;
}
repo->addByMesh(mesh, FileUtils::fromCwd("game/models/skybox/"), "png");
allocateOptions();
pair = new RendererStaticPair{mesh, options};
}
Skybox::~Skybox() {
delete mesh;
delete options;
delete pair;
}
void Skybox::update(const Vec4& playerPosition) {
mesh->translation.identity();
mesh->translation.translate(playerPosition);
}
void Skybox::allocateOptions() {
options = new StaPipOptions();
options->frustumCulling = Tyra::PipelineFrustumCulling_None;
options->shadingType = Tyra::TyraShadingGouraud;
options->textureMappingType = Tyra::TyraNearest;
options->blendingEnabled = true;
options->antiAliasingEnabled = false;
}
} // namespace Demo
+1 -1
View File
@@ -18,7 +18,7 @@ using Tyra::TyrobjLoader;
namespace Demo { namespace Demo {
Terrain::Terrain(TextureRepository* repo) Terrain::Terrain(TextureRepository* repo)
: heightmap(-5.0F, // Min height : heightmap(-5.0F, // Min height
70.0F, // Max height 100.0F, // Max height
Vec4(-196.6F, 0.0F, -412.0F, 1.0F), // Left up Vec4(-196.6F, 0.0F, -412.0F, 1.0F), // Left up
Vec4(286.0F, 0.0F, 443.3F, 1.0F) // Right down Vec4(286.0F, 0.0F, 443.3F, 1.0F) // Right down
) { ) {
+2
View File
@@ -17,3 +17,5 @@ Arrows = Right joy
Space = X Space = X
Circle = C Circle = C
``` ```
- Enable **"EE timing hack"** in PCSX2 hacks!
@@ -29,14 +29,13 @@ class RendererCoreGSVRam {
int allocate(const TextureData& texData); int allocate(const TextureData& texData);
int allocateBuffer(const int& width, const int& height, const int& psm); int allocateBuffer(const int& width, const int& height, const int& psm);
int allocate(const int& width, const int& height, const int& psm,
const int& alignment);
/** Free texture, FIFO order */ /** Free texture, FIFO order */
void free(const int& address); void free(const int& address);
private: private:
int allocate(const int& width, const int& height, const int& psm,
const int& alignment);
int getSize(int width, const int& height, const int& psm, int getSize(int width, const int& height, const int& psm,
const int& alignment); const int& alignment);
@@ -65,19 +65,21 @@ void Path3::sendTexture(Texture* texture,
const RendererCoreTextureBuffers& texBuffers) { const RendererCoreTextureBuffers& texBuffers) {
packet2_reset(texturePacket, false); packet2_reset(texturePacket, false);
int coreWidth = texBuffers.core->width <= 64 ? 64 : texBuffers.core->width;
packet2_update( packet2_update(
texturePacket, texturePacket,
draw_texture_transfer(texturePacket->base, texture->getCoreData().data, draw_texture_transfer(texturePacket->base, texture->getCoreData().data,
texture->getWidth(), texture->getHeight(), texture->getWidth(), texture->getHeight(),
texture->getCoreData().psm, texture->getCoreData().psm,
texBuffers.core->address, texBuffers.core->width)); texBuffers.core->address, coreWidth));
if (texBuffers.clut != nullptr) { if (texBuffers.clut != nullptr) {
auto* clut = texture->getClutData(); auto* clut = texture->getClutData();
packet2_update(texturePacket, draw_texture_transfer( int clutWidth = texBuffers.clut->width <= 64 ? 64 : texBuffers.clut->width;
texturePacket->next, clut->data, packet2_update(texturePacket,
clut->width, clut->height, clut->psm, draw_texture_transfer(texturePacket->next, clut->data,
texBuffers.clut->address, clut->width)); clut->width, clut->height, clut->psm,
texBuffers.clut->address, clutWidth));
} }
packet2_chain_open_cnt(texturePacket, 0, 0, 0); packet2_chain_open_cnt(texturePacket, 0, 0, 0);