View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# HLSL Bump Mapping Problem (Solved)

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

15 replies to this topic

### #1SharinganShuriken  Members

Posted 27 July 2014 - 07:12 AM

### #2cozzie  Members

Posted 27 July 2014 - 08:11 AM

How are you wrapping the texture? (if you say that all is fine with sphere/ cylinder, but not with cube)

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

### #3SharinganShuriken  Members

Posted 27 July 2014 - 12:24 PM

Edited by SharinganShuriken, 11 August 2014 - 12:34 PM.

### #4cozzie  Members

Posted 28 July 2014 - 10:43 AM

Have you played around with other wrapping types?
Another cause could be the UV coordinates in your mesh data, they should range from 0 to 1 for a basic cube

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

### #5SharinganShuriken  Members

Posted 29 July 2014 - 05:53 AM

Edited by SharinganShuriken, 11 August 2014 - 12:35 PM.

### #6Lithander  Members

Posted 29 July 2014 - 07:55 AM

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;
else
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

Edited by Lithander, 29 July 2014 - 07:58 AM.

### #7SharinganShuriken  Members

Posted 29 July 2014 - 12:23 PM

Edited by SharinganShuriken, 11 August 2014 - 12:35 PM.

### #8Lithander  Members

Posted 30 July 2014 - 04:17 AM

Try this:

float3 GetBump(Pixel input)
{
float3 N = normalize(input.Normal);
// Calculate the size of a single pixel in the bump texture.
float2 bumpTextureSize;
BumpTexture.GetDimensions(bumpTextureSize[0], bumpTextureSize[1]);
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);

return Nn;
}

### #9SharinganShuriken  Members

Posted 30 July 2014 - 05:56 AM

Edited by SharinganShuriken, 11 August 2014 - 12:35 PM.

### #10Stainless  Members

Posted 30 July 2014 - 06:33 AM

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

### #11Lithander  Members

Posted 30 July 2014 - 06:39 AM

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.

### #12SharinganShuriken  Members

Posted 30 July 2014 - 08:52 AM

Edited by SharinganShuriken, 11 August 2014 - 12:35 PM.

### #13SharinganShuriken  Members

Posted 11 August 2014 - 12:35 PM

Dear Community,

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

Lovely Greetings
SharinganShuriken

### #14belfegor  Members

Posted 11 August 2014 - 01:40 PM

Why do you delete all your posts? That is rude!

### #15slicer4ever  GDNet+

Posted 11 August 2014 - 01:55 PM

Why do you delete all your posts? That is rude!

seconded, would it be possible for a mod to restore his posts?
Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

### #16Migi0027 (肉コーダ)  Members

Posted 12 August 2014 - 12:05 AM

Btw. If the posts are restored, could you post the solution so other users with the same problem as yours could get their answer?

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/cuboidzone.wordpress.com/

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.