Terrain light problem

Started by
19 comments, last by lyzerk 11 years, 7 months ago
hmm ok i did what i want now its a dark atmospher. but its directional light so i want do it like, strategy game, open lights with camera, like here http://prntscr.com/ewzcm
so i need point light for map i can do it with this effect file ?
(and this effect file from DirectxSampler)

[source lang="cpp"]//-----------------------------------------------------------------------------
// File: CompiledEffect.fx
//
// Desc:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
// Global variables
//-----------------------------------------------------------------------------
float4 g_MaterialAmbientColor; // Material's ambient color
float4 g_MaterialDiffuseColor; // Material's diffuse color

// This effect file uses a single directional light
float3 g_LightDir = normalize(float3(1.0f, 1.0f, -1.0f)); // Light's direction
float4 g_LightAmbient = { 0.1f, 0.1f, 0.1f, 0.1f }; // Light's ambient color
float4 g_LightDiffuse = { 1.0f, 1.0f, 1.0f, 1.0f }; // Light's diffuse color

texture g_RenderTargetTexture; // Full screen render target texture
texture g_MeshTexture; // Color texture for mesh

float g_fTime; // App's time in seconds
float4x4 g_mWorld; // World matrix for object
float4x4 g_mWorldViewProjection; // World * View * Projection matrix



//-----------------------------------------------------------------------------
// Texture samplers
//-----------------------------------------------------------------------------
sampler RenderTargetSampler =
sampler_state
{
Texture = <g_RenderTargetTexture>;
MinFilter = POINT;
MagFilter = POINT;
MipFilter = NONE;
AddressU = Clamp;
AddressV = Clamp;
};

sampler MeshTextureSampler =
sampler_state
{
Texture = <g_MeshTexture>;
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
};


//-----------------------------------------------------------------------------
// Vertex shader output structure
//-----------------------------------------------------------------------------
struct VS_OUTPUT
{
float4 Position : POSITION; // vertex position
float4 Diffuse : COLOR0; // vertex diffuse color
float2 TextureUV : TEXCOORD0; // vertex texture coords
};


//-----------------------------------------------------------------------------
// Name: RenderSceneVS
// Type: Vertex shader
// Desc: This shader computes standard transform and lighting
//-----------------------------------------------------------------------------
VS_OUTPUT RenderSceneVS( float4 vPos : POSITION,
float3 vNormal : NORMAL,
float2 vTexCoord0 : TEXCOORD0 )
{
VS_OUTPUT Output;
float3 vNormalWorldSpace;

// Animation the vertex based on time and the vertex's object space position
float4 vAnimatedPos = vPos;
/*vAnimatedPos.x *= (1.0 + cos(g_fTime)/10);
vAnimatedPos.y *= (1.0 + sin(g_fTime)/10);
vAnimatedPos.z *= (1.0 + cos(g_fTime)/10);*/

// Transform the position from object space to homogeneous projection space
Output.Position = mul(vAnimatedPos, g_mWorldViewProjection);

// Transform the normal from object space to world space
vNormalWorldSpace = normalize(mul(vNormal, (float3x3)g_mWorld)); // normal (world space)

// Compute simple directional lighting equation
Output.Diffuse.rgb = g_MaterialDiffuseColor * g_LightDiffuse * max(0,dot(vNormalWorldSpace, g_LightDir)) +
g_MaterialAmbientColor * g_LightAmbient;

Output.Diffuse.a = 1.0f;

// Just copy the texture coordinate through
Output.TextureUV = vTexCoord0;

return Output;
}


//-----------------------------------------------------------------------------
// Pixel shader output structure
//-----------------------------------------------------------------------------
struct PS_OUTPUT
{
float4 RGBColor : COLOR0; // Pixel color
};


//-----------------------------------------------------------------------------
// Name: RenderScenePS
// Type: Pixel shader
// Desc: This shader outputs the pixel's color
//-----------------------------------------------------------------------------
PS_OUTPUT RenderScenePS( VS_OUTPUT In )
{
PS_OUTPUT Output;

// Lookup mesh texture and modulate it with diffuse
Output.RGBColor = tex2D(MeshTextureSampler, In.TextureUV) * In.Diffuse;

return Output;
}



//-----------------------------------------------------------------------------
// Name: RenderScene
// Type: Technique
// Desc: Renders scene to render target
//-----------------------------------------------------------------------------
technique RenderScene
{
pass P0
{
ZENABLE = true;
VertexShader = compile vs_2_0 RenderSceneVS();
PixelShader = compile ps_2_0 RenderScenePS();
}
}
[/source]

I know im asking too much question but i want to learn it :/ and sorry for my english.

Thanks.

This topic is closed to new replies.

Advertisement