Advertisement Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

256 Neutral

About renderkid

  • Rank
  1. Hey there,   So I have been having some problems with SSAO shader in Deffered Rendering for very long long time. And mostly due to this problem stopped doing anything for several months. So this time decided to ask for help as would like to solve this nastiness and keep on learning different shader techniques.   I mostly tried to follow all SSAO tutorials and checked shader examples (   I also profilled in RenderDoc and data seems very similar. But for some reason SSAO does not work. Here is the screen with range check (the white framebuffer image show ssao outpout): [attachment=34881:SSAO1.png]   Here is the image without range check (the dark framebuffer image show ssao output): As you can see (its dark pitch black... No idea really why) [attachment=34880:ssao2.png]     In first shader pass I generate textures for deffered shader and SSAO. This code generates normals in vertex shader for SSAO: mat3 normalMatrix = transpose(inverse(mat3(mvMatrix))); vs_out.normal = normalMatrix * inNormal; and I convert vertices into model space as my deffered calculation is in modelspace vs_out.ws_coords = vec3(ubo.modelMatrix * tmpPos); In fragment shader I pass it like this: outNormal = vec4(normalize(fs_in.normal) * 0.5 + 0.5, LinearizeDepth(gl_FragCoord.z)); also I compress the texture for better perfomance: //Position outvec0.x = packHalf2x16(fs_in.ws_coords.xy); //Pos And Specular outvec0.y = packHalf2x16(vec2(fs_in.ws_coords.z, specularTexture.x)); When I come to my SSAO pass (in fragment shader): float SSAOAlgo0() { ivec2 P1 = ivec2(inUV * textureSize(PosSpecularPacked, 0)); uvec2 uvec2_PosSpecularPacked = texelFetch(PosSpecularPacked, P1, 0).rg; vec4 normalDepthTexture = texture(NormalDepth, inUV, 0); //Get position and depth texture vec2 tempPosition0 = unpackHalf2x16(uvec2_PosSpecularPacked.x); vec2 tempPosAndSpec = unpackHalf2x16(uvec2_PosSpecularPacked.y); vec3 fragPos = vec3(tempPosition0, tempPosAndSpec.x); //Convert frag pos to view space as the fragPos is in modelSpace at the moment fragPos = vec3(ubo.view * vec4(fragPos, 1.0f)); //fragPos.y = -fragPos.y; //Get normal vec3 normal = normalize( * 2.0 - 1.0); //Random vec using noise lookup ivec2 texDim = textureSize(NormalDepth, 0); ivec2 noiseDim = textureSize(texNoise, 0); const vec2 noiseUV = vec2(float(texDim.x)/float(noiseDim.x), float(texDim.y)/(noiseDim.y)) * inUV; vec3 randomVec = texture(texNoise, noiseUV).xyz * 2.0 - 1.0; // Create TBN change-of-basis matrix: from tangent-space to view-space vec3 tangent = normalize(randomVec - normal * dot(randomVec, normal)); vec3 bitangent = cross(normal, tangent); mat3 TBN = mat3(tangent, bitangent, normal); // Iterate over the sample kernel and calculate occlusion factor float f_occlusion = 0.0f; for(int i = 0; i < SSAO_KERNEL_SIZE; ++i) { // get sample position vec3 Sample = TBN * ubossaokernel.samples[i].xyz; // From tangent to view-space Sample = fragPos + Sample * SSAO_RADIUS; // project sample position (to sample texture) (to get position on screen/texture) vec4 offset = vec4(Sample, 1.0f); offset = ubo.projection * offset; // from view to clip-space /= offset.w; // perspective divide = * 0.5f + 0.5f; // transform to range 0.0 - 1.0 // get sample depth float sampleDepth = -texture(NormalDepth, offset.xy, 0).w; // Get depth value of kernel sample // range check & accumulate //#define RANGE_CHECK #ifdef RANGE_CHECK float rangeCheck = smoothstep(0.0f, 1.0f, SSAO_RADIUS / abs(fragPos.z - sampleDepth )); f_occlusion += (sampleDepth >= Sample.z ? 1.0f : 0.0f) * rangeCheck; #else f_occlusion += (sampleDepth >= Sample.z ? 1.0f : 0.0f); #endif } f_occlusion = 1.0f - (f_occlusion / float(SSAO_KERNEL_SIZE)); return f_occlusion; } void main() { FragColor = SSAOAlgo0(); } SSAO kernel and Noise generation looks like this: void Renderer::InitializeSSAOData() { std::uniform_real_distribution<float> randomFloats(0.0f, 1.0f); // random floats between 0.0 - 1.0 std::default_random_engine generator; for (uint32_t i = 0; i < 64; ++i) { glm::vec3 sample( randomFloats(generator) * 2.0f - 1.0f, randomFloats(generator) * 2.0f - 1.0f, randomFloats(generator) ); sample = glm::normalize(sample); sample *= randomFloats(generator); float scale = scale = static_cast<float>(i) / 64.0; scale = lerp(0.1f, 1.0f, scale*scale); sample *= scale; uboSSAOKernel.ssaoKernel[i] = glm::vec4(sample, 0.0f); } std::vector<glm::vec4> ssaoNoise; ssaoNoise.reserve(16); for (uint32_t i = 0; i < 16; i++) { glm::vec4 noise( randomFloats(generator) * 2.0 - 1.0, randomFloats(generator) * 2.0 - 1.0, 0.0f, 0.0f); ssaoNoise.push_back(noise); } //Generates texture. But cant see anything in debugger in it. Better generate on gpu... at the moment GenerateTexture(ssaoNoise, 4, 4, 1, VK_FORMAT_R32G32B32A32_SFLOAT, &m_NoiseGeneratedTexture, VK_IMAGE_USAGE_SAMPLED_BIT, VK_FILTER_NEAREST); //Send data void * pData; VK_CHECK_RESULT(vkMapMemory(m_pWRenderer->m_SwapChain.device, uniformData.ssaokernel.memory, 0, sizeof(uboSSAOKernel), 0, (void **)&pData)); memcpy(pData, &uboSSAOKernel, sizeof(uboSSAOKernel)); vkUnmapMemory(m_pWRenderer->m_SwapChain.device, uniformData.ssaokernel.memory); } The full code can be found in here: (       Thanks.
  2. I'm using AMD RX480 Radeon Software Version16.11.4 Hmmm. Yea.. That's really strange then... But yea. Creating each framebuffer as R32 totally works. But little bit more painful if using packHalf2x16
  3. Hi all,   Does anyone have explanation why it is like this? I really do not need RGBA as all information fits in 32RGB texture. So having additional 32A just wastes bandwidth. [sharedmedia=core:attachments:34218]       I get this error: [sharedmedia=core:attachments:34219]     But it works fine with RGBA framebuffer texture [sharedmedia=core:attachments:34220]        
  4. Yea, I did the same thing in the end. It was still little bit weird that I haven't had any problems before the new driver update..... Thanks for the info.
  5. I also noticed that old Imgui Vulkan code was not working anymore but I saw that he does the same thing for in and out.   Is there any specification or explanation more about this?
  6. Hi,   Before updating from 16.10.3 AMD Driver version to 16.11.2 I have not had any problem with shader code. But with new update. vkCreateGraphicsPipelines fails with error:   "The thread tried to read or write data that is misaligned on hardware that does not provide alignment. For example, 16-bit values must be aligned on 2-byte boundaries; 32-bit values on 4-byte boundaries, and so on."     I tried to find the problem why it is like this and what I noticed: Assigning and passing data like this from  vertex to fragment resulted in these problems.   Vertex Shader:   out VS_OUT {     vec3 eyeDir;     vec3 lightDir;     vec3 normal;     vec2 texcoord; } vs_out;   void main() {     vs_out.texcoord = vec2(1.0); //Will give here error for access. Uncomenting this line will run shader properly. }   Fragment Shader: in VS_OUT {     vec3 eyeDir;     vec3 lightDir;     vec3 normal; vec2 texcoord; } fs_in;     but once I added layout and location to them: Vertex Shader: layout (location = 5) out VS_OUT {     vec3 eyeDir;     vec3 lightDir;     vec3 normal; vec2 texcoord; } vs_out;   Fragment Shader: layout (location = 5) in VS_OUT {     vec3 eyeDir;     vec3 lightDir;     vec3 normal; vec2 texcoord; } fs_in;   The shader code was not failing anymore.     Can anyone confirm if anyone have the same problem with new AMD Driver?  
  7. renderkid

    BC3 format is not loaded correctly

    From a quick glance you're missing a break in your switch.     Daaaamn. Didn't notice it. But yeaa..... Fixed the problem.... Thanks a lot mate :)
  8. Hi Guys,   I been working on some vulkan api examples. I tried loading bc3 texture but for some reason it is not loaded correctly. [attachment=33219:bc3Wrong.png]   This is how it looks in AMD compressonator: [attachment=33220:spec_color.png]   Loading all the other texture formats as bc1, bc2, bc5, bc7. Is fine. I'm using GLI( texture loading. The code for loading specific texture format looks like this: gli::texture2d tex2D(gli::load(filename.c_str())); assert(!tex2D.empty()); if (tex2D.empty()) { return false; } //Find correct texture format gli::texture::format_type type = tex2D.format(); switch (type) { case gli::texture::format_type::FORMAT_RGBA_BP_UNORM_BLOCK16: format = VkFormat::VK_FORMAT_BC7_UNORM_BLOCK; break; case gli::texture::format_type::FORMAT_RGBA_DXT3_UNORM_BLOCK16: format = VkFormat::VK_FORMAT_BC2_UNORM_BLOCK; break; case gli::texture::format_type::FORMAT_RG_ATI2N_UNORM_BLOCK16: format = VkFormat::VK_FORMAT_BC5_UNORM_BLOCK; break; case gli::texture::format_type::FORMAT_R_ATI1N_UNORM_BLOCK8: format = VkFormat::VK_FORMAT_BC4_UNORM_BLOCK; break; case gli::texture::format_type::FORMAT_RGBA_DXT5_UNORM_BLOCK16: format = VkFormat::VK_FORMAT_BC3_UNORM_BLOCK; case gli::texture::format_type::FORMAT_RGBA_DXT1_UNORM_BLOCK8: format = VkFormat::VK_FORMAT_BC1_RGBA_UNORM_BLOCK; break; } You can find texture loading code on:   The project is Shadow Mapping.     Do not really know what it is the problem....
  9. Hi all,   I tried to find this explanation in the books but could not find anything.     The problem. When I turn on index buffer after GL_ARRAY_BUFFER. Everythings renders properly for (int i = 0; i < model.meshes.size(); i++) { MD5Mesh* m = &model.meshes[i]; m->UpdateMesh(m, jointFrame, nullptr, m->deformInfo); deformInfo_t* vert = m->deformInfo; drawVert* vertD = vert->verts; glBindTexture(GL_TEXTURE_2D, tex_id[i]); buffer[i].EnableVAO(); buffer[i].EnableVBO(); index[i].EnableVBO(); buffer[i].Update(vert->verts, sizeof(vertD[0]) * vert->numSourceVerts); glDrawElements(GL_TRIANGLES, m->deformInfo->numIndexes, GL_UNSIGNED_INT, (void*)0); } [attachment=31408:Screenshot_41.png]     But when I enable index buffer before enabling GL_ARRAY_BUFFER. I get this [attachment=31409:Screenshot_42.png]   Any ideas why it is like this? Thanks.
  10. renderkid

    glew does not initializes extensions

    Yup, I was using static lib. I see now :D :D . That makes sense. Thanks a lot :D
  11. Hi all,   Today I occured quite interesting problem and I really do not know why it is like this. So I though maybe any of you will have an answer to this problem. The problem: In my engine I have renderer.dll that deals with all rendering. The .exe file manages windows and creates OpenGL rendering context. If I try to initialize glew in .exe file. My .dll renderer can not use any opengl code because for some reasons it's not getting those extensions that were loaded successfully in .exe application.     If I load extension in renderer.dll, everything then works fine.   Any ideas why it is like this? Thanks.  
  12. renderkid

    Rotation matrix stretches geometry

      Yea, it is perspective matrix. Just bad naming....
  13. renderkid

    Rotation matrix stretches geometry

    Aaaah. Damn it. I noticed that there is still the same stretching when rotating on x axis Only z axis  and y axis works good.       Using the first option, when rotating triangle on x axis, it stretches in y direction and moves towards +z direction while moving at the same time up and down y axis. When using the second option, it stretches only on y axis and moves up and down y axis which is normal except the stretching. Also, using second option, when rotating triangle on y axis, it seems that it rotates around some kind of point instead rotating around it's local space. When using first option, when rotating triangle on y axis, it rotates around it's orbit, which is fine. Even though I use this math for x rotation
  14. renderkid

    Rotation matrix stretches geometry

      I can't believe. It fuckingly worked :D :D :D :D Thanks mate. Damn it..... But why it's like this?
  15. renderkid

    Rotation matrix stretches geometry

    The shader code is simple:   layout(location = 0) in vec3 vertex_pos; uniform mat4 orthoMatrix; uniform mat4 objectPosition; uniform mat4 rotate; out vec3 texcoord;   void main(void) { gl_Position =   orthoMatrix * objectPosition * rotate *vec4(vertex_pos, 1.0); texcoord = vertex_pos; }
  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!