@laurel_vasquez wrote:
Hello,
I'm super new to writing shaders and really wanted to improve my skills by writing immersive water shaders. I've been following this tutorial to guide me in creating a bump map shader. Currently my shader isn't changing anything, and the output looks like this:
The original water drawing is below on the left and the bump map is on the right:
(Trying to draw the water half transparent so you can see the sand below it)
From my understanding, the tutorial explains that in the bump map, at each x,y location the pixel located there holds data on the normal vector to the '3d' surface. Then you use that data to calculate some distortion term to add to the original coordinate location, and draw the pixel at the distorted location instead.
Do you know why no distortion is occurring?
My shader is:
//bump map texture Texture2D bumpMap; //water original texture Texture2D waterLayover; //additional necessary variables float xWaveLength; float xWaveHeight; sampler WaterBumpMapSampler = sampler_state { texture = <bumpMap>; }; sampler WaterLayoverSampler = sampler_state { texture = <waterLayover>; }; float4 PixelShaderFunction(float4 pos : SV_POSITION, float4 color1 : COLOR0, float2 texCoord : TEXCOORD0) : SV_TARGET0 { //sample bump map float4 bumpColor = tex2D(WaterBumpMapSampler, texCoord.xy); //get offset float2 perturbation = xWaveHeight * (bumpColor.rg - 0.5f)*2.0f; //apply offset to coordinates in original texture float2 currentCoords = texCoord.xy; float2 perturbatedTexCoords = currentCoords + perturbation; //return the perturbed values float4 color = tex2D(WaterLayoverSampler, perturbatedTexCoords); return color; } technique Technique1 { pass Pass1 { PixelShader = compile ps_4_0 PixelShaderFunction(); } }
And my draw call looks like:
protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); // TODO: Add your drawing code here spriteBatch.Begin(); spriteBatch.Draw(sandMap, Vector2.Zero, Color.White); spriteBatch.End(); spriteBatch.Begin(SpriteSortMode.FrontToBack); bumpEffect.Parameters["bumpMap"].SetValue(bumpMap); bumpEffect.Parameters["waterLayover"].SetValue(waterLayoverMap); bumpEffect.Parameters["xWaveLength"].SetValue(0.1f); bumpEffect.Parameters["xWaveHeight"].SetValue(0.3f); bumpEffect.CurrentTechnique.Passes[0].Apply(); spriteBatch.Draw(waterLayoverMap, Vector2.Zero, Color.White); spriteBatch.End(); base.Draw(gameTime); }
Posts: 2
Participants: 2