«Математика. Прикладная математика» - страница 4
.RU

«Математика. Прикладная математика» - страница 4



sourcevals[2] = (tex2D( g_samShadow, ShadowTexC + float2(0, 1.0/SMAP_SIZE) ) + SHADOW_EPSILON < vPosLight.z / vPosLight.w)? 0.0f: 1.0f;

sourcevals[3] = (tex2D( g_samShadow, ShadowTexC + float2(1.0/SMAP_SIZE, 1.0/SMAP_SIZE) ) + SHADOW_EPSILON < vPosLight.z / vPosLight.w)? 0.0f: 1.0f;

// lerp between the shadow values to calculate our light amount

float LightAmount = lerp( lerp( sourcevals[0], sourcevals[1], lerps.x ),

lerp( sourcevals[2], sourcevals[3], lerps.x ),

lerps.y );

// Light it

Diffuse = ( saturate( dot( -vLight, normalize( vNormal ) ) ) * LightAmount * ( 1 - g_vLightAmbient ) + g_vLightAmbient )

* g_vMaterial;

} else

{

Diffuse = g_vLightAmbient * g_vMaterial;

}


return tex2D( g_samScene, Tex ) * Diffuse;

}

// Point

float4 PixScenePoint( float2 Tex : TEXCOORD0,

float4 vPos : TEXCOORD1,

float3 vNormal : TEXCOORD2,

float4 vPosLight : TEXCOORD3 ) : COLOR

{

float4 Diffuse;


// vLight is the unit vector from the light to this pixel

float3 vLight = normalize( float3( vPos - g_vLightPos ) );


// Compute diffuse from the light

if( dot( vLight, g_vLightDir ) > g_fCosTheta ) // Light must face the pixel (within Theta)

{

// Pixel is in lit area. Find out if it's

// in shadow using 2x2 percentage closest filtering


//transform from RT space to texture space.

float2 ShadowTexC = 0.5 * vPosLight.xy / vPosLight.w + float2( 0.5 + 0.5/SMAP_SIZE, 0.5 - 0.5/SMAP_SIZE );

ShadowTexC.y = 1.0f - ShadowTexC.y;

// do the shadow check

float Depth = tex2D( g_samShadow, ShadowTexC ) + SHADOW_EPSILON < vPosLight.z / vPosLight.w ? 0.0f : 1.0f;

// Light it

Diffuse = ( saturate( dot( -vLight, normalize( vNormal ) ) ) * Depth * ( 1 - g_vLightAmbient ) + g_vLightAmbient )

* g_vMaterial;

} else

{

Diffuse = g_vLightAmbient * g_vMaterial;

}


return tex2D( g_samScene, Tex ) * Diffuse;

}

// Bilinear

float4 PixSceneBilinear( float2 Tex : TEXCOORD0,

float4 vPos : TEXCOORD1,

float3 vNormal : TEXCOORD2,

float4 vPosLight : TEXCOORD3 ) : COLOR

{

float4 Diffuse;


// vLight is the unit vector from the light to this pixel

float3 vLight = normalize( float3( vPos - g_vLightPos ) );


// Compute diffuse from the light

if( dot( vLight, g_vLightDir ) > g_fCosTheta ) // Light must face the pixel (within Theta)

{

// Pixel is in lit area. Find out if it's

// in shadow using 2x2 percentage closest filtering


//transform from RT space to texture space.

float2 ShadowTexC = 0.5 * vPosLight.xy / vPosLight.w + float2( 0.5, 0.5 );

ShadowTexC.y = 1.0f - ShadowTexC.y;


// transform to texel space

float2 texelpos = SMAP_SIZE * ShadowTexC;

// Determine the lerp amounts

float2 lerps = frac( texelpos );


//read in bilerp stamp

float sourcevals[4];

sourcevals[0] = (tex2D( g_samShadow, ShadowTexC ));

sourcevals[1] = (tex2D( g_samShadow, ShadowTexC + float2(1.0/SMAP_SIZE, 0) ));

sourcevals[2] = (tex2D( g_samShadow, ShadowTexC + float2(0, 1.0/SMAP_SIZE) ));

sourcevals[3] = (tex2D( g_samShadow, ShadowTexC + float2(1.0/SMAP_SIZE, 1.0/SMAP_SIZE) ));

// lerp between the depth values

float Depth = lerp( lerp( sourcevals[0], sourcevals[1], lerps.x ),

lerp( sourcevals[2], sourcevals[3], lerps.x ),

lerps.y );

Depth = Depth + SHADOW_EPSILON < vPosLight.z / vPosLight.w ? 0.0f : 1.0f;

// Light it

Diffuse = ( saturate( dot( -vLight, normalize( vNormal ) ) ) * Depth * ( 1 - g_vLightAmbient ) + g_vLightAmbient )

* g_vMaterial;

} else

{

Diffuse = g_vLightAmbient * g_vMaterial;

}


return tex2D( g_samScene, Tex ) * Diffuse;

}

// MaxDepth

float4 PixSceneMaxDepth( float2 Tex : TEXCOORD0,

float4 vPos : TEXCOORD1,

float3 vNormal : TEXCOORD2,

float4 vPosLight : TEXCOORD3 ) : COLOR

{

float4 Diffuse;


// vLight is the unit vector from the light to this pixel

float3 vLight = normalize( float3( vPos - g_vLightPos ) );


// Compute diffuse from the light

if( dot( vLight, g_vLightDir ) > g_fCosTheta ) // Light must face the pixel (within Theta)

{

// Pixel is in lit area. Find out if it's

// in shadow using 2x2 percentage closest filtering


//transform from RT space to texture space.

float2 ShadowTexC = 0.5 * vPosLight.xy / vPosLight.w + float2( 0.5, 0.5 );

ShadowTexC.y = 1.0f - ShadowTexC.y;


//read depths

float sourcevals[4];

sourcevals[0] = (tex2D( g_samShadow, ShadowTexC ));

sourcevals[1] = (tex2D( g_samShadow, ShadowTexC + float2(1.0/SMAP_SIZE, 0) ));

sourcevals[2] = (tex2D( g_samShadow, ShadowTexC + float2(0, 1.0/SMAP_SIZE) ));

sourcevals[3] = (tex2D( g_samShadow, ShadowTexC + float2(1.0/SMAP_SIZE, 1.0/SMAP_SIZE) ));

// max of the depth values

float Depth = max(max(sourcevals[0], sourcevals[1]), max(sourcevals[2], sourcevals[3]));

Depth = Depth + SHADOW_EPSILON < vPosLight.z / vPosLight.w ? 0.0f : 1.0f;

// Light it

Diffuse = ( saturate( dot( -vLight, normalize( vNormal ) ) ) * Depth * ( 1 - g_vLightAmbient ) + g_vLightAmbient )

* g_vMaterial;

} else

{

Diffuse = g_vLightAmbient * g_vMaterial;

}


return tex2D( g_samScene, Tex ) * Diffuse;

}

// MinDepth

float4 PixSceneMinDepth( float2 Tex : TEXCOORD0,

float4 vPos : TEXCOORD1,

float3 vNormal : TEXCOORD2,

float4 vPosLight : TEXCOORD3 ) : COLOR

{

float4 Diffuse;


// vLight is the unit vector from the light to this pixel

float3 vLight = normalize( float3( vPos - g_vLightPos ) );


// Compute diffuse from the light

if( dot( vLight, g_vLightDir ) > g_fCosTheta ) // Light must face the pixel (within Theta)

{

// Pixel is in lit area. Find out if it's

// in shadow using 2x2 percentage closest filtering


//transform from RT space to texture space.

float2 ShadowTexC = 0.5 * vPosLight.xy / vPosLight.w + float2( 0.5, 0.5 );

ShadowTexC.y = 1.0f - ShadowTexC.y;


//read depths

float sourcevals[4];

sourcevals[0] = (tex2D( g_samShadow, ShadowTexC ));

sourcevals[1] = (tex2D( g_samShadow, ShadowTexC + float2(1.0/SMAP_SIZE, 0) ));

sourcevals[2] = (tex2D( g_samShadow, ShadowTexC + float2(0, 1.0/SMAP_SIZE) ));

sourcevals[3] = (tex2D( g_samShadow, ShadowTexC + float2(1.0/SMAP_SIZE, 1.0/SMAP_SIZE) ));

// max of the depth values

float Depth = min(min(sourcevals[0], sourcevals[1]), min(sourcevals[2], sourcevals[3]));

Depth = Depth + SHADOW_EPSILON < vPosLight.z / vPosLight.w ? 0.0f : 1.0f;

// Light it

Diffuse = ( saturate( dot( -vLight, normalize( vNormal ) ) ) * Depth * ( 1 - g_vLightAmbient ) + g_vLightAmbient )

* g_vMaterial;

} else

{

Diffuse = g_vLightAmbient * g_vMaterial;

}


return tex2D( g_samScene, Tex ) * Diffuse;

}

// Grads

float4 PixSceneGrads( float2 Tex : TEXCOORD0,

float4 vPos : TEXCOORD1,

float3 vNormal : TEXCOORD2,

float4 vPosLight : TEXCOORD3 ) : COLOR

{

float4 Diffuse;


// vLight is the unit vector from the light to this pixel

float3 vLight = normalize( float3( vPos - g_vLightPos ) );


// Compute diffuse from the light

if( dot( vLight, g_vLightDir ) > g_fCosTheta ) // Light must face the pixel (within Theta)

{

// Pixel is in lit area. Find out if it's

// in shadow using 2x2 percentage closest filtering


//transform from RT space to texture space.

float2 ShadowTexC = 0.5 * vPosLight.xy / vPosLight.w + float2( 0.5 + 0.5/SMAP_SIZE, 0.5 - 0.5/SMAP_SIZE );

ShadowTexC.y = 1.0f - ShadowTexC.y;

// compute grads wrt light src

float3 str = vPosLight.xyz / vPosLight.w;

float3

d_str_dx = ddx(str) * g_screen_res.x,

d_str_dy = ddy(str) * g_screen_res.y;

float2x2 d_st_dxdy = { d_str_dx.xy, d_str_dy.xy };

float2x2 d_st_dxdy_inv = float2x2(d_st_dxdy._22, d_st_dxdy._12, d_st_dxdy._21, d_st_dxdy._11) / determinant(d_st_dxdy);

float2 d_r_dsdt_abs = abs(mul(d_st_dxdy_inv, float2(d_str_dx.z, d_str_dy.z)));

float grads_magnitude = 0.5 * (d_r_dsdt_abs.x + d_r_dsdt_abs.y);//return grads_magnitude/10;


// do the shadow check

float Depth = tex2D( g_samShadow, ShadowTexC ) + SHADOW_EPSILON < vPosLight.z / vPosLight.w ? 0.0f : 1.0f;


// apply grads fade

Depth *= (1 - smoothstep(g_grad_begin_fade, g_grad_end_fade, grads_magnitude));

// Light it

Diffuse = ( saturate( dot( -vLight, normalize( vNormal ) ) ) * Depth * ( 1 - g_vLightAmbient ) + g_vLightAmbient )

* g_vMaterial;

} else

{

Diffuse = g_vLightAmbient * g_vMaterial;

}


return tex2D( g_samScene, Tex ) * Diffuse;

}


//-----------------------------------------------------------------------------

// Vertex Shader: VertLight

// Desc: Process vertex for the light object

//-----------------------------------------------------------------------------

void VertLight( float4 iPos : POSITION,

float3 iNormal : NORMAL,

float2 iTex : TEXCOORD0,

out float4 oPos : POSITION,

out float2 Tex : TEXCOORD0 )

{

//

// Transform position to view space

//

oPos = mul( iPos, g_mWorldView );


//

// Transform to screen coord

//

oPos = mul( oPos, g_mProj );


//

// Propagate texture coord

//

Tex = iTex;

}


//-----------------------------------------------------------------------------

// Pixel Shader: PixLight

// Desc: Process pixel for the light object

//-----------------------------------------------------------------------------

float4 PixLight( float2 Tex : TEXCOORD0,

float4 vPos : TEXCOORD1 ) : COLOR

{

return tex2D( g_samScene, Tex );

}


//-----------------------------------------------------------------------------

// Vertex Shader: VertShadow

// Desc: Process vertex for the shadow map

//-----------------------------------------------------------------------------

void VertShadow( float4 Pos : POSITION,

float3 Normal : NORMAL,

out float4 oPos : POSITION,

out float2 Depth : TEXCOORD0 )

{

//

// Compute the projected coordinates

//

oPos = mul( Pos, g_mWorldView );

oPos = mul( oPos, g_mProj );


//

// Store z and w in our spare texcoord

//

Depth.xy = oPos.zw;

}


//-----------------------------------------------------------------------------

// Pixel Shader: PixShadow

// Desc: Process pixel for the shadow map

//-----------------------------------------------------------------------------

void PixShadow( float2 Depth : TEXCOORD0,

out float4 Color : COLOR )

{

//

// Depth is z / w

//

Color = Depth.x / Depth.y;

}

// SlopeScaleBias

void PixShadowSlopeScaleBiasMax( float2 Depth : TEXCOORD0,

out float4 Color : COLOR )

{

//

// Depth is z / w

//

Color = Depth.x / Depth.y;

Color += max(abs(ddx(Color)), abs(ddy(Color)));

}

void PixShadowSlopeScaleBiasSum( float2 Depth : TEXCOORD0,

out float4 Color : COLOR )

{

//

// Depth is z / w

//

Color = Depth.x / Depth.y;

Color += 0.5 * (abs(ddx(Color)) + abs(ddy(Color)));

}


//-----------------------------------------------------------------------------

// Technique: RenderScene

// Desc: Renders scene objects

//-----------------------------------------------------------------------------

technique RenderScene

{

pass p0

{

VertexShader = compile vs_1_1 VertScene();

PixelShader = compile ps_2_0 PixScene();

}

}

technique RenderScenePoint

{

pass p0

{

VertexShader = compile vs_1_1 VertScene();

PixelShader = compile ps_2_0 PixScenePoint();

}

}

technique RenderSceneBilinear

{

pass p0

{

VertexShader = compile vs_1_1 VertScene();

PixelShader = compile ps_2_0 PixSceneBilinear();

}

}

technique RenderSceneMaxDepth

{

pass p0

{

VertexShader = compile vs_1_1 VertScene();

PixelShader = compile ps_2_0 PixSceneMaxDepth();

}

}

technique RenderSceneMinDepth

{

pass p0

{

VertexShader = compile vs_3_0 VertScene();

PixelShader = compile ps_3_0 PixSceneMinDepth();

}

}

technique RenderSxeneGrads

{

pass p0

{

VertexShader = compile vs_3_0 VertScene();

PixelShader = compile ps_3_0 PixSceneGrads();

}

}


//-----------------------------------------------------------------------------

// Technique: RenderLight

// Desc: Renders the light object

//-----------------------------------------------------------------------------

technique RenderLight

{

pass p0

{

VertexShader = compile vs_1_1 VertLight();

PixelShader = compile ps_1_1 PixLight();

}

}


//-----------------------------------------------------------------------------

// Technique: RenderShadow

// Desc: Renders the shadow map

//-----------------------------------------------------------------------------

technique RenderShadow

{

pass p0

{

VertexShader = compile vs_1_1 VertShadow();

PixelShader = compile ps_2_0 PixShadow();

}

}

technique RenderShadowSlopeScaleBiasMax

{

pass p0

{

VertexShader = compile vs_1_1 VertShadow();

PixelShader = compile ps_2_a PixShadowSlopeScaleBiasMax();

}

}

technique RenderShadowSlopeScaleBiasSum

{

pass p0

{

VertexShader = compile vs_1_1 VertShadow();

PixelShader = compile ps_2_a PixShadowSlopeScaleBiasSum();

}

}


defines.fxh

//--------------------------------------------------------------------------------------

// File: defines.fxh

//--------------------------------------------------------------------------------------


#pragma once


// rendering modes

#define RENDERING_MODE_FINAL 0

#define RENDERING_MODE_LOCAL_NORMAL 1

#define RENDERING_MODE_WORAL_NORMAL 2

#define RENDERING_MODE_SEARCH_STEPS 3


// gradient evaluation methods

#define GRAD_METHOD_STD 0

#define GRAD_METHOD_BASE_PLANE 1

#define GRAD_METHOD_HYBRID 2


shared.fxh

//--------------------------------------------------------------------------------------

// File: shared.fxh

//--------------------------------------------------------------------------------------


//--------------------------------------------------------------------------------------

// Shared variables

//--------------------------------------------------------------------------------------

shared textureCUBE g_CubeTexture; // color texture for cube


shared float g_fTime; // App's time in seconds

shared float4x4 g_mViewProjection; // View * Projection matrix


//--------------------------------------------------------------------------------------

// Texture samplers

//--------------------------------------------------------------------------------------

samplerCUBE CubeMapSampler =

sampler_state

{

Texture = ;

MipFilter = LINEAR;

MinFilter = ANISOTROPIC;

MagFilter = LINEAR;

MaxAnisotropy = 16;

AddressU = CLAMP;

AddressV = CLAMP;

AddressW = CLAMP;

};


Cube.fx

//--------------------------------------------------------------------------------------

// File: Cube.fx

//--------------------------------------------------------------------------------------


//--------------------------------------------------------------------------------------

// Includes

//--------------------------------------------------------------------------------------

#include "shared.fxh"


//--------------------------------------------------------------------------------------

// Global variables

//--------------------------------------------------------------------------------------

float4x4 g_mWorld; // World matrix for cube


//--------------------------------------------------------------------------------------

// Vertex shader output structure

//--------------------------------------------------------------------------------------

struct VS_OUTPUT

{

float4 Position : POSITION; // vertex position

float3 TextureXYZ : TEXCOORD0; // vertex texture coords

};


//--------------------------------------------------------------------------------------

// This shader computes standard transform

//--------------------------------------------------------------------------------------

VS_OUTPUT Transform_VS(float3 vPos : POSITION)

{

VS_OUTPUT Output;

float4x4 g_mWorldViewProjection = mul(g_mWorld, g_mViewProjection);

// Transform the position from object space to homogeneous projection space

Output.Position = mul(float4(vPos, 1), g_mWorldViewProjection);

// Just copy the texture coordinate through

Output.TextureXYZ = vPos;

return Output;

}


//--------------------------------------------------------------------------------------

// Cube pixel shader

//--------------------------------------------------------------------------------------

float4 Cube_PS(VS_OUTPUT In) : COLOR0

{

float4 Output;

// Lookup cube map

Output.rgb = texCUBE(CubeMapSampler, In.TextureXYZ);

Output.a = 1;

return Output;

}


//--------------------------------------------------------------------------------------

// Techniques

//--------------------------------------------------------------------------------------

technique Cube

{

pass P0

{

VertexShader = compile vs_2_0 Transform_VS();

PixelShader = compile ps_2_0 Cube_PS();

CullMode = CW;

}

}


SurfaceDetailVariations.fx

//--------------------------------------------------------------------------------------

// File: SurfaceDetailVariations.fx

//--------------------------------------------------------------------------------------


//--------------------------------------------------------------------------------------

// Includes

//--------------------------------------------------------------------------------------

#include "defines.fxh"

#include "shared.fxh"


//--------------------------------------------------------------------------------------

// Global variables

//--------------------------------------------------------------------------------------

static const float3 g_MaterialAmbientColor = { 0.2, 0.2, 0.2 }; // Material's ambient color

static const float3 g_MaterialDiffuseColor = { 0.5, 0.5, 0.5 }; // Material's diffuse color

static const float3 g_MaterialSpecularColor = { 0.7, 0.7, 0.7 }; // Material's specular color

static const float3 g_Normal = { 0.0, 0.0, -1.0 }; // Quad's normal in object space

static const float g_Shine = 128;

float g_height_delta_scale;

float g_max_height;

float g_grad_threshold;

float g_max_raytrace_bias;

float g_linear_search_delta;

int g_binary_search_steps;

float g_reflectance;

bool g_reflections;

bool g_cast_shadows;

float g_tex_scale; // Simple transform in tangent space

float3 g_Eye; // Eye position in world space

float3 g_WorldLightDir; // Normalized light's direction in world space

float4 g_LightDiffuse; // Light's diffuse color

float2 g_normal_height_map_res; // Resolution of normal height map

int g_rendering_mode; // Renderein mode (normal, final)

int g_height_diff_samples; // Technique (number of samples) of height map differentiation

int g_grad_method; // Gradients evaluation method


texture2D g_ColorTexture; // Color texture for object

texture2D g_NormalHeightTexture; // Normal & height texture for object


float4x4 g_mWorld; // World matrix for object


//--------------------------------------------------------------------------------------

// Texture samplers

//--------------------------------------------------------------------------------------

sampler2D ColorTextureSampler =

sampler_state

{

Texture = ;

MipFilter = LINEAR;

MinFilter = ANISOTROPIC;

MagFilter = LINEAR;

MaxAnisotropy = 16;

AddressU = MIRROR;

AddressV = MIRROR;

};


sampler2D NormalHeightTextureSampler =

sampler_state

{

Texture = ;

MipFilter = LINEAR;

MinFilter = LINEAR;

MagFilter = LINEAR;

MaxAnisotropy = 16;

AddressU = MIRROR;

AddressV = MIRROR;

};


//--------------------------------------------------------------------------------------

// Vertex shaders output structures

//--------------------------------------------------------------------------------------

struct TRANSFORM_REFLECT_VS_OUTPUT

{

float4 Position : POSITION; // vertex position

float2 TextureUV : TEXCOORD0; // vertex texture coords

float3 WorldPos : TEXCOORD1; // vertex position in world space

float3 Normal : TEXCOORD2; // vertex normal in world space

float3 Reflect : TEXCOORD3; // vertex reflection direction in world space

};


struct TRANSFORM_VS_OUTPUT

{

float4 Position : POSITION; // vertex position

float2 TextureUV : TEXCOORD0; // vertex texture coords

float3 WorldPos : TEXCOORD1; // vertex position in world space

};


//--------------------------------------------------------------------------------------

// This shader computes standard transform along with world normal and reflection direction

//--------------------------------------------------------------------------------------

TRANSFORM_REFLECT_VS_OUTPUT Transform_Reflect_VS(float3 vPos : POSITION, float2 vTexCoord0 : TEXCOORD0)

{

TRANSFORM_REFLECT_VS_OUTPUT Output;

float4x4 g_mWorldViewProjection = mul(g_mWorld, g_mViewProjection);

// Transform the position from object space to homogeneous projection space

Output.Position = mul(float4(vPos, 1), g_mWorldViewProjection);

// Just copy the texture coordinate through

Output.TextureUV = vTexCoord0;

// Transform the position from object space to world space

Output.WorldPos = mul(float4(vPos, 1), g_mWorld);

// Transform the normal from object space to world space

Output.Normal = normalize(mul(g_Normal, (float3x3)g_mWorld)); // normal (world space)

// Find reflection direction in world space

float3 v = g_Eye - Output.WorldPos;

Output.Reflect = reflect(-v, Output.Normal);

return Output;

}


//--------------------------------------------------------------------------------------

// This shader computes standard transform

//--------------------------------------------------------------------------------------

TRANSFORM_VS_OUTPUT Transform_VS(float3 vPos : POSITION, float2 vTexCoord0 : TEXCOORD0)

{

TRANSFORM_VS_OUTPUT Output;

float4x4 g_mWorldViewProjection = mul(g_mWorld, g_mViewProjection);

// Transform the position from object space to homogeneous projection space

Output.Position = mul(float4(vPos, 1), g_mWorldViewProjection);

// Just copy the texture coordinate through

Output.TextureUV = vTexCoord0;

// Transform the position from object space to world space

Output.WorldPos = mul(float4(vPos, 1), g_mWorld);

return Output;

}


//--------------------------------------------------------------------------------------

// Displacement mapping vertex shader

//--------------------------------------------------------------------------------------

TRANSFORM_VS_OUTPUT DisplacementMapping_VS(float3 vPos : POSITION, float2 vTexCoord0 : TEXCOORD0)

{

TRANSFORM_VS_OUTPUT Output;


float4x4 g_mWorldViewProjection = mul(g_mWorld, g_mViewProjection);

// Transform the position from object space to homogeneous projection space

Output.Position = mul(float4(vPos, 1), g_mWorldViewProjection);

// Just copy the texture coordinate through

Output.TextureUV = vTexCoord0;

// Transform the position from object space to world space

Output.WorldPos = mul(float4(vPos, 1), g_mWorld);

return Output;

}


//--------------------------------------------------------------------------------------

// Pixel shader output structure

//--------------------------------------------------------------------------------------

struct PS_OUTPUT

{

float4 RGBColor : COLOR0; // Pixel color

};


//--------------------------------------------------------------------------------------

// These functions returns normal (possible unnormalized) in (+t +b -n) space

//--------------------------------------------------------------------------------------

// Forward declarations

float3 FetchNormal(uniform sampler2D NormalHeightSampler, in float2 uv);

float3 FetchNormal(uniform sampler2D NormalHeightSampler, in float2 uv, in float2 dx, in float2 dy);


float3 FetchNormal(uniform sampler2D NormalHeightSampler, in float2 uv)

{

return FetchNormal(NormalHeightSampler, uv, ddx(uv), ddy(uv));

}


float3 FetchNormal(uniform sampler2D NormalHeightSampler, in float2 uv, in float2 dx, in float2 dy)

{

if(g_height_diff_samples == 0)

{

// fetch normal from normal map

float3 n = tex2Dgrad(NormalHeightSampler, uv, dx, dy).xyz;

// unpack [0..1]->[-1..1]

n = n * 2.0 - 1.0;

// reconstruct z

n.z = sqrt(1 - dot(n.xy, n.xy));

return float3(n.x, -n.y, -n.z);

}

else

{

/*------------------------------------------------------------------------------

compute normal based on height map in normalized (+t +b +n) space

U = u / g_tex_scale ( = 2u); dh/dU = 0.5 * dh/du

V = v / g_tex_scale ( = 2v); dh/dV = 0.5 * dh/dv

n = (dp/dU x dp/dV) - (dh/dU * dp/dU) - (dh/dV * dp/dV) (*)

------------------------------------------------------------------------------*/

// compute delta

// const float tex_compress = max(length(dx * g_normal_height_map_res), length(dy * g_normal_height_map_res));

// const float2 delta = clamp((float2)tex_compress, 1, g_normal_height_map_res) / g_normal_height_map_res * g_height_delta_scale;

const float2 delta = g_height_delta_scale / g_normal_height_map_res;

float3 n;

// ( * g_tex_scale) for d/du->d/dU, d/dv->d/dV

// ( / -g_tex_scale) for unnormalized (+T +B -N) -> normalized (+t +b +n) space

// (-) in formula (*)

if (g_height_diff_samples == 3)

{

float

height_centre = tex2Dgrad(NormalHeightSampler, float2(uv.x, uv.y), dx, dy).w,

height_x = tex2Dgrad(NormalHeightSampler, float2(uv.x + delta.x, uv.y), dx, dy).w,

heitht_y = tex2Dgrad(NormalHeightSampler, float2(uv.x, uv.y + delta.y), dx, dy).w;

n.x = g_max_height * (height_x - height_centre) / delta;

n.y = g_max_height * (heitht_y - height_centre) / delta;

malinovka-skazka-vernie-druzya.html
malish-i-karlson-spektakl-vipusknikov-nachalnoj-shkoli-uroki-nachinayutsya-133.html
malishej-po-sotne-v-mesyac-zakon-po-ukazaniyu-suda-iniciativa-prinyatiya-zakona-ishodila-ot-sudej-konstitucionnogo.html
malishi-privatizatori-lgota-dlya-msp-trebuet-srochnih-razyasnenij.html
malko-inna-anatolevna-uchitel-informatiki-gimnazii-11-g-norilska-krasnoyarskogo-kraya.html
malleus-maleficarum-chto-zhe-iz-sebya-predstavlyaet-stranica-23.html
  • tasks.bystrickaya.ru/10-organizacionno-pedagogicheskie-meropriyatiya-plan-uchebno-vospitatelnoj-raboti-municipalnogo-obsheobrazovatelnogo.html
  • university.bystrickaya.ru/glava-1-obshie-polozheniya-kompleksnaya-bezopasnost-nesovershennoletnih-chast-1-pravovie-akti-rossijskoj-federacii.html
  • reading.bystrickaya.ru/komissiya-po-delam-nesovershennoletnih-i-zashite-ih-prav-za-dekabr-2011-goda-voprosi-vnesennie-na-rassmotrenie-glavi-administracii.html
  • school.bystrickaya.ru/elektromagnitnie-volni-mezhdu-parallelnimi-idealno-provodyashimi-ploskostyami.html
  • knigi.bystrickaya.ru/socialnaya-sfera-pasport-municipalnogo-obrazovaniya-gorod-vologda.html
  • composition.bystrickaya.ru/polozhenie-ob-organizacii-deyatelnosti-problemnih-komissij.html
  • literature.bystrickaya.ru/drugoe-tv-vzaimodejstvie-gosdumi-s-federalnimi-organami-6-radio-6.html
  • crib.bystrickaya.ru/itogi-iv-respublikanskoj-diagnostiki-obrazovatelnih-dostizhenij-uchashihsya-vipusk-4-izdatelstvo-biro-stranica-18.html
  • occupation.bystrickaya.ru/minusinskij-medicinskij-tehnikum-teksti-dlya-chteniya-po-anglijskomu-yaziku-dlya-studentov-medicinskih-specialnostej-minusinsk-2010.html
  • university.bystrickaya.ru/glava-11-yakov-shprenger-genrih-kramer-instituoris.html
  • textbook.bystrickaya.ru/informacionnij-byulleten-altajskogo-regionalnogo-otdeleniya-partii-edinaya-rossiya-4-33-g-barnaul-mart-2011g.html
  • universitet.bystrickaya.ru/stenograficheskij-otchet-o-videokonferencii-po-voprosam-realizacii-prioritetnih-nacionalnih-proektov-moskva-kreml-8-iyunya-2006-goda-v-putin-stranica-6.html
  • klass.bystrickaya.ru/alkogolnaya-produkciya-s-obemnoj-dolej-etilovogo-spirta-ot-9-do-25-procentov-vklyuchitelno-za-isklyucheniem-vin.html
  • textbook.bystrickaya.ru/i-kusochnaya-lokalnaya-interpolyaciya-osnovi-diskretnoj-matematiki.html
  • write.bystrickaya.ru/glava-13-steh-por-kak-atakuyushij-flot-rasi-pribil-na-tosev-3-admiral-atvar-mnozhestvo-raz-sobiral-kapitanov-korablej.html
  • education.bystrickaya.ru/1-399-000-893-274-obshinski-svet-grad-dobrich.html
  • bystrickaya.ru/zashita-ot-zakaznogo-bankrotstvazashita-ot-zakaznogo-bankrotstva-chast-5.html
  • learn.bystrickaya.ru/etika-kommersanta-2.html
  • zadachi.bystrickaya.ru/pisma-v-gazetu-kirovskaya-pravda-v-godi-velikoj-otechestvennoj-vojni.html
  • essay.bystrickaya.ru/biznes-vne-zakona-chelyabinskie-narkopolicejskie-izyali-chetire-kilogramma-marihuani.html
  • occupation.bystrickaya.ru/note-iie-cannot-guarantee-this-letters-confidentiality-once-it-becomes-part-of-a-universitys-records.html
  • exchangerate.bystrickaya.ru/inkvizicionnij-process-formalnaya-sistema-dokazatelstv.html
  • grade.bystrickaya.ru/metodika-izucheniya-cerkovnoslavyanskogo-yazika-kak-put-osushestvleniya-mezhpredmetnih-svyazej-v-sovremennoj-shkole.html
  • exchangerate.bystrickaya.ru/k-voprosu-o-pravovih-vozmozhnostyah-prokurora-v-grazhdanskom-sudoproizvodstve.html
  • institut.bystrickaya.ru/tema-vsego-chasov-uchebno-metodicheskij-kompleks-dlya-studentov-specialnosti-030501-yurisprudenciya.html
  • universitet.bystrickaya.ru/strannost-strannih-attraktorov-s-p-kapica-s-p-kurdyumov-g-g-malineckij-sinergetika-i-prognozi-budushego.html
  • lektsiya.bystrickaya.ru/programma-disciplini-ekonomicheskaya-socialnaya-i-politicheskaya-geografiya-opd-f-11-celi-i-zadachi-disciplini.html
  • spur.bystrickaya.ru/kompleksnij-analiz-pravovogo-mehanizma-pomesheniya-tovarov-pod-tamozhennie-rezhimi-pererabotki-chast-8.html
  • laboratornaya.bystrickaya.ru/razdel-15-neotlozhnie-sostoyaniya-intensivnaya-terapiya-i-reanimaciya-v-pediatrii-socialnaya-gigiena-i-organizaciya-skoroj-medicinskoj-pomoshi.html
  • lesson.bystrickaya.ru/statisticheskoe-izuchenie-byudzheta-amurskoj-oblasti.html
  • otsenki.bystrickaya.ru/shken-ajmanov-atindai-azafilm-akcionerlk-oami.html
  • knigi.bystrickaya.ru/respubliki-kazahstan-stranica-9.html
  • literature.bystrickaya.ru/doklad-komissii-obshestvennoj-palati-rossijskoj-federacii-po-delam-veteranov-voennosluzhashih-i-chlenov-ih-semej.html
  • testyi.bystrickaya.ru/abaj-poeziyasindai-danali-abaj-poeziyasindai-danali.html
  • grade.bystrickaya.ru/na-uchebnoe-posobie-ekonomicheskij-analiz-deyatelnosti-predpriyatij-m-2002g-pyastolov-s-m.html
  • © bystrickaya.ru
    Мобильный рефератник - для мобильных людей.