six 2D textures

Сomentários

Transcrição

six 2D textures
Bachelor Praktikum:
Echtzeitgraphik in C++ und DirectX10
computer graphics & visualization
Proto-Texturing
• Idea:
– Set of textures that serve as prototypes for different
materials (e.g. sand, grass, rock, snow, etc.)
– Height/slope-dependent weighting function to
decide how the textures are blended for a single
fragment
3D Praktikum WS 2009/2010 – Echtzeitgraphik in C++ und DirectX10
K. Bürger, S. Auer, Prof. Dr. Westermann
computer graphics & visualization
Proto-Texturing
• Pre-Processing:
– Store the precomputed weight
function in a RGBA-texture
Slope
– Weights for the different
materials are stored in the
distinct color channels
– Sum of weights should be 1
Height
Sand
Grass
Rock
Snow
3D Praktikum WS 2009/2010 – Echtzeitgraphik in C++ und DirectX10
K. Bürger, S. Auer, Prof. Dr. Westermann
computer graphics & visualization
Proto-Texturing
• How to texture a specific fragment?
1. Use height and slope as texture
coordinates to determine the
according weights
2. Use xz-coordinate as (scaled)
texture coordinate to access the
proto textures
3. Fetch samples from the proto
textures and blend them according
to the given weights
3D Praktikum WS 2009/2010 – Echtzeitgraphik in C++ und DirectX10
K. Bürger, S. Auer, Prof. Dr. Westermann
computer graphics & visualization
Environment Mapping
• An “advanced texturing” method in computer
graphics, which is used to
approximate reflections in
curved surfaces
3D Praktikum WS 2009/2010 – Echtzeitgraphik in C++ und DirectX10
K. Bürger, S. Auer, Prof. Dr. Westermann
computer graphics & visualization
Cubic Environment Mapping
• Idea:
– The Environment Map is
composed of six 2D textures,
representing the view from
the center of the box in the
orthogonal viewing directions
– Object is thought to be placed
at the center of the box and
the direction of the reflectance rays are used to
determine the reflected color of the environment
3D Praktikum WS 2009/2010 – Echtzeitgraphik in C++ und DirectX10
K. Bürger, S. Auer, Prof. Dr. Westermann
computer graphics & visualization
Cubic Environment Mapping
• Assumptions:
– Object is at the center of the cube
– Distance between object and cube (and its pictured
surroundings) is (near) infinity (or far enough)
3D Praktikum WS 2009/2010 – Echtzeitgraphik in C++ und DirectX10
K. Bürger, S. Auer, Prof. Dr. Westermann
computer graphics & visualization
Cubic Environment Mapping
• Given:
– normal n, position p (-> view vector v)
• Approach:
1. Compute reflection vector r
2. Assuming that p is in the center of the cube:
• Largest component and sign determines the cube face
• The two other components are adapted to the texture
space and devided by the largest component in order to
get the texture coordinates within the cube face.
• Note: cube map sampling is directly supported by HLSL!
3D Praktikum WS 2009/2010 – Echtzeitgraphik in C++ und DirectX10
K. Bürger, S. Auer, Prof. Dr. Westermann
computer graphics & visualization
Using Cubemaps
Application (Loading the resource):
Use the D3DX10CreateShaderResourceViewFromFile() function and cubemaps
in .dds Format (available on the couse homepage), so DirectX will automatically
create CubeMap resouce (Texture2DArray with special settings...)
HLSL sample code to access a cube map resource:
TextureCube2D myCubeMap;
//the Cube Map
float4 PSTextured(float4 pos : SV_Position, float3 wp : WORLDPOS, float3 normal : NORMAL) : SV_Target0{
//Calculate reflection vector based on incident view direction and surface normal
float3 incident = normalize(g_vEyePos - wp);
float3 R = reflect(incident, normalize(normal));
return myCubeMap.Sample( mySampler, R ).rgba; // a 3 component vector is needed to sample a cubemap
}
3D Praktikum WS 2009/2010 – Echtzeitgraphik in C++ und DirectX10
K. Bürger, S. Auer, Prof. Dr. Westermann
computer graphics & visualization
Environment
How can we colorize the background with the cubemap ?
Render „SkyBox or SkyDome“ textured with CubeMap Faces
Render single quad covering the whole viewport and calculate cubemap
intersection analytically
3D Praktikum WS 2009/2010 – Echtzeitgraphik in C++ und DirectX10
K. Bürger, S. Auer, Prof. Dr. Westermann
computer graphics & visualization
Environment
(0,0)
(Width-1,0)
(1,0)
(1,2)
(0.143,0.111)
(0,Height-1)
(0,1)
(Width-1,Height-1)
(1,1)
Inside a pixelshader we can always access the system value SV_Position, whose
x and y components contain a fragments position in texelcoordinates !
Normalize those values trough division by (Width-1, Height-1)
3D Praktikum WS 2009/2010 – Echtzeitgraphik in C++ und DirectX10
K. Bürger, S. Auer, Prof. Dr. Westermann
computer graphics & visualization
Environment
Normalized Device Coordinates (a position projected onto the imageplane,
after perspective transformation and dehomogenization) range from [-1,1] in
the xy-Domain (plus a nonlinear depthvalue for z-Testing)
(-1,1)
x
(1,1)
y
(0,-1)
(1,-1)
Shift Coordinates into NDC range: x = 2∙x -1, y = 1-2∙y
3D Praktikum WS 2009/2010 – Echtzeitgraphik in C++ und DirectX10
K. Bürger, S. Auer, Prof. Dr. Westermann
computer graphics & visualization
Environment
• We also know that the Camera is located at the origin of the view coordinate system
and looks down the +z-Axis.
• Based on camera parameters we can transform NDC coordinates into a vector from
the camera trought the image plane by scaling the normalized device coordinates
accordingly („fan out the view rays...“!)
x
1
FoV
-1
y
Vec3 ViewVec= Vec3(AspectRatio∙tan(0.5f∙FieldOfView)∙x, tan(0.5f∙FieldOfView)∙y, 1.0f);
3D Praktikum WS 2009/2010 – Echtzeitgraphik in C++ und DirectX10
K. Bürger, S. Auer, Prof. Dr. Westermann
computer graphics & visualization
Environment
• Multiplication with the inverse View-Matrix then transforms the
view rays back to worldspace, where they can be used as
CubeMap-Lookup coordinates.
3D Praktikum WS 2009/2010 – Echtzeitgraphik in C++ und DirectX10
K. Bürger, S. Auer, Prof. Dr. Westermann
computer graphics & visualization
Assignment 7
1. Proto-Textures:
–
–
–
–
Different tetures for sand, grass, rock, snow.
Pre-process weights and write them into a texture.
Use Height/slope to determine weights.
Use weights to blend the different material textures.
2. Cubic Environment Mapping
– Create a water surface on a specific height.
– Use cube map to approximate the reflexions of the
environment on the water surface.
3. Environment
– Use the cube map to render the environment around the
terrain.
3D Praktikum WS 2009/2010 – Echtzeitgraphik in C++ und DirectX10
K. Bürger, S. Auer, Prof. Dr. Westermann
computer graphics & visualization