Presentation is loading. Please wait.

Presentation is loading. Please wait.

Displacement mapping Szécsi László. Letöltés rock.obj rkd.jpg rbump.jpg rnormal.jpg.

Similar presentations


Presentation on theme: "Displacement mapping Szécsi László. Letöltés rock.obj rkd.jpg rbump.jpg rnormal.jpg."— 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 )

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

5 main.fx #include #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 normálok

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

11 Normal mapped

12 .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 ) O:StaticEntity(_, {name='rock1', multiMesh='parallaxMappedRock', position = { x=50, y=100, z=0} } )

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

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

15 parallax – ez marad a végén float3 tangentNormal = normalize(normalTexture.Sample(linearSample r, 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);

16 .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 ) O:StaticEntity(_, {name='rock2', multiMesh='reliefMappedRock', position = { x=100, y=100, z=0} } )

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

18 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));

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

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

21 Relief mapping


Download ppt "Displacement mapping Szécsi László. Letöltés rock.obj rkd.jpg rbump.jpg rnormal.jpg."

Similar presentations


Ads by Google