SlideServe
Menu
Preferences
© SlideServe · v2026

Displacement mapping

sanjiv avatar
24 slides · 430 Views · 240 likes · Aug 23, 2014

Displacement mapping. Sz écsi László. Let öltés. rock . obj rkd.jpg rbump.jpg rnormal.jpg. lua: Normal mappelt modell. O:IndexedMesh(_, {name='rock', file='rock. obj '}) O:Material(_, {name='normalMappedRock', technique='displacement', pass='normalMapped'}, function(_)

Displacement mapping - slide 1
01 / 24Displacement mapping
1 / 17

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

More Related Content

Presentation Transcript
  1. Displacement mapping Szécsi László

  2. Letöltés • rock.obj • rkd.jpg • rbump.jpg • rnormal.jpg

  3. lua: Normal mappelt modell O:IndexedMesh(_, {name='rock', file='rock.obj'}) O:Material(_, {name='normalMappedRock', technique='displacement', pass='normalMapped'}, function(_) O:setSrv(_, {effectVariable='kdTexture', file='rkd.jpg'}) O:setSrv(_, {effectVariable='bumpTexture', file='rbumb.jpg'}) O:setSrv(_, {effectVariable='normalTexture', file='rnormal.jpg'}) end ) O:MultiMesh(_, {name='normalMappedRock'}, function(_) O:FlipMesh(_, {}, function(_) O:ShadedMesh(_, {mien='basic', indexedMesh='rock', material='normalMapped'}) end ) end )

  4. lua: entitás • O:StaticEntity(_, {name='rock0', multiMesh='normalMappedRock', position = { x=0, y=100, z=0} } )

  5. main.fx • #include <envmapped.fx> • #include <billboard.fx> • #include "displacement.fx"

  6. displacement.fx technique11 displacement { pass normalMapped { SetVertexShader ( CompileShader( vs_5_0, vsTrafo() ) ); SetGeometryShader( NULL ); SetRasterizerState( defaultRasterizer ); SetPixelShader( CompileShader( ps_5_0, psNormalMapped() ) ); SetDepthStencilState( defaultCompositor, 0 ); SetBlendState( defaultBlender, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF ); } }

  7. textúra shader resourceok • Texture2D normalTexture; • Texture2D bumpTexture;

  8. pixel shader: tangent frame float4 psNormalMapped(VsosTrafo input) : SV_TARGET { 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); }

  9. MÁSIK MÓDSZER I structIaosTangent { float4 pos: POSITION; float3 normal : NORMAL; float3 tangent : TANGENT; float3 binormal : BINORMAL; float2 tex : TEXCOORD; }; structVsosTangent { float4 pos : SV_POSITION; float4 worldPos : WORLDPOS; float3 normal : NORMAL; float3 tangent : TANGENT; float3 binormal : BINORMAL; float2 tex : TEXCOORD; };

  10. MÁSIK MÓDSZER II VsosTangentvsTangent(IaosTangent input) { VsosTangent output = (VsosTangent)0; output.pos = mul(input.pos, modelViewProjMatrix); output.worldPos = mul(input.pos, modelMatrix); output.normal = mul(modelMatrixInverse, float4(input.normal.xyz, 0.0)); output.tangent = mul(modelMatrixInverse, float4(input.tangent.xyz, 0.0)); output.binormal = mul(modelMatrixInverse, float4(input.binormal.xyz, 0.0)); output.tex = input.tex; return output; }

  11. MÁSIK MÓDSZER III float4 psNormalMapped(VsosTangent input) : SV_TARGET { float3 T= normalize(input.tangent.xyz); float3 B= -normalize(input.binormal.xyz); float3 N = normalize(input.normal.xyz);

  12. normálok

  13. pixel shader: normal map … float3 tangentNormal = normalize(normalTexture.Sample(linearSampler, 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) * kdTexture.Sample(linearSampler, input.tex); }

  14. Normal mapped

  15. .lua O:Material(_, {name='parallaxMapped', technique='displacement', pass='parallaxMapped'}, function(_) O:setSrv(_, {effectVariable='kdTexture', file='rkd.jpg'}) O:setSrv(_, {effectVariable='bumpTexture', file='rbump.jpg'}) O:setSrv(_, {effectVariable='normalTexture', file='rnormal.jpg'}) end ) O:MultiMesh(_, {name='parallaxMappedRock'}, function(_) O:FlipMesh(_, {}, function(_) O:ShadedMesh(_, {mien='basic', indexedMesh='rock', material='parallaxMapped'}) end ) end ) O:StaticEntity(_, {name='rock1', multiMesh='parallaxMappedRock', position = { x=50, y=100, z=0} } )

  16. parallax pass parallaxMapped { SetVertexShader ( CompileShader( vs_5_0, vsTrafo() ) ); SetGeometryShader( NULL ); SetRasterizerState( defaultRasterizer ); SetPixelShader( CompileShader( ps_5_0, psParallaxMapped() ) ); SetDepthStencilState( defaultCompositor, 0 ); SetBlendState( defaultBlender, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF ); }

  17. parallax – ez jön be a normalosba … float bump_height = 0.1; float bump = bumpTexture.Sample(linearSampler, input.tex); float3 viewDir = normalize(eyePos - input.worldPos); viewDir = float3(dot(viewDir, T), dot(viewDir, B), dot(viewDir, normal)); float2 texOffset = bump_height * viewDir.xy // / viewDir.z * bump; input.tex += texOffset;

  18. parallax – ez marad a végén float3 tangentNormal = normalize(normalTexture.Sample(linearSampler, 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) * kdTexture.Sample(linearSampler, input.tex);

  19. .lua O:Material(_, {name='reliefMapped', technique='displacement', pass='reliefMapped'}, function(_) O:setSrv(_, {effectVariable='kdTexture', file='rkd.jpg'}) O:setSrv(_, {effectVariable='bumpTexture', file='rbump.jpg'}) O:setSrv(_, {effectVariable='normalTexture', file='rnormal.jpg'}) end ) O:MultiMesh(_, {name='reliefMappedRock'}, function(_) O:FlipMesh(_, {}, function(_) O:ShadedMesh(_, {mien='basic', indexedMesh='rock', material='reliefMapped'}) end ) end ) O:StaticEntity(_, {name='rock2', multiMesh='reliefMappedRock', position = { x=100, y=100, z=0} } )

  20. Binary relief pass reliefMapped { SetVertexShader ( CompileShader( vs_5_0, vsTrafo() ) ); SetGeometryShader( NULL ); SetRasterizerState( defaultRasterizer ); SetPixelShader( CompileShader( ps_5_0, psReliefMapped() ) ); SetDepthStencilState( defaultCompositor, 0 ); SetBlendState( defaultBlender, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF ); }

  21. ez ugyanaz float4 psReliefMapped(VsosTrafo input) : SV_TARGET { 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)); float bump_height = 0.2; float bump = bumpTexture.Sample(linearSampler, input.tex); float3 viewDir = normalize(eyePos - input.worldPos); viewDir = float3(dot(viewDir, T), dot(viewDir, B), dot(viewDir, normal));

  22. psReliefMapped folyt. 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 = bumpTexture.Sample(linearSampler, 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;

  23. psBinaryRelief folyt. 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);}

  24. Relief mapping