This is my point light geometry (a sphere) rendered normally as if it was real geometry like the level around it. It's a sphere with radius 1, centered on the point light's position, scaled to the light's size. Here's my point light shader, taken straight from the aforementioned tutorial minus the specular component stuff: [source lang="cpp"] float4x4 mat_world; float4x4 mat_view; float4x4 mat_projection; //this is used to compute the world-position float4x4 mat_invviewproj; //color of the light float3 light_color; //this is the position of the light float3 light_position; //how far does this light reach float light_radius; //control the brightness of the light float light_intensity; texture tex_diffuse; sampler2D smp_diffuse = sampler_state { Texture = ; MinFilter = LINEAR; MagFilter = LINEAR; MipFilter = LINEAR; }; texture tex_normal; sampler2D smp_normal = sampler_state { Texture = ; MinFilter = LINEAR; MagFilter = LINEAR; MipFilter = LINEAR; }; struct VertexShaderInput { float3 position : POSITION0; }; struct VertexShaderOutput { float4 position : POSITION0; float4 screen_position : TEXCOORD0; }; VertexShaderOutput MyVertexShader ( VertexShaderInput input ) { VertexShaderOutput output; //processing geometry coordinates float4 world_position = mul(float4(input.position,1), mat_world); float4 view_position = mul(world_position, mat_view); output.position = mul(view_position, mat_projection); output.screen_position = output.position; return output; } float4 MyPixelShader(VertexShaderOutput input) : COLOR0 { //obtain screen position input.screen_position.xy /= input.screen_position.w; //obtain textureCoordinates corresponding to the current pixel //the screen coordinates are in [-1,1]*[1,-1] //the texture coordinates need to be in [0,1]*[0,1] float2 tex_coord = 0.5f * (float2(input.screen_position.x,-input.screen_position.y) + 1); //get normal data from the normalMap float4 normal_data = tex2D(smp_normal,tex_coord); //tranform normal back into [-1,1] range float3 normal = 2.0f * normal_data.xyz - 1.0f; //read depth float depth_val = tex2D(smp_normal,tex_coord).a; //compute screen-space position float4 position; position.xy = input.screen_position.xy; position.z = depth_val; position.w = 1.0f; //transform to world space position = mul(position, mat_invviewproj); position /= position.w; //surface-to-light vector float3 light_vector = light_position - position; //compute attenuation based on distance - linear attenuation float attenuation = saturate(1.0f - length(light_vector)/light_radius); //normalize light vector light_vector = normalize(light_vector); //compute diffuse light float ndl = max(0,dot(normal,light_vector)); float3 diffuse_light = ndl * light_color.rgb; //take into account attenuation and lightIntensity. return attenuation * light_intensity * float4(diffuse_light.rgb,1.0f); } [/source] And this is how I render the light geometry: [source lang="cpp"] D3DXMATRIX scaling_matrix; D3DXMatrixScaling ( &scaling_matrix, 5.0f, 5.0f, 5.0f ); D3DXMATRIX rotation_matrix_x; D3DXMatrixRotationX ( &rotation_matrix_x, D3DXToRadian ( 0.0f ) ); D3DXMATRIX rotation_matrix_y; D3DXMatrixRotationY ( &rotation_matrix_y, D3DXToRadian ( 0.0f ) ); D3DXMATRIX rotation_matrix_z; D3DXMatrixRotationZ ( &rotation_matrix_z, D3DXToRadian ( 0.0f ) ); D3DXMATRIX translation_matrix; D3DXMatrixTranslation ( &translation_matrix, 0.0f, -15.0f, 0.0f ); D3DXMATRIX srt = scaling_matrix * ( rotation_matrix_x * rotation_matrix_y * rotation_matrix_z ) * translation_matrix; window->GetDevice ( )->SetTransform ( D3DTS_WORLD, &srt ); D3DXMATRIX w; window->GetDevice ( )->GetTransform ( D3DTS_WORLD, &w ); D3DXMATRIX v; window->GetDevice ( )->GetTransform ( D3DTS_VIEW, &v ); D3DXMATRIX p; window->GetDevice ( )->GetTransform ( D3DTS_PROJECTION, &p ); D3DXMATRIX ivp; D3DXMatrixMultiply ( &ivp, &v, &p ); D3DXMatrixInverse ( &ivp, NULL, &ivp ); shader_point_light->effect->SetMatrix ( "mat_world", &w ); shader_point_light->effect->SetMatrix ( "mat_view", &v ); shader_point_light->effect->SetMatrix ( "mat_projection", &p ); shader_point_light->effect->SetMatrix ( "mat_invviewproj", &ivp ); shader_point_light->effect->SetVector ( "light_color", &D3DXVECTOR4 ( 0.18f, 0.96f, 0.91f, 1.0f ) ); D3DXVECTOR4 lightpos ( 0.0f, -15.0f, 0.0f, 0.0f ); shader_point_light->effect->SetVector ( "light_position", &lightpos ); shader_point_light->effect->SetFloat ( "light_radius", 5.0f ); shader_point_light->effect->SetFloat ( "light_intensity", 1.0f ); shader_point_light->effect->SetTexture ( "tex_diffuse", g_buffer.texture[0] ); shader_point_light->effect->SetTexture ( "tex_normal", g_buffer.texture[1] ); shader_point_light->effect->CommitChanges ( ); window->GetDevice ( )->SetRenderTarget ( 0, back_buffer ); RenderGeometryDetails details; LPDIRECT3DVERTEXBUFFER9 vb; LPDIRECT3DINDEXBUFFER9 ib; sphere->GetVertexBuffer ( &vb ); sphere->GetIndexBuffer ( &ib ); details.primitive_type = D3DPT_TRIANGLELIST; details.num_vertices = sphere->GetNumVertices ( ); details.num_primitives = sphere->GetNumFaces ( ); details.vertex_format = sphere->GetFVF ( ); details.vertex_bytesize = sphere->GetNumBytesPerVertex ( ); details.vertex_buffer = vb; details.index_buffer = ib; details.texture = NULL; details.alpha_blend_mode = AlphaBlend_Blend; float camera_to_center = D3DXVec3Length ( &D3DXVECTOR3 ( lightpos.x - camera->position.x, lightpos.y - camera->position.y, lightpos.z - camera->position.z ) ); if ( camera_to_center < 5.0f ) details.cull_mode = Cull_Clockwise; else details.cull_mode = Cull_CounterClockwise; details.z_test = true; RenderGeometry ( details ); [/source] And this is the output I'm getting:
You can clearly see that it's like I'm looking through a transparent sphere where everything behind it gets shaded, almost like additional directional lighting. This is my first deferred renderer, I'm still fairly new to this all and I can't quite keep up with it yet. I'm having trouble understanding what could be wrong here. Any help would be greatly appreciated? What looks iffy to you here? Am I missing an entire step?



