.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
  • laboratornaya.bystrickaya.ru/referat-po-fizike.html
  • education.bystrickaya.ru/-ga-praslova-programma-osobennosti-formirovaniya-informacionnoj-kulturi-uchashihsya-v-obsheobrazovatelnih-uchrezhdeniyah.html
  • portfolio.bystrickaya.ru/otchyot-o-rezultatah-deyatelnosti-upravleniya-prirodnih-resursov-i-ohrani-okruzhayushej-sredi-penzenskoj-oblasti-za-2010-god-stranica-3.html
  • institute.bystrickaya.ru/glava-9-chelovek-v-obliche-zhivotnogo-propp-v-problemi-komizma-i-smeha-ritualnij-smeh-v-folklore-po-povodu-skazki-o-nesmeyane.html
  • abstract.bystrickaya.ru/18-sindromi-narusheniya-soznaniya-uchebnoe-posobie-dlya-studentov-mediko-psihologicheskogo-fakulteta-grodno-2004-g.html
  • grade.bystrickaya.ru/nacionalnaya-associaciya-pensionnih-fondov-monitoring-smi-rf-po-pensionnoj-tematike-25-noyabrya-2010-goda.html
  • thescience.bystrickaya.ru/kniga-dlya-rabotnikov-doshkolnih-uchrezhdenij.html
  • tasks.bystrickaya.ru/23-sociologiya-grazhdanstvennosti-grazhdanskoe-vospitanie-ili-akc.html
  • university.bystrickaya.ru/glava-19-zdravoohranenie-meinrad-perrez-lehrbuch-klinische-psychologie-psychotherapie.html
  • teacher.bystrickaya.ru/geograficheskaya-harakteristika-bibliograficheskij-ukazatel-2000-g.html
  • portfolio.bystrickaya.ru/osobennosti-formirovaniya-socialnih-fondov-v-stranah-rinochnoj-ekonomiki-poryadok-raschetov-s-vnebyudzhetnimi-socialnimi-fondami-v-rf-chast-7.html
  • doklad.bystrickaya.ru/uchebno-metodicheskij-kompleks-disciplini-gse-v-03-geokriologiya-merzlotovedenie-i-glyaciologiya.html
  • esse.bystrickaya.ru/programma-spec-kursa-belgorodskoj-duhovnoj-seminarii-s-missionerskoj-napravlennostyu-osobennosti-duhovno-prosvetitelskoj-i-vospitatelnoj-raboti-v-mestah-lisheniya-svobodi-tema-1.html
  • znaniya.bystrickaya.ru/raspredelenie-obyoma-realizacii-po-otgruzke-otkritoe-akcionernoe-obshestvo.html
  • university.bystrickaya.ru/gipoteza-issledovaniya-dinamika-kulturnih-modelej-v-globaliziruyushemsya-mire.html
  • nauka.bystrickaya.ru/vliyanie-sozvezdij-nakshatr-indijskaya-predskazatelnaya-astrologiya.html
  • letter.bystrickaya.ru/o-problemah-povisheniya-nadezhnosti-energoobespecheniya-v-rajonah-krajnego-severa.html
  • znanie.bystrickaya.ru/43-pozicionirovanie-kak-tehnologiya-marketingovogo-proektirovaniya-markov-aleksandr-petrovich.html
  • books.bystrickaya.ru/dumi-astrahanskoj-oblasti-stranica-10.html
  • books.bystrickaya.ru/doklad-municipalnogo-obrazovatelnogo-uchrezhdeniya-zhizdrinskaya-srednyaya-obsheobrazovatelnaya-shkola-2-stranica-2.html
  • holiday.bystrickaya.ru/novosti-negosudarstvennih-pensionnih-fondov-monitoring-smi-rf-po-pensionnoj-tematike-2-dekabrya-2010-goda.html
  • otsenki.bystrickaya.ru/rol-morskih-perevozok-v-mezhdunarodnom-biznese.html
  • crib.bystrickaya.ru/kniga-rasschitana-na-shirokie-krugi-specyaist-razlichnih-nepraerenij-nauki-i-tehniki-stranica-25.html
  • knigi.bystrickaya.ru/resheni-e-stranica-13.html
  • zanyatie.bystrickaya.ru/rizhij-ricar-posvyashaetsya-vsem-moim-druzyam-stranica-11.html
  • doklad.bystrickaya.ru/vopros-kakovo-bilo-bi-sootnoshenie-poter-dlya-shokovoj-terapii-pri-racionalnih-ozhidaniya-v-sluchae-visokogo-kredita-doveriya-so-storoni-naseleniya.html
  • kontrolnaya.bystrickaya.ru/proizvodit-priyom-abiturientov-p.html
  • university.bystrickaya.ru/ezhekvartalnijotche-t-emitenta-emissionnih-cennih-bumag-za-3-kvartal-2007g.html
  • abstract.bystrickaya.ru/23-vnesenie-izmenenij-v-izveshenie-o-provedenii-konkursa-i-konkursnuyu-dokumentaciyu.html
  • assessments.bystrickaya.ru/elhonon-goldberg-upravlyayushij-mozg-lobnie-doli-liderstvo-i-civilizaciya-annotaciya.html
  • upbringing.bystrickaya.ru/literatura-8-klass-a-s-pushkin-kapitanskaya-dochka.html
  • predmet.bystrickaya.ru/rost-kachestvennih-harakteristik-upravlencheskogo-personala-iz-chisla-molodih-specialistov-kak-faktor-povisheniya-konkurentosposobnosti-promishlennih-predpriyatij-stranica-17.html
  • college.bystrickaya.ru/23shlyuz-otchet-o-nauchno-issledovatelskoj-rabote-po-teme-21-razrabotka-rekomendacij-po-sozdaniyu-i-ispolzovaniyu.html
  • turn.bystrickaya.ru/ojin-erezhes-15-sel-mektep-bashasi-didaktikali-ojindar-rastiran-abilgazinova-g-z.html
  • student.bystrickaya.ru/22vidi-balansa-plan-schetov-buhgalterskogo-ucheta-37-5-formi-buhgalterskogo-ucheta-38.html
  • © bystrickaya.ru
    Мобильный рефератник - для мобильных людей.