Forgot your password?
Or sign in with one of these services
, July 27, 2014 in Graphics and GPU Programming
This topic is 1261 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.
If you intended to correct an error in the post then please contact us.
Just skimmed over your shader but this part looks odd and is probably where things go wrong:
if(N.x == 1.0f)
p1.y += 0.5f;
p1.x += 0.5f;
Shaders that use normal(!) mapping typically require a face normal and a tangent to work. The tangent is parallel to the surface and always perpendicular to the normal and exported meshes that are UV mapped should have one by default.
When implementing bump mapping you should also make use of the tangent. You can take a normal mapping shader as a reference. The only conceptual difference is that instead of sampling once to get the the normal of a fragment you sample the bump map multiple times in the direct neighbourhood. From the difference between samples you calculate a gradient along the tangent and along the binormal (binormal = tangent cross normal) and based on the gradient you skew the normal to receive the bump effet.
Solution B: Convert your bump map to a normal map using Nvidia's Texture tools. https://developer.nvidia.com/nvidia-texture-tools-adobe-photoshop
float3 GetBump(Pixel input)
float3 N = normalize(input.Normal);
// Calculate the size of a single pixel in the bump texture.
float2 pixelSize = 1.0f / bumpTextureSize;
float2 uv = UVTransform(input.UV, BumpTextureScale, BumpTextureRotate, BumpTextureTranslate);
// Get the height value of this pixel.
float3 mid = BumpTexture.Sample(TrilinearSampler, uv).r;
// Get the height values of all neighbouring pixels.
float left = BumpTexture.Sample(TrilinearSampler, uv + float2(-pixelSize.x, 0)).r;
float right = BumpTexture.Sample(TrilinearSampler, uv + float2(pixelSize.x, 0)).r;
float top = BumpTexture.Sample(TrilinearSampler, uv + float2(0, -pixelSize.y)).r;
float bottom = BumpTexture.Sample(TrilinearSampler, uv + float2(0, pixelSize.y)).r;
// Calculate the amount of height difference.
float3 p1 = ((bottom - mid) - (top - mid)) * normalize(input.Binormal);
float3 p2 = ((left - mid) - (right - mid)) * normalize(input.Tangent);
// Calculate the final offset to add to the normal.
float3 No = (p1 + p2) * -BumpDepth;
// Add the offset to the normal and normalize it.
float3 Nn = normalize(N + No);
this looks wrong to me
float3 result = N + (uv.x * xGrad) + (uv.y * yGrad);
Why are you using the input UV coordinates to modify the normal?
I would try changing it to
float3 result = N + float3(xGrad,yGrad,0);
and see what happens
The problem would be easier to solve if you could upload a sample where we can make changes to the shader and immediately see the results. I just changed the existing code to use tanget and binormal, but what stainless points out looks odd indeed. Probably there are multiple issues that influence each other.
the Bump Problem is solved :)
Don't be sad now if you don't figure out the solution, i bet i have in the future Problems that i can't fix and where can the first one who post the right solution earn good money :)
Why do you delete all your posts? That is rude!
Btw. If the posts are restored, could you post the solution so other users with the same problem as yours could get their answer?
Started 13 hours ago
Started Yesterday at 04:45 PM
Started Yesterday at 02:00 AM
Started Sunday at 02:57 PM
Started Saturday at 02:26 PM
Create an account with GameDev.net and join the game development conversation on our forums, blogs, articles, and more!