Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


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.

  • You cannot reply to this topic
15 replies to this topic

#1 SharinganShuriken   Members   -  Reputation: 95

Like
0Likes
Like

Posted 27 July 2014 - 07:12 AM

:)



Sponsor:

#2 cozzie   Members   -  Reputation: 1659

Like
0Likes
Like

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)

#3 SharinganShuriken   Members   -  Reputation: 95

Like
0Likes
Like

Posted 27 July 2014 - 12:24 PM

:)


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


#4 cozzie   Members   -  Reputation: 1659

Like
0Likes
Like

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

#5 SharinganShuriken   Members   -  Reputation: 95

Like
0Likes
Like

Posted 29 July 2014 - 05:53 AM

:)


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


#6 Lithander   Members   -  Reputation: 245

Like
1Likes
Like

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.


#7 SharinganShuriken   Members   -  Reputation: 95

Like
0Likes
Like

Posted 29 July 2014 - 12:23 PM

:)


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


#8 Lithander   Members   -  Reputation: 245

Like
1Likes
Like

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


#9 SharinganShuriken   Members   -  Reputation: 95

Like
0Likes
Like

Posted 30 July 2014 - 05:56 AM

:)


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


#10 Stainless   Members   -  Reputation: 1042

Like
0Likes
Like

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



#11 Lithander   Members   -  Reputation: 245

Like
0Likes
Like

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.



#12 SharinganShuriken   Members   -  Reputation: 95

Like
0Likes
Like

Posted 30 July 2014 - 08:52 AM

:)


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


#13 SharinganShuriken   Members   -  Reputation: 95

Like
-4Likes
Like

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



#14 belfegor   Crossbones+   -  Reputation: 2691

Like
2Likes
Like

Posted 11 August 2014 - 01:40 PM

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



#15 slicer4ever   Crossbones+   -  Reputation: 3949

Like
2Likes
Like

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.

#16 Migi0027 =A=   Crossbones+   -  Reputation: 1987

Like
0Likes
Like

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?


Hi! Cuboid Zone
The Rule: Be polite, be professional, but have a plan to steal all their shaders!





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.



PARTNERS