Commit for 2021.03.12.7z
This commit is contained in:
parent
7b7d26a494
commit
63ab2a5584
2
Makefile
2
Makefile
@ -39,7 +39,7 @@ INCS += -I$(ENGINE_INC_DIR) -I$(INC_DIR) -I$(VULKAN_SDK_PATH)/include -I/mi
|
||||
LIBS += -L$(ENGINE_LIB_DIR) -L$(LIB_DIR) -L$(LIB_DIR)/$(PREFIX) -L$(VULKAN_SDK_PATH)/Lib
|
||||
|
||||
ifneq (,$(findstring win64,$(ARCH)))
|
||||
REQ_DEPS += opengl json:nlohmann png openal ogg freetype ncurses curl luajit bullet meshoptimizer xatlas # draco discord
|
||||
REQ_DEPS += vulkan json:nlohmann png openal ogg freetype ncurses curl luajit bullet meshoptimizer xatlas # draco discord
|
||||
FLAGS +=
|
||||
DEPS += -lgdi32
|
||||
else ifneq (,$(findstring dreamcast,$(ARCH)))
|
||||
|
@ -250,20 +250,20 @@ float random(vec3 seed, int i){
|
||||
return fract(sin(dot_product) * 43758.5453);
|
||||
}
|
||||
|
||||
float shadowFactor( Light light, uint shadowMap, float def ) {
|
||||
float shadowFactor( Light light, uint shadowMap ) {
|
||||
vec4 positionClip = light.projection * light.view * vec4(position.world, 1.0);
|
||||
positionClip.xyz /= positionClip.w;
|
||||
|
||||
if ( positionClip.x < -1 || positionClip.x >= 1 ) return def;
|
||||
if ( positionClip.y < -1 || positionClip.y >= 1 ) return def;
|
||||
if ( positionClip.z <= 0 || positionClip.z >= 1 ) return def;
|
||||
if ( positionClip.x < -1 || positionClip.x >= 1 ) return 0.0;
|
||||
if ( positionClip.y < -1 || positionClip.y >= 1 ) return 0.0;
|
||||
if ( positionClip.z <= 0 || positionClip.z >= 1 ) return 0.0;
|
||||
|
||||
float factor = 1.0;
|
||||
|
||||
// spot light
|
||||
if ( light.type == 2 || light.type == 3 ) {
|
||||
float dist = length( positionClip.xy );
|
||||
if ( dist > 0.5 ) return def;
|
||||
if ( dist > 0.5 ) return 0.0;
|
||||
|
||||
// spot light with attenuation
|
||||
if ( light.type == 3 ) {
|
||||
@ -273,6 +273,14 @@ float shadowFactor( Light light, uint shadowMap, float def ) {
|
||||
|
||||
vec2 uv = positionClip.xy * 0.5 + 0.5;
|
||||
float bias = light.depthBias;
|
||||
/*
|
||||
if ( true ) {
|
||||
float cosTheta = clamp(dot(normal.eye, normalize(light.position.xyz - position.eye)), 0, 1);
|
||||
bias = clamp(bias * tan(acos(cosTheta)), 0, 0.01);
|
||||
} else if ( true ) {
|
||||
bias = max(bias * 10 * (1.0 - dot(normal.eye, normalize(light.position.xyz - position.eye))), bias);
|
||||
}
|
||||
*/
|
||||
|
||||
float eyeDepth = positionClip.z;
|
||||
|
||||
@ -281,13 +289,14 @@ float shadowFactor( Light light, uint shadowMap, float def ) {
|
||||
return eyeDepth < texture(samplerTextures[shadowMap], uv).r - bias ? 0.0 : factor;
|
||||
}
|
||||
for ( int i = 0; i < samples; ++i ) {
|
||||
// int index = i;
|
||||
// int index = int( float(samples) * random(gl_FragCoord.xyy, i) ) % samples;
|
||||
int index = int( float(samples) * random(floor(position.world.xyz * 1000.0), i)) % samples;
|
||||
float lightDepth = texture(samplerTextures[shadowMap], uv + poissonDisk[index] / 700.0 ).r;
|
||||
if ( eyeDepth < lightDepth - bias ) factor -= 1.0 / samples;
|
||||
}
|
||||
return factor;
|
||||
}
|
||||
|
||||
vec3 hslToRgb(vec3 HSL) {
|
||||
vec3 RGB; {
|
||||
float H = HSL.x;
|
||||
@ -722,7 +731,7 @@ void main() {
|
||||
light.position.xyz = vec3(ubo.matrices.view[inPushConstantPass] * vec4(light.position.xyz, 1));
|
||||
|
||||
if ( validTextureIndex(light.mapIndex) ) {
|
||||
float factor = shadowFactor( light, light.mapIndex, 0.0 );
|
||||
float factor = shadowFactor( light, light.mapIndex );
|
||||
light.power *= factor;
|
||||
litFactor += light.power;
|
||||
}
|
||||
|
@ -112,6 +112,7 @@ void main() {
|
||||
}
|
||||
if ( C.a == 0 ) discard;
|
||||
}
|
||||
#if 0
|
||||
if ( validTextureIndex( material.indexLightmap ) ) {
|
||||
#if UF_DEFERRED_SAMPLING
|
||||
outUvs = inSt;
|
||||
@ -121,6 +122,7 @@ void main() {
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#if !UF_DEFERRED_SAMPLING
|
||||
// sample normal
|
||||
if ( validTextureIndex( material.indexNormal ) ) {
|
||||
|
@ -52,12 +52,12 @@ int main(int argc, char** argv){
|
||||
uf::hooks.call(hook, json);
|
||||
}
|
||||
#if UF_ENV_DREAMCAST
|
||||
UF_TIMER_MULTITRACE_START("==== START FRAME ====");
|
||||
// UF_TIMER_MULTITRACE_START("==== START FRAME ====");
|
||||
ext::render();
|
||||
UF_TIMER_MULTITRACE("RENDER");
|
||||
// UF_TIMER_MULTITRACE("RENDER");
|
||||
ext::tick();
|
||||
UF_TIMER_MULTITRACE("TICK");
|
||||
UF_TIMER_MULTITRACE_END("==== END FRAME ====");
|
||||
// UF_TIMER_MULTITRACE("TICK");
|
||||
// UF_TIMER_MULTITRACE_END("==== END FRAME ====");
|
||||
#else
|
||||
client::render();
|
||||
ext::render();
|
||||
|
@ -56,3 +56,11 @@
|
||||
GL_VALIDATION_MESSAGE("[Validation Error] " << #f << ": " << errorString); \
|
||||
} \
|
||||
}
|
||||
|
||||
#if 0
|
||||
#define GL_MUTEX_LOCK() ext::opengl::mutex.lock();
|
||||
#define GL_MUTEX_UNLOCK() ext::opengl::mutex.unlock();
|
||||
#else
|
||||
#define GL_MUTEX_LOCK();
|
||||
#define GL_MUTEX_UNLOCK();
|
||||
#endif
|
@ -245,7 +245,7 @@ void ext::opengl::CommandBuffer::submit() {
|
||||
GL_ERROR_CHECK(glClearColor(info->color[0], info->color[1], info->color[2], info->color[3]));
|
||||
GL_ERROR_CHECK(glClearDepth(info->depth));
|
||||
GL_ERROR_CHECK(glClear(info->bits));
|
||||
GL_ERROR_CHECK(glLightModelfv(GL_LIGHT_MODEL_AMBIENT, &info->color[0]));
|
||||
// GL_ERROR_CHECK(glLightModelfv(GL_LIGHT_MODEL_AMBIENT, &info->color[0]));
|
||||
} break;
|
||||
case ext::opengl::enums::Command::VIEWPORT: {
|
||||
InfoViewport* info = (InfoViewport*) header;
|
||||
|
@ -1402,7 +1402,7 @@ void ext::opengl::Graphic::record( CommandBuffer& commandBuffer, GraphicDescript
|
||||
|
||||
for ( auto& attribute : descriptor.geometry.attributes.descriptor ) {
|
||||
if ( attribute.name == "position" ) vertexAttributePosition = attribute;
|
||||
else if ( attribute.name == "normal" ) vertexAttributeNormal = attribute;
|
||||
// else if ( attribute.name == "normal" ) vertexAttributeNormal = attribute;
|
||||
else if ( attribute.name == "color" ) vertexAttributeColor = attribute;
|
||||
else if ( attribute.name == "uv" ) vertexAttributeUv = attribute;
|
||||
else if ( attribute.name == "st" ) vertexAttributeSt = attribute;
|
||||
|
@ -142,10 +142,16 @@ void UF_API ext::opengl::removeRenderMode( ext::opengl::RenderMode* mode, bool f
|
||||
void UF_API ext::opengl::initialize() {
|
||||
device.initialize();
|
||||
// swapchain.initialize( device );
|
||||
if ( 0 ) {
|
||||
{
|
||||
std::vector<uint8_t> pixels = {
|
||||
255, 0, 255, 255, 0, 0, 0, 255,
|
||||
0, 0, 0, 255, 255, 0, 255, 255,
|
||||
255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255,
|
||||
255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255,
|
||||
255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255,
|
||||
255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255,
|
||||
0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255,
|
||||
0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255,
|
||||
0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255,
|
||||
0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255,
|
||||
};
|
||||
Texture2D::empty.sampler.descriptor.filter.min = uf::renderer::enums::Filter::NEAREST;
|
||||
Texture2D::empty.sampler.descriptor.filter.mag = uf::renderer::enums::Filter::NEAREST;
|
||||
@ -301,7 +307,6 @@ void UF_API ext::opengl::tick(){
|
||||
if ( ext::opengl::states::resized || ext::opengl::settings::experimental::rebuildOnTickBegin ) {
|
||||
ext::opengl::states::rebuild = true;
|
||||
}
|
||||
if ( uf::scene::useGraph ) {
|
||||
auto graph = uf::scene::generateGraph();
|
||||
for ( auto entity : graph ) {
|
||||
if ( !entity->hasComponent<uf::Graphic>() ) continue;
|
||||
@ -310,18 +315,6 @@ if ( uf::scene::useGraph ) {
|
||||
graphic.initializePipeline();
|
||||
ext::opengl::states::rebuild = true;
|
||||
}
|
||||
} else {
|
||||
for ( uf::Scene* scene : uf::scene::scenes ) {
|
||||
if ( !scene ) continue;
|
||||
scene->process([&]( uf::Entity* entity ) {
|
||||
if ( !entity->hasComponent<uf::Graphic>() ) return;
|
||||
ext::opengl::Graphic& graphic = entity->getComponent<uf::Graphic>();
|
||||
if ( graphic.initialized || !graphic.process || graphic.initialized ) return;
|
||||
graphic.initializePipeline();
|
||||
ext::opengl::states::rebuild = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
for ( auto& renderMode : renderModes ) {
|
||||
if ( !renderMode ) continue;
|
||||
if ( !renderMode->device ) {
|
||||
@ -391,23 +384,12 @@ void UF_API ext::opengl::destroy() {
|
||||
synchronize();
|
||||
|
||||
Texture2D::empty.destroy();
|
||||
if ( uf::scene::useGraph ) {
|
||||
auto graph = uf::scene::generateGraph();
|
||||
for ( auto entity : graph ) {
|
||||
if ( !entity->hasComponent<uf::Graphic>() ) continue;
|
||||
uf::Graphic& graphic = entity->getComponent<uf::Graphic>();
|
||||
graphic.destroy();
|
||||
}
|
||||
} else {
|
||||
for ( uf::Scene* scene : uf::scene::scenes ) {
|
||||
if ( !scene ) continue;
|
||||
scene->process([&]( uf::Entity* entity ) {
|
||||
if ( !entity->hasComponent<uf::Graphic>() ) return;
|
||||
uf::Graphic& graphic = entity->getComponent<uf::Graphic>();
|
||||
graphic.destroy();
|
||||
});
|
||||
}
|
||||
}
|
||||
for ( auto& renderMode : renderModes ) {
|
||||
if ( !renderMode ) continue;
|
||||
renderMode->destroy();
|
||||
|
@ -1,5 +1,6 @@
|
||||
#if UF_USE_OPENGL
|
||||
|
||||
#include <uf/ext/opengl/ogl.h>
|
||||
#include <uf/ext/opengl/opengl.h>
|
||||
#include <uf/ext/opengl/rendermode.h>
|
||||
#include <uf/ext/opengl/initializers.h>
|
||||
@ -146,6 +147,7 @@ void ext::opengl::RenderMode::render() {
|
||||
//UF_TIMER_TRACE_INIT();
|
||||
#if UF_USE_OPENGL_GLDC
|
||||
glKosSwapBuffers();
|
||||
// profiler_print_stats();
|
||||
#else
|
||||
glutSwapBuffers();
|
||||
#endif
|
||||
|
@ -73,17 +73,19 @@ void ext::opengl::BaseRenderMode::initialize( Device& device ) {
|
||||
GL_ERROR_CHECK(glEnable(GL_BLEND));
|
||||
GL_ERROR_CHECK(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
|
||||
|
||||
GL_ERROR_CHECK(glEnable(GL_LIGHTING));
|
||||
// GL_ERROR_CHECK(glEnable(GL_LIGHTING));
|
||||
// GL_ERROR_CHECK(glEnable(GL_NORMALIZE));
|
||||
GL_ERROR_CHECK(glEnable(GL_COLOR_MATERIAL));
|
||||
GL_ERROR_CHECK(glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE));
|
||||
GL_ERROR_CHECK(glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR));
|
||||
// GL_ERROR_CHECK(glEnable(GL_COLOR_MATERIAL));
|
||||
// GL_ERROR_CHECK(glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE));
|
||||
// GL_ERROR_CHECK(glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR));
|
||||
#if UF_USE_DREAMCAST
|
||||
GL_ERROR_CHECK(glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 0));
|
||||
GL_ERROR_CHECK(glShadeModel(GL_SMOOTH));
|
||||
//profiler_enable();
|
||||
GL_ERROR_CHECK(glEnable(GL_NEARZ_CLIPPING_KOS));
|
||||
// GL_ERROR_CHECK(glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 0));
|
||||
// GL_ERROR_CHECK(glShadeModel(GL_SMOOTH));
|
||||
#else
|
||||
GL_ERROR_CHECK(glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1));
|
||||
GL_ERROR_CHECK(glShadeModel(GL_SMOOTH));
|
||||
// GL_ERROR_CHECK(glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1));
|
||||
// GL_ERROR_CHECK(glShadeModel(GL_SMOOTH));
|
||||
#endif
|
||||
|
||||
ext::opengl::RenderMode::initialize( device );
|
||||
|
@ -67,7 +67,11 @@ bool ext::opengl::Texture::generated() const {
|
||||
}
|
||||
void ext::opengl::Texture::destroy() {
|
||||
if ( !device ) return;
|
||||
if ( generated() ) GL_ERROR_CHECK(glDeleteTextures(1, &image));
|
||||
if ( generated() ) {
|
||||
GL_MUTEX_LOCK();
|
||||
GL_ERROR_CHECK(glDeleteTextures(1, &image));
|
||||
GL_MUTEX_UNLOCK();
|
||||
}
|
||||
image = GL_NULL_HANDLE;
|
||||
}
|
||||
void ext::opengl::Texture::loadFromFile(
|
||||
@ -210,11 +214,13 @@ void ext::opengl::Texture::fromBuffers(
|
||||
this->updateDescriptors();
|
||||
if ( data ) this->update( data, bufferSize, 0 );
|
||||
#else
|
||||
GL_MUTEX_LOCK();
|
||||
GL_ERROR_CHECK(glGenTextures(1, &image));
|
||||
GL_ERROR_CHECK(glBindTexture(viewType, image));
|
||||
GL_ERROR_CHECK(glTexParameteri(viewType, GL_TEXTURE_MIN_FILTER, sampler.descriptor.filter.min));
|
||||
GL_ERROR_CHECK(glTexParameteri(viewType, GL_TEXTURE_MAG_FILTER, sampler.descriptor.filter.mag));
|
||||
GL_ERROR_CHECK(glBindTexture(viewType, 0));
|
||||
GL_MUTEX_UNLOCK();
|
||||
if ( data ) this->update( data, bufferSize, 0 );
|
||||
this->updateDescriptors();
|
||||
#endif
|
||||
@ -244,9 +250,11 @@ void ext::opengl::Texture::update( uf::Image& image, uint32_t layer ) {
|
||||
void ext::opengl::Texture::update( void* data, size_t bufferSize, uint32_t layer ) {
|
||||
#if UF_ENV_DREAMCAST
|
||||
if ( internalFormat > 0 ) {
|
||||
GL_MUTEX_LOCK();
|
||||
GL_ERROR_CHECK(glBindTexture(viewType, image));
|
||||
GL_ERROR_CHECK(glCompressedTexImage2DARB( viewType, 0, internalFormat, width, height, 0, bufferSize, data));
|
||||
GL_ERROR_CHECK(glBindTexture(viewType, 0));
|
||||
GL_MUTEX_UNLOCK();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
@ -274,6 +282,7 @@ void ext::opengl::Texture::update( void* data, size_t bufferSize, uint32_t layer
|
||||
format = GL_RGBA;
|
||||
break;
|
||||
}
|
||||
GL_MUTEX_LOCK();
|
||||
GL_ERROR_CHECK(glBindTexture(viewType, image));
|
||||
switch ( viewType ) {
|
||||
case enums::Image::VIEW_TYPE_2D: { GL_ERROR_CHECK(glTexImage2D(viewType, 0, format, width, height, 0, format, type, data)); } break;
|
||||
@ -282,6 +291,7 @@ void ext::opengl::Texture::update( void* data, size_t bufferSize, uint32_t layer
|
||||
#endif
|
||||
}
|
||||
GL_ERROR_CHECK(glBindTexture(viewType, 0));
|
||||
GL_MUTEX_UNLOCK();
|
||||
}
|
||||
|
||||
void ext::opengl::Texture::generateMipmaps( uint32_t layer ) {
|
||||
|
@ -708,6 +708,12 @@ void EXT_API ext::tick() {
|
||||
TIMER( every ) {
|
||||
// UF_DEBUG_MSG("Framerate: " << (1.0/times.deltaTime) << " FPS | Frametime: " << (times.deltaTime * 1000) << "ms");
|
||||
UF_DEBUG_MSG("System: " << (every * 1000.0/::times.frames) << " ms/frame | Time: " << time << " | Frames: " << ::times.frames << " | FPS: " << ::times.frames / time);
|
||||
#if UF_ENV_DREAMCAST
|
||||
// pvr_stats_t stats;
|
||||
// pvr_get_stats(&stats);
|
||||
// UF_DEBUG_MSG("PVR stats: " << stats.frame_last_time << " ms | " << stats.frame_rate << " fps | " << stats.reg_last_time << " ms | " << stats.rnd_last_time << " ms | " << stats.vtx_buffer_used << " bytes | " << stats.vtx_buffer_used_max << " bytes | " << stats.buf_last_time << " ms" );
|
||||
#endif
|
||||
|
||||
::times.frames = 0;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user