rocklobster

Members
  • Content count

    92
  • Joined

  • Last visited

Community Reputation

415 Neutral

About rocklobster

  • Rank
    Member
  1. Hey guys,   Since the start of my hobby project, I've been using one PC for development which is using an ATI card. I've just tried to run my project on my friends computer and my laptop (both have nVidia cards) and nothing renders, the screen is the same colour as the glClear(...) with nothing showing.    I did some debugging with glGetError and I'm not getting any errors showing up. I removed my render target and just rendered my scene to the default framebuffer and then things started drawing (minus the post-processing). So this leads me to believe my framebuffer object is not created correctly for nVidia cards? bool Graphics::CreateRenderTarget( RenderTarget* target ) { GLuint fbo; glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_FRAMEBUFFER, fbo); target->SetFrameBufferId(fbo); for (uint32 i = 0; i < target->GetNumSources(); i++) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); GLuint tex; glActiveTexture(GL_TEXTURE0 + i); glGenTextures(1, &tex); glBindTexture(GL_TEXTURE_2D, tex); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, target->GetWidth(), target->GetHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, 0); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, tex, 0); target->SetSourceId(i, tex); } if (target->UseDepth()) { GLuint depth; glGenRenderbuffers(1, &depth); glBindRenderbuffer(GL_RENDERBUFFER, depth); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, target->GetWidth(), target->GetHeight()); target->SetDepthBufferId(depth); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth); } glDrawBuffers(target->GetNumSources(), target->GetDrawBuffers()); if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { return false; } return true; } Anything obviously incorrect? I can post more info If needed.
  2. Runs fine on my machine (60 always):   CPU: i5-2500k 3.3ghz RAM: 12GB OS: Windows 64-bit GPU: Sapphire 6950
  3. Awesome mate, seems to be working fine now! Cheers for the help.
  4. Cheers I'll give it a shot when I get home from work.
  5. Ok so this is what I've changed: glm::mat4 modelMatrix = modelNode->GetTransform(); glm::mat4 modelView = viewMatrix * modelMatrix; glm::mat4 mvp = m_renderSystem->GetCamera()->GetProjectionMatrix() * modelView; glm::mat3 normalMat = glm::transpose(glm::inverse(glm::mat3(modelView))); m_graphics->SetUniform(id, "u_NormalMatrix", 1, false, normalMat); m_graphics->SetUniform(id, "u_ModelMatrix", 1, false, modelMatrix); m_graphics->SetUniform(id, "u_ModelViewMatrix", 1, false, modelView); m_graphics->SetUniform(id, "u_MVP", 1, false, mvp);  Vertex Shader:   Multiplying the in_Position by the u_ModelMatrix, getting the direction from the light position to the vertex in world space and then multiplying by normal matrix to get oriented in eye space. void main() { PositionEye = vec3(u_ModelViewMatrix * vec4(in_Position, 1.0)); NormalEye = u_NormalMatrix * in_Normal; TexCoord = in_TexCoord; vec3 PosWorld = vec3(u_ModelMatrix * vec4(in_Position, 1.0)); vec3 lightDirWorld = normalize(GlobalLightPos - PosWorld); LightDirEye = u_NormalMatrix * lightDirWorld; gl_Position = u_MVP * vec4(in_Position, 1.0); } Fragment Shader:   Basically the same, doing normalising here instead of vertex shader. vec3 shadePixel(vec3 diff) { vec3 s = normalize(LightDirEye); float sDotN = max(dot(s, normalize(NormalEye)), 0.0); vec3 diffuse = vec3(1.0, 1.0, 1.0) * diff * sDotN; return diffuse; } void main() { vec3 diff = texture(Texture, TexCoord * TexRepeat); out_Position = PositionEye; out_Normal = normalize(NormalEye); out_Diffuse = shadePixel(texture(Texture, TexCoord * TexRepeat)); out_Tangent = Tangent; out_Binormal = Binormal; } Now this seems to be creating a weird effect, half of my world is shaded which looks normal, the other half is just completely black!?!
  6. Thanks,     It was a point light previously (Sun) but I figured I could switch it easily to a directional light by just getting the direction from it's position to the vertex's position? To transform the in_Position into world space would just be: vec3 PosWorld = vec3(ModelMatrix * vec4(in_Position, 1.0)); correct?          Assuming your model's normal are in object space you need to be using the product of the model view matrix here.  That's one problem.   I'm not sure what you mean by "product of the model view matrix"?    something like this: glm::mat3 normalMatrix = glm::transpose(glm::inverse(glm::mat3(modelView))); So it is the inverse of the ModelView rather than just the View?   I can't test this out at the moment but I'll post back with results later on.
  7. Hey guys,   I'm implementing deferred shading and I've decided to calculate shading for a single global light in the first pass, then do all the other lights in the second pass. I'm not sure If I've got my normal/light and vertex positions all in the correct space and the lighting effect does not look correct.   Vertex shader: #version 400 layout (location = 0) in vec3 in_Position; layout (location = 1) in vec3 in_Normal; layout (location = 2) in vec3 in_TexCoord; layout (location = 3) in vec3 in_Tangent; layout (location = 4) in vec3 in_Binormal; out vec3 PositionEye; out vec3 NormalEye; out vec3 TexCoord; out vec3 Tangent; out vec3 Binormal; out vec3 LightDirEye; uniform vec3 GlobalLightPos; uniform mat4 u_ModelMatrix; uniform mat4 u_ViewMatrix; uniform mat4 u_ModelViewMatrix; uniform mat3 u_NormalMatrix; uniform mat4 u_MVP; void main() { PositionEye = vec3(u_ModelViewMatrix * vec4(in_Position, 1.0)); NormalEye = u_NormalMatrix * in_Normal; TexCoord = in_TexCoord; vec3 lightDirWorld = normalize(GlobalLightPos - in_Position); LightDirEye = u_NormalMatrix * lightDirWorld; gl_Position = u_MVP * vec4(in_Position, 1.0); } Fragment shader: #version 400 in vec3 PositionEye; in vec3 NormalEye; in vec3 TexCoord; in vec3 Tangent; in vec3 Binormal; in vec3 LightDirEye; uniform sampler2D Texture; uniform float TexRepeat; layout (location = 0) out vec3 out_Position; layout (location = 1) out vec3 out_Normal; layout (location = 2) out vec3 out_Diffuse; layout (location = 3) out vec3 out_Tangent; layout (location = 4) out vec3 out_Binormal; vec3 shadePixel(vec3 diff) { vec3 s = LightDirEye; float sDotN = max(dot(s, NormalEye), 0.0); vec3 diffuse = vec3(1.0, 1.0, 1.0) * diff * sDotN; return diffuse; } void main() { vec3 diff = texture(Texture, TexCoord * TexRepeat); out_Position = PositionEye; out_Normal = NormalEye; out_Diffuse = shadePixel(texture(Texture, TexCoord * TexRepeat)); out_Tangent = Tangent; out_Binormal = Binormal; } Uniforms: glm::vec3 lightPos = m_sceneGraph->GetGlobalLightPos(); glm::mat4 viewMatrix = m_renderSystem->GetCamera()->GetViewMatrix(); glm::mat3 normalMat = m_renderSystem->GetCamera()->GetNormalMatrix(); m_graphics->SetUniform(id, "GlobalLightPos", lightPos); m_graphics->SetUniform(id, "u_ViewMatrix", 1, false, viewMatrix); m_graphics->SetUniform(id, "u_NormalMatrix", 1, false, normalMat); glm::mat4 modelMatrix = modelNode->GetTransform(); glm::mat4 modelView = viewMatrix * modelMatrix; glm::mat4 mvp = m_renderSystem->GetCamera()->GetProjectionMatrix() * modelView; m_graphics->SetUniform(id, "u_ModelMatrix", 1, false, modelMatrix); m_graphics->SetUniform(id, "u_ModelViewMatrix", 1, false, modelView); m_graphics->SetUniform(id, "u_MVP", 1, false, mvp); The light pos is just glm::vec3(0.0f, 50.0f, 0.0f)   and the normal matrix is: glm::mat3 Camera::GetNormalMatrix() { return glm::transpose(glm::inverse(glm::mat3(m_view))); } Can't seem to work out what is going wrong here.
  8. Deferred Shading lighting stage

    Ah ok, I get it thanks. I was wondering about this also, because not all of my geometry has Tangents and BiTangents also, which is a bit annoying... Thanks for all your help.
  9. Deferred Shading lighting stage

    Just one last thing, what do you mean when you say "one shader for every material type"?   My definition of a material is just something like: class Material { Vec3 diffuse Vec3 ambient Vec3 specular Tex2 diffuse_Map Tex2 normal_Map Tex2 specular_Map } so I don't know what you mean.
  10. Deferred Shading lighting stage

    Thanks. Right now I'm currently outputting Position, Normal, Diffuse, Tangent and BiTangent. Should I also output specular and ambient properties? Or will this be too much memory usage?
  11. Hey guys,   I've attempted to implement deffered shading lately and I'm a bit confused about the lighting stage.   This is the algorithm for what I do at the moment: FirstPass - Bind render target - bind my G-buffer shader program - render the scene SecondPass - Bind my normal shader for rendering the quad (fragment shader takes Position, Normal and Diffuse samplers as uniforms) - Render full screen quad - swap buffers So am I right to assume that to light the scene I should also add this change to the second pass: SecondPass - Bind my normal shader for rendering the quad (fragment shader takes Position, Normal and Diffuse samplers as uniforms) - FOR EACH LIGHT IN THE SCENE - Set this light as uniform for the shader - Render full screen quad - END FOR - swap buffers And in my fragment shader I'll have the code which shades all the pixels based on the type of light passed in (directional, point or spot).   Cheers for any help
  12. Collada pivot node

    Awesome thanks! That was a great explanation.
  13. Collada pivot node

    What is jointOrientX? Why is it there? Why is there a sub-node with the suffix -pivot?   Can someone please explain this to me, here is part of the .dae file: <node name="Box012" id="Box012" sid="Box012"> <translate sid="translate">91.838813 42.641855 -53.673642</translate> <rotate sid="jointOrientX">1 0 0 -90.000000</rotate> <scale sid="scale">2.540000 2.540000 2.540000</scale> <node id="Box012-Pivot" name="Box012-Pivot"> <translate>0.000000 -13.999999 -0.128876</translate> <rotate>0.000000 0.000000 0.000000 0.000000</rotate> <instance_geometry url="#Box012-lib"> <bind_material> <technique_common> <instance_material symbol="_04 - Default" target="#_04 - Default"/> </technique_common> </bind_material> </instance_geometry> </node> <extra> <technique profile="FCOLLADA"> <visibility>1.000000</visibility> </technique> </extra> </node> The object "Box012" is not rendered in the correct place, and I think it is because it doesn't have the transform of "Box012-Pivot". But pivot is a sub node, and it doesn't reference any mesh? I'm a bit confused why it's even there. I don't remember having a pivot when I exported from 3ds max. 
  14. Design portable vertex declaration

    Just thought I'd link this http://www.gamedev.net/topic/634564-catering-for-multiple-vertex-definitions/#entry5002042   A similar thread I started quite a while ago. Roughly the same stuff, but maybe you'll find some more useful info in there.