1 / 19

Displacement mapping

Displacement mapping. Sz écsi László. Let öltés. big.x rkd.jpg rbump.jpg rnormal.jpg. Normal map .xml. <Mesh name="rock" xFileName="media\big.x" autoShadedMesh="false" /> <ShadedMesh name="rockNormal" mesh="rock" > <Role name="basic"> <Material technique="normalMapped">

mercia
Download Presentation

Displacement mapping

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Displacement mapping Szécsi László

  2. Letöltés • big.x • rkd.jpg • rbump.jpg • rnormal.jpg

  3. Normal map .xml • <Mesh name="rock" xFileName="media\\big.x" • autoShadedMesh="false" /> • <ShadedMesh name="rockNormal" mesh="rock" > • <Role name="basic"> • <Material technique="normalMapped"> • <Texture name="kdMap" file="rkd.jpg"/> • <Texture name="bumpMap" • file="rbump.jpg"/> • <Texture name="normalMap" • file="rnormal.jpg"/> • </Material> • </Role> • </ShadedMesh>

  4. XML • <PhysicsEntity name="rockNormal" shadedMesh="rockNormal" physicsModel="ground" position.x="-100" position.z="-50"/>

  5. displacement.fx • technique normalMapped • { • pass ExamplePass • { • VertexShader = compile vs_2_0 vsTrafo(); • PixelShader = compile ps_3_0 psNormalMapped(); • } • }

  6. samplerek • texture normalMap; • sampler2D normalMapSampler = sampler_state{ • texture = < normalMap >; • MinFilter = LINEAR; • MagFilter = LINEAR; • MipFilter = LINEAR; • AddressU = Wrap; • AddressV = Wrap; • }; • texture bumpMap; • sampler2D bumpMapSampler = sampler_state{ • texture = < bumpMap >; • MinFilter = LINEAR; • MagFilter = LINEAR; • MipFilter = LINEAR; • AddressU = Wrap; • AddressV = Wrap; • };

  7. pixel shader: tangent frame • float4 psNormalMapped(TrafoOutput input) : COLOR0{ • float3 normal = normalize(input.normal); • float2 dtdx = ddx(input.tex); • float2 dtdy = ddy(input.tex); • float3 dpdx = ddx(input.worldPos); • float3 dpdy = ddy(input.worldPos); • float3 sTangent = (dpdx * dtdy.y - dpdy * dtdx.y); • float3 sBinormal = (dpdy * dtdx.x - dpdx * dtdy.x) ; • float3 N = normalize(cross(sBinormal, sTangent)); • float3 B = normalize(cross(input.normal, sTangent)); • float3 T = normalize(cross(B, input.normal)); • return abs(N.xyzz); }

  8. pixel shader: normal map • … • float3 tangentNormal = normalize(tex2D(normalMapSampler, input.tex).xzy -float3(0.5, 0.5, 0.5)); • float3 worldNormal = B * tangentNormal.z + normal * tangentNormal.y + T * tangentNormal.x; • return abs(worldNormal.y) * tex2D(kdMapSampler, input.tex); • }

  9. .xml • <ShadedMesh name="rockParallax" mesh="rock" > • <Role name="basic"> • <Material technique="parallax"> • <Texture name="kdMap" file="rkd.jpg"/> • <Texture name="bumpMap" • file="rbump.jpg"/> • <Texture name="normalMap" • file="rnormal.jpg"/> • </Material> • </Role> • </ShadedMesh>

  10. XML • <PhysicsEntity name="rockParallax" shadedMesh="rockParallax" physicsModel="ground" position.x="0" position.z="-50"/>

  11. parallax • technique parallax • { • pass ExamplePass • { • VertexShader = compile vs_2_0 vsTrafo(); • PixelShader = compile ps_3_0 psParallax(); • } • }

  12. parallax • … • float bump_height = 0.1; • float bump = tex2D(bumpSampler, input.tex); • float3 viewDir = normalize(eyePosition - input.worldPos); • viewDir = float3(dot(viewDir, T), dot(viewDir, B), dot(viewDir, normal)); • float2 texOffset = 0.09 * viewDir.xy • // / viewDir.z • * bump; • input.tex += texOffset;

  13. parallax • float3 tangentNormal = normalize(tex2D(normalMapSampler, input.tex).xzy -float3(0.5, 0.5, 0.5)); • float3 worldNormal = B * tangentNormal.z + normal * tangentNormal.y + T * tangentNormal.x; • return abs(worldNormal.y) * tex2D(kdMapSampler, input.tex);

  14. .xml • <ShadedMesh name="rock" mesh="rock" > • <Role name="basic"> • <Material technique="binaryRelief"> • <Texture name="kdMap" file="rkd.jpg"/> • <Texture name="bumpMap" • file="rbump.jpg"/> • <Texture name="normalMap" • file="rnormal.jpg"/> • </Material> • </Role> • </ShadedMesh>

  15. XML • <PhysicsEntity name="rock" shadedMesh="rock" physicsModel="ground" position.x="100" position.z="-50"/>

  16. Binary relief • technique binaryRelief • { • pass ExamplePass • { • VertexShader = compile vs_2_0 vsTrafo(); • PixelShader = compile ps_3_0 psBinaryRelief(); • } • }

  17. ez ugyanaz • float4 psBinaryRelief(TrafoOutput input) : COLOR0 • { • float3 normal = normalize(input.normal); • float2 dtdx = ddx(input.tex); • float2 dtdy = ddy(input.tex); • float3 dpdx = ddx(input.worldPos); • float3 dpdy = ddy(input.worldPos); • float k = dtdx.x * dtdy.y - dtdx.y * dtdy.x; • float3 sTangent = (dpdx * dtdy.y - dpdy * dtdx.y); • float3 sBinormal = (dpdy * dtdx.x - dpdx * dtdy.x) ; • float3 B = normalize(cross(input.normal, sTangent)); • float3 T = normalize(cross(B, input.normal)); • float3 viewDir = normalize(eyePosition - input.worldPos); • viewDir = float3(dot(viewDir, T), dot(viewDir, B), dot(viewDir, normal));

  18. psBinaryRelief folyt. • float bump_height = 0.1; • float3 sRange = - viewDir * bump_height / viewDir.z * 0.5; • float3 sPos = float3(input.tex, 0) - sRange; • for( int i=0; i<6; i++ ) • { • float bump = tex2D(bumpMapSampler, sPos.xy); • sRange *= 0.5; • if (sPos.z > bump * bump_height) // If outside • sPos += sRange; // Move forward • else • sPos -= sRange; // Move backward • } • sPos -= 4 * sRange; • input.tex = sPos.xy;

  19. psBinaryRelief folyt. • float3 tangentNormal = normalize(tex2D(normalMapSampler, input.tex).xzy -float3(0.5, 0.5, 0.5)); • tangentNormal += dot(tangentNormal.xzy, viewDir) * viewDir; • tangentNormal = normalize(tangentNormal); • float3 worldNormal = B * tangentNormal.z + normal * tangentNormal.y + T * tangentNormal.x; • return abs(worldNormal.y) * tex2D(kdMapSampler, input.tex);}

More Related