Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

107 Neutral

About Alexaroth

  • Rank
  1. Alexaroth

    Phong shading issue in directx

      Again, thanks for the answer and sorry to bother you with my noobness. I know what you are talking about and it was indeed blender's fault. Actually, my fault; I was using metaball instead of NURBS sphere when exporting the .obj.    Sorry again for the trouble and thanks for the help, at least I learned testing normals via RGB now :)    Cheers
  2. Alexaroth

    Phong shading issue in directx

      Thanks for the answer, so does that mean that the normals from Blender are not correct? Is there a way to fix that somehow? 
  3. Alexaroth

    Phong shading issue in directx

    Also, tried your suggestion (previous 'broken' normals as RGB). I'm not sure on how to interpret this (what should I be looking for?)  
  4. Alexaroth

    Phong shading issue in directx

      Indeed it seems the FX file is okay...     I decided to try a hack and set all the normals to the value of the actual x y and z position (which for a centred sphere they also represent the smoothest possible normals)       Surprise, surprise....    Well, now I am down to the normals... I need to change them in the model loader, but what do I need to do to them? Is blender at fault for this? In the .obj file each vertex has it's own normal so what could I possible do to them further?
  5. This has been bugging me for several days now and I can't really figure out if this is actually a problem or not!   This is a low poly sphere      I'm using phong shading and the normals provided by blender when exporting the sphere object.   This is a higher poly count sphere:     As you can notice, the edges are still visible and that is driving me insane. I'm using Blender's vertex normals so those values should be correct.     The only thing left that could be wrong is the FX file, which again, should be okay.   Here is the code for it:    VS_OUTPUT VS(float4 inPos : POSITION, float2 inTexCoord : TEXCOORD, float3 normal : NORMAL) { VS_OUTPUT output; output.Pos = mul(inPos, WVP); output.worldPos = mul(inPos, World); output.normal = mul(normal, World); output.TexCoord = inTexCoord; float4 worldPosition = mul(inPos, World); output.viewDirection = normalize(cameraPos - worldPosition); return output; } float4 PS(VS_OUTPUT input) : SV_TARGET { float3 reflection; float4 specular; input.normal = normalize(input.normal); float4 tex = ObjTexture.Sample(ObjSamplerState, input.TexCoord); float3 finalColor = float3(0.0f, 0.0f, 0.0f); specular = float4(0.0f, 0.0f, 0.0f, 0.0f); //Create ambient float3 finalAmbient = tex * light.ambient; //Create the vector between light position and pixels position float3 lightToPixelVec = light.pos - input.worldPos; //Find the distance between the light pos and pixel pos float distance = length(lightToPixelVec); //If pixel is too far, return if( distance > light.range ) return float4(finalAmbient, tex.a); //Turn lightToPixelVec into a unit length vector describing the pixels direction from the lights position lightToPixelVec /= distance; //Calculate how much light the pixel gets by the angle in which the light strikes the pixels surfaec float howMuchLight = dot(input.normal, lightToPixelVec); reflection = normalize(2 * input.normal + lightToPixelVec); specular = pow(saturate(dot(reflection, input.viewDirection)), light.specularPower); //If light is striking the front side of the pixel if( howMuchLight > 0.0f ) { finalColor += howMuchLight * tex * light.diffuse + specular; // falloff factor finalColor /= light.att[0] + (light.att[1] * distance) + (light.att[2] * (distance*distance)); } finalColor = saturate(finalColor + finalAmbient); return float4(finalColor, tex.a); }     The code is simplified so that only the relevant light stuff is shown. Nothing too fancy, so I would immensely appreciate if someone could tell me why I simply can't get phong shading to work properly.
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net 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!