KarimIO

Members
  • Content count

    100
  • Joined

  • Last visited

Community Reputation

271 Neutral

About KarimIO

  • Rank
    Member

Personal Information

  • Interests
    Art
    Audio
    Design
    Programming
  1. 3D Do models go inside a BSP?

    I didn't mean frustum culling of pixels, I'm aware that happens automatically, I meant of subtrees and entire objects or areas. Awesome! Thanks! I'll check it out soon. And is this used in addition to the previously mentioned techniques, or instead of it? Thanks again, JoeJ and Hodgman!
  2. 3D Do models go inside a BSP?

    As I said, I currently use only models for geometry. I wanted to add CSG-geometry for blocking things out, as well as for people who come from the Source Engine that might find it useful. This is pretty much what I planned to do before wanting to look for more effective methods. Quick question though, should frustum culling be done before or after occlusion culling? So an optimal approach would be using the PVS for static objects and occlusion queries for dynamic ones, while checking the partitioning tree for where the dynamic objects are to reduce the amount of occlusions, correct? I know nothing of Hi-Z Pyramids, but I'll check them out!
  3. 3D Do models go inside a BSP?

    Alrighty so basically I should use CSG geometry without the BSP partitioning. PVS is an all-encompassing thing, right, not just an individual technology? But in regard to partitioning and visibility, I remember Frostbite used sphere-based partitioning. Is that still used today, or can you suggest another partition method.
  4. 3D Do models go inside a BSP?

    Thanks for responding quickly and helpfully as usual, Hodgman! Doesn't Source use BSP for practically for everything under the sun and Unreal use it for blocking? It's not just partitioning and visibility I'd like it for, but also that blocking. Yeah that makes sense, but it shouldn't be difficult to overcome. How is this done though? The only thing that comes to mind is having an interior and exterior collision mesh, so anything including the interior mesh would block other BSP elements and anything in the exterior would represent what leaf the actual model is in.
  5. Hey guys, So I'm starting to think about BSP for my engine, which so far only supports models. And I've got a couple stupid questions. How are static and dynamic models usually used with the BSP visibility side of things? As far as I'm aware, dynamic models only use the BSP tree as a way to cull before visibility culling, so i guess I can compare an OOBB to the BSP tree leaves - is this correct? How do static meshes affect the BSP tree in terms of blocking visibility? Thanks in advance!
  6. In the main prepass vertex shader, I need to use this: #pragma pack_matrix( row_major ) Multiplication should be column major by default because I use GLM. Yet, for one specific file, I need to use row_major.
  7. The problem is, I'm doing no such thing. GLM outputs the same column-major matrices, but for some reason one shader requires row major and the other column major. I understand everything you're talking about, it's just DirectX likes it one way in one shader and another way in another shader.
  8. @Hodgman Sorry! Didn't see the response until now! Keep in mind as I used GLM, it's column major. Here's the code that works: //////////////////////////////////////////////////////////////////////////////// // Filename: mainVert.vs //////////////////////////////////////////////////////////////////////////////// ///////////// // GLOBALS // ///////////// #pragma pack_matrix( row_major ) cbuffer MatrixBuffer { matrix worldMatrix; matrix viewMatrix; matrix projectionMatrix; }; ////////////// // TYPEDEFS // ////////////// struct VertexInputType { float3 position : POSITION; float3 normal : NORMAL; float3 tangent : TANGENT; float2 texCoord : TEXCOORD0; }; struct PixelInputType { float4 position : SV_POSITION; float3 worldPosition : POSITION; float3 normal : NORMAL; float3 tangent : TANGENT; float2 texCoord : TEXCOORD0; }; //////////////////////////////////////////////////////////////////////////////// // Vertex Shader //////////////////////////////////////////////////////////////////////////////// PixelInputType main(VertexInputType input) { float4 position; PixelInputType output; // Change the position vector to be 4 units for proper matrix calculations. position = float4(input.position, 1.0f); // Calculate the position of the vertex against the world, view, and projection matrices. position = mul(position, worldMatrix); output.worldPosition = position.xyz; position = mul(position, viewMatrix); output.position = mul(position, projectionMatrix); output.normal = normalize(mul(float4(input.normal, 1.0), worldMatrix).xyz); output.tangent = normalize(mul(float4(input.tangent, 1.0), worldMatrix).xyz); output.texCoord = float2(input.texCoord.x, -input.texCoord.y); return output; } //////////////////////////////////////////////////////////////////////////////// // Filename: pointLightFrag.ps //////////////////////////////////////////////////////////////////////////////// #pragma pack_matrix( column_major ) #include "inc_transform.hlsl" #include "inc_light.hlsl" ////////////// // TYPEDEFS // ////////////// struct PixelInputType { float4 position : SV_POSITION; float2 texCoord : TEXCOORD0; float3 viewRay : POSITION; }; Texture2D shaderTexture[4]; SamplerState SampleType[4]; cbuffer MatrixInfoType { matrix invView; matrix invProj; float4 eyePos; float4 resolution; }; cbuffer Light { float3 lightPosition; float lightAttenuationRadius; float3 lightColor; float lightIntensity; }; //////////////////////////////////////////////////////////////////////////////// // Pixel Shader //////////////////////////////////////////////////////////////////////////////// float4 main(PixelInputType input) : SV_TARGET { float depth = shaderTexture[3].Sample(SampleType[0], input.texCoord).r; float3 Position = WorldPosFromDepth(invProj, invView, depth, input.texCoord); //return float4(position, 1.0); /*float near = 0.1; float far = 100; float ProjectionA = far / (far - near); float ProjectionB = (-far * near) / (far - near); depth = ProjectionB / ((depth - ProjectionA)); float4 position = float4(input.viewRay * depth, 1.0);*/ // Convert to World Space: // position = mul(invView, position); float3 Albedo = shaderTexture[0].Sample(SampleType[0], input.texCoord).rgb; float3 Normal = shaderTexture[1].Sample(SampleType[0], input.texCoord).rgb; float4 Specular = shaderTexture[2].Sample(SampleType[0], input.texCoord); float3 lightPow = lightColor * lightIntensity; float3 outColor = LightPointCalc(Albedo.rgb, Position.xyz, Specular, Normal.xyz, lightPosition, lightAttenuationRadius, lightPow, eyePos.xyz); // hdrGammaTransform() return float4(hdrGammaTransform(outColor), 1.0f); }
  9. @Hodgman Got any idea for the question above?
  10. Okay thank you a lot, Hodgman I finally got it to work! But I do have a question, my main vertex.hlsl which takes the actual geometry and pushes it into the gbuffer requires row-major whereas the rest works fine using column major. Do you have any idea why that could be?
  11. I've tried this, but now it's far too zoomed in. Originally, it did look quite like my OpenGL results. Is there a reason for this? projection *= glm::translate(glm::vec3(0.0f,0.0f,0.5f)) * glm::scale(glm::vec3(1.0f,1.0f,0.5f));
  12. Thanks for the quick response. Firstly, GL is column major whereas directx is row major. I've already had to transpose for my first geometry stage and it works well. Second, will I need to change my first stage to accommodate this change as well? Also can I just multiply it by glm::translate(0,0,0.5)xProjection EDIT: I've switched to row major vertices in DirectX using the following: #pragma pack_matrix( row_major ) I guess DirectX just uses row major by default. I'm still having the same issues though. I tried using the following in ViewPosFromDepth: float z = depth * 0.5 + 0.5;
  13. I'm trying to port my engine to DirectX and I'm currently having issues with depth reconstruction. It works perfectly in OpenGL (even though I use a bit of an expensive method). Every part besides the depth reconstruction works so far. I use GLM because it's a good math library that has no need to install any dependencies or anything for the user. So basically I get my GLM matrices: struct DefferedUBO { glm::mat4 view; glm::mat4 invProj; glm::vec4 eyePos; glm::vec4 resolution; }; DefferedUBO deffUBOBuffer; // ... glm::mat4 projection = glm::perspective(engine.settings.fov, aspectRatio, 0.1f, 100.0f); // Get My Camera CTransform *transform = &engine.transformSystem.components[engine.entities[entityID].components[COMPONENT_TRANSFORM]]; // Get the View Matrix glm::mat4 view = glm::lookAt( transform->GetPosition(), transform->GetPosition() + transform->GetForward(), transform->GetUp() ); deffUBOBuffer.invProj = glm::inverse(projection); deffUBOBuffer.view = glm::inverse(view); if (engine.settings.graphicsLanguage == GRAPHICS_DIRECTX) { deffUBOBuffer.invProj = glm::transpose(deffUBOBuffer.invProj); deffUBOBuffer.view = glm::transpose(deffUBOBuffer.view); } // Abstracted so I can use OGL, DX, VK, or even Metal when I get around to it. deffUBO->UpdateUniformBuffer(&deffUBOBuffer); deffUBO->Bind()); Then in HLSL, I simply use the following: cbuffer MatrixInfoType { matrix invView; matrix invProj; float4 eyePos; float4 resolution; }; float4 ViewPosFromDepth(float depth, float2 TexCoord) { float z = depth; // * 2.0 - 1.0; float4 clipSpacePosition = float4(TexCoord * 2.0 - 1.0, z, 1.0); float4 viewSpacePosition = mul(invProj, clipSpacePosition); viewSpacePosition /= viewSpacePosition.w; return viewSpacePosition; } float3 WorldPosFromViewPos(float4 view) { float4 worldSpacePosition = mul(invView, view); return worldSpacePosition.xyz; } float3 WorldPosFromDepth(float depth, float2 TexCoord) { return WorldPosFromViewPos(ViewPosFromDepth(depth, TexCoord)); } // ... // Sample the hardware depth buffer. float depth = shaderTexture[3].Sample(SampleType[0], input.texCoord).r; float3 position = WorldPosFromDepth(depth, input.texCoord).rgb; Here's the result: This just looks like random colors multiplied with the depth. Ironically when I remove transposing, I get something closer to the truth, but not quite: You're looking at Crytek Sponza. As you can see, the green area moves and rotates with the bottom of the camera. I have no idea at all why. The correct version, along with Albedo, Specular, and Normals.
  14. Another bump. Still no solution. Also, it works perfectly on Linux.
  15. @Hodgman @TheChubu Sorry but buuump. Any ideas, guys?