Commit for 2020.09.16.7z
This commit is contained in:
parent
1acffac153
commit
e16ade7185
@ -4,6 +4,7 @@
|
||||
layout (binding = 1) uniform sampler samp;
|
||||
layout (binding = 2) uniform texture2D albedoTexture;
|
||||
layout (binding = 3) uniform texture2D normalTexture;
|
||||
layout (binding = 4) uniform texture2D positionTexture;
|
||||
|
||||
struct Cursor {
|
||||
vec2 position;
|
||||
@ -17,6 +18,7 @@ layout (location = 2) in Cursor inCursor;
|
||||
|
||||
layout (location = 0) out vec4 outAlbedoSpecular;
|
||||
layout (location = 1) out vec4 outNormal;
|
||||
layout (location = 2) out vec4 outPosition;
|
||||
|
||||
void main() {
|
||||
outAlbedoSpecular = texture(sampler2D(albedoTexture, samp), inUv);
|
||||
@ -25,6 +27,7 @@ void main() {
|
||||
// uv.x = 1-uv.x;
|
||||
outAlbedoSpecular = texture(sampler2D(albedoTexture, samp), uv);
|
||||
outNormal = texture(sampler2D(normalTexture, samp), uv);
|
||||
outPosition = texture(sampler2D(positionTexture, samp), uv);
|
||||
if ( outAlbedoSpecular.a < 0.01f ) outAlbedoSpecular = vec4(0,0,0,1);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@ layout (input_attachment_index = 0, binding = 1) uniform subpassInput samplerAlb
|
||||
layout (input_attachment_index = 0, binding = 2) uniform subpassInput samplerNormal;
|
||||
layout (input_attachment_index = 0, binding = 3) uniform subpassInput samplerPosition;
|
||||
// layout (input_attachment_index = 0, binding = 4) uniform subpassInput samplerDepth;
|
||||
layout (binding = 5) uniform sampler2D samplerShadows[BASE_LIGHTS_SIZE];
|
||||
layout (binding = 5) uniform sampler2D samplerShadows[LIGHTS];
|
||||
|
||||
layout (location = 0) in vec2 inUv;
|
||||
layout (location = 1) in flat uint inPushConstantPass;
|
||||
@ -86,20 +86,26 @@ void phong( Light light, vec4 albedoSpecular, inout vec3 i ) {
|
||||
}
|
||||
|
||||
bool debugShadow( Light light, uint i ) {
|
||||
return false;
|
||||
// return false;
|
||||
|
||||
{
|
||||
outFragColor.rgb = texture(samplerShadows[i], inUv).rgb;
|
||||
outFragColor.a = 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
vec4 positionClip = light.projection * light.view * vec4(position.world, 1.0);
|
||||
positionClip.xyz /= positionClip.w;
|
||||
float lightDepth = texture(samplerShadows[i], positionClip.xy * 0.5 + 0.5).r;
|
||||
|
||||
float eyeDepth = positionClip.z;
|
||||
eyeDepth = lightDepth;
|
||||
// eyeDepth = lightDepth;
|
||||
float bias = 0.0005;
|
||||
|
||||
if ( positionClip.x < -1 || positionClip.x >= 1 ) eyeDepth = 1;
|
||||
else if ( positionClip.y < -1 || positionClip.y >= 1 ) eyeDepth = 1;
|
||||
else if ( positionClip.z < 0 || positionClip.z >= 1 ) eyeDepth = 1;
|
||||
// else eyeDepth /= 0.00526;
|
||||
else eyeDepth /= 0.00526;
|
||||
|
||||
outFragColor.rgb = vec3( 1 - eyeDepth );
|
||||
outFragColor.a = 1;
|
||||
@ -110,7 +116,7 @@ bool debugShadow( Light light, uint i ) {
|
||||
float shadowFactor( Light light, uint i ) {
|
||||
vec4 positionClip = light.projection * light.view * vec4(position.world, 1.0);
|
||||
positionClip.xyz /= positionClip.w;
|
||||
float lightDepth = texture(samplerShadows[i], positionClip.xy * 0.5 + 0.5).r;
|
||||
float lightDepth = texture(samplerShadows[(i*4)+3], positionClip.xy * 0.5 + 0.5).r;
|
||||
float eyeDepth = positionClip.z;
|
||||
float bias = 0.0005;
|
||||
// bias = max(0.05 * (1.0 - dot(normal.eye, light.position.xyz - position.eye)), bias);
|
||||
@ -138,6 +144,19 @@ void main() {
|
||||
vec4 positionWorld = iView * vec4(position.eye, 1);
|
||||
position.world = positionWorld.xyz;
|
||||
}
|
||||
/*
|
||||
{
|
||||
for ( int i = 0; i < LIGHTS; ++i ) {
|
||||
outFragColor.rgb = texture(samplerShadows[i], inUv).rgb;
|
||||
}
|
||||
float depth = texture(samplerShadows[3], inUv).r;
|
||||
depth /= 0.00526;
|
||||
outFragColor.rgb = vec3(1 - depth);
|
||||
// outFragColor.rgb = texture(samplerShadows[0], inUv).rgb;
|
||||
outFragColor.a = 1;
|
||||
return;
|
||||
}
|
||||
*/
|
||||
/*
|
||||
{
|
||||
mat4 iProj = inverse( ubo.matrices.projection[inPushConstantPass] );
|
||||
@ -164,6 +183,7 @@ void main() {
|
||||
|
||||
vec3 fragColor = albedoSpecular.rgb * ubo.ambient.rgb;
|
||||
bool lit = false;
|
||||
|
||||
for ( uint i = 0; i < LIGHTS; ++i ) {
|
||||
Light light = ubo.lights[i];
|
||||
|
||||
@ -171,7 +191,6 @@ void main() {
|
||||
lit = true;
|
||||
|
||||
light.position.xyz = vec3(ubo.matrices.view[inPushConstantPass] * vec4(light.position.xyz, 1));
|
||||
|
||||
if ( light.shadowed > 0 ) {
|
||||
float shadowFactor = shadowFactor( light, i );
|
||||
if ( shadowFactor <= 0.0001 ) continue;
|
||||
|
||||
@ -148,12 +148,16 @@ void uf::Scene::tick() {
|
||||
if ( entity->hasComponent<ext::vulkan::RenderTargetRenderMode>() ) {
|
||||
auto& renderMode = entity->getComponent<ext::vulkan::RenderTargetRenderMode>();
|
||||
auto& renderTarget = renderMode.renderTarget;
|
||||
|
||||
uint8_t i = 0;
|
||||
for ( auto& attachment : renderTarget.attachments ) {
|
||||
if ( !(attachment.usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) ) continue;
|
||||
// if ( !(attachment.usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) ) continue;
|
||||
// if ( (attachment.usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) ) continue;
|
||||
if ( (attachment.layout == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR) ) continue;
|
||||
auto& texture = blitter.material.textures.emplace_back();
|
||||
texture.aliasAttachment(attachment);
|
||||
light.type.y = true;
|
||||
break;
|
||||
// break;
|
||||
}
|
||||
} else {
|
||||
light.type.y = false;
|
||||
@ -193,30 +197,48 @@ const uf::Entity* uf::Scene::getController() const {
|
||||
}
|
||||
*/
|
||||
uf::Entity* uf::Scene::getController() {
|
||||
static uf::Entity* cachedController = NULL;
|
||||
if ( ext::vulkan::currentRenderMode ) {
|
||||
static ext::vulkan::RenderMode* cachedRenderMode = NULL;
|
||||
auto& renderMode = *ext::vulkan::currentRenderMode;
|
||||
std::string name = renderMode.name;
|
||||
auto split = uf::string::split( name, ": " );
|
||||
if ( split.front() == "Render Target" ) {
|
||||
|
||||
if ( cachedRenderMode == &renderMode && cachedController && cachedController->getUid() > 0 ) {
|
||||
return cachedController;
|
||||
}
|
||||
cachedController = NULL;
|
||||
cachedRenderMode = &renderMode;
|
||||
auto split = uf::string::split( renderMode.name, ":" );
|
||||
if ( split.front() == "RT" ) {
|
||||
uint64_t uid = std::stoi( split.back() );
|
||||
uf::Entity* ent = this->findByUid( uid );
|
||||
if ( ent ) return ent;
|
||||
if ( ent ) return cachedController = ent;
|
||||
}
|
||||
}
|
||||
return this->findByName("Player");
|
||||
if ( cachedController && cachedController->getUid() > 0 ) return cachedController;
|
||||
return cachedController = this->findByName("Player");
|
||||
// return this;
|
||||
}
|
||||
const uf::Entity* uf::Scene::getController() const {
|
||||
static const uf::Entity* cachedController = NULL;
|
||||
if ( ext::vulkan::currentRenderMode ) {
|
||||
static ext::vulkan::RenderMode* cachedRenderMode = NULL;
|
||||
auto& renderMode = *ext::vulkan::currentRenderMode;
|
||||
std::string name = renderMode.name;
|
||||
auto split = uf::string::split( name, ": " );
|
||||
if ( split.front() == "Render Target" ) {
|
||||
|
||||
if ( cachedRenderMode == &renderMode && cachedController && cachedController->getUid() > 0 ) {
|
||||
return cachedController;
|
||||
}
|
||||
cachedController = NULL;
|
||||
cachedRenderMode = &renderMode;
|
||||
auto split = uf::string::split( renderMode.name, ":" );
|
||||
if ( split.front() == "RT" ) {
|
||||
uint64_t uid = std::stoi( split.back() );
|
||||
const uf::Entity* ent = this->findByUid( uid );
|
||||
if ( ent ) return ent;
|
||||
if ( ent ) return cachedController = ent;
|
||||
}
|
||||
}
|
||||
return this->findByName("Player");
|
||||
if ( cachedController && cachedController->getUid() > 0 ) return cachedController;
|
||||
return cachedController = this->findByName("Player");
|
||||
// return this;
|
||||
}
|
||||
|
||||
std::vector<uf::Scene*> uf::scene::scenes;
|
||||
|
||||
@ -420,8 +420,8 @@ void ext::vulkan::Pipeline::update( Graphic& graphic ) {
|
||||
for ( auto& input : subpass.inputs ) {
|
||||
inputDescriptors.push_back(ext::vulkan::initializers::descriptorImageInfo(
|
||||
renderTarget.attachments[input.attachment].view,
|
||||
input.layout
|
||||
// input.layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL ? VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL : input.layout
|
||||
// input.layout
|
||||
input.layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL ? VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL : input.layout
|
||||
));
|
||||
}
|
||||
{
|
||||
@ -446,8 +446,8 @@ void ext::vulkan::Pipeline::update( Graphic& graphic ) {
|
||||
if ( layout.descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER && !d.sampler )
|
||||
d.sampler = emptyTexture.sampler.sampler;
|
||||
|
||||
// if ( d.imageLayout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL )
|
||||
// d.imageLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
|
||||
if ( d.imageLayout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL )
|
||||
d.imageLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
|
||||
}
|
||||
imageInfos.push_back( d );
|
||||
}
|
||||
|
||||
@ -302,13 +302,13 @@ void ext::vulkan::tick() {
|
||||
ext::vulkan::mutex.unlock();
|
||||
}
|
||||
void ext::vulkan::render() {
|
||||
// ext::vulkan::mutex.lock();
|
||||
if ( hasRenderMode("", true) ) {
|
||||
RenderMode& primary = getRenderMode("", true);
|
||||
auto it = std::find( renderModes.begin(), renderModes.end(), &primary );
|
||||
if ( it + 1 != renderModes.end() ) std::rotate( it, it + 1, renderModes.end() );
|
||||
}
|
||||
|
||||
ext::vulkan::mutex.lock();
|
||||
for ( auto& renderMode : renderModes ) {
|
||||
if ( !renderMode ) continue;
|
||||
ext::vulkan::currentRenderMode = renderMode;
|
||||
@ -317,7 +317,7 @@ void ext::vulkan::render() {
|
||||
}
|
||||
|
||||
ext::vulkan::currentRenderMode = NULL;
|
||||
ext::vulkan::mutex.unlock();
|
||||
// ext::vulkan::mutex.unlock();
|
||||
}
|
||||
void ext::vulkan::destroy() {
|
||||
ext::vulkan::mutex.lock();
|
||||
|
||||
@ -14,7 +14,7 @@ void ext::Light::initialize() {
|
||||
auto& camera = this->getComponent<uf::Camera>();
|
||||
if ( metadata["light"]["shadows"]["enabled"].asBool() ) {
|
||||
auto& renderMode = this->getComponent<ext::vulkan::RenderTargetRenderMode>();
|
||||
std::string name = "Render Target: " + std::to_string((int) this->getUid());
|
||||
std::string name = "RT:" + std::to_string((int) this->getUid());
|
||||
ext::vulkan::addRenderMode( &renderMode, name );
|
||||
if ( metadata["light"]["shadows"]["resolution"].isArray() ) {
|
||||
renderMode.width = metadata["light"]["shadows"]["resolution"][0].asUInt64();
|
||||
|
||||
@ -69,7 +69,7 @@ void ext::Portal::initialize() {
|
||||
}
|
||||
{
|
||||
auto& renderMode = this->getComponent<ext::vulkan::RenderTargetRenderMode>();
|
||||
std::string name = "Render Target: " + std::to_string((int) this->getUid());
|
||||
std::string name = "RT:" + std::to_string((int) this->getUid());
|
||||
ext::vulkan::addRenderMode( &renderMode, name );
|
||||
if ( ext::openvr::enabled ) {
|
||||
ext::openvr::initialize();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user