Pixel Lighting 2D Rendering / Normal Map - directX

I'm looking for the simplest, easiest, and fastest way to render 2D textured ATVs with per-pixel normals. I mean the 3D world where the camera is fixed and all the texture squares are facing in the same direction (camera) and there will be light dots between them, and I want the textures to have normal pixel values, so they will burn as if they were 3D models.

most of the methods that I found on the network are too complicated and heavy, because they relate to real 3D models, while all I need is simple 2 ATVs.

Does anyone know a suitable technique or can publish a useful tutorial? oh and DX are just pls.

thank.

+3
source share
2 answers

I have more experience with XNA, not directX, but the principle is the same.

You need a normal map, this tells your shader exactly that the normal surface is at a given point. Then you need your squares to appear in the form of textures (they probably already exist, so this is actually not an extra work). Then you draw ATVs with a pixel shader, inside the shader you do something like:

//This shader only handles one directional light, there are various tecnhiques for handling multiple lights.
float3 LightDirection;

//Normal map, set this before rendering the quad
Texture NormalMap;
//sampler
sampler normalSampler = sampler_state
{
  texture = <NormalMap>;
}

//Diffusemap, set this before rendering the quad. This is just your normal texture you want applied to the quad
Texture DiffuseMap;
//sampler
sampler diffuseSampler = sampler_state
{
  texture = <DiffuseMap>;
}

/* you probably need a vertex shader to run all your translations etc, that pretty bog standard stuff so I won't include one here */

float4 PixelShader(float2 texCoord : TEXCOORD0) : COLOR0
{
  //standard directional lighting equation with normals
  float3 Normal = tex2D(normalSampler, texCoord);
  float dot = dot(LightDirection, Normal);
  return tex2D(normalSampler, texCoord) * dot;
}
+3
source

, . , , , N.L (L) (N) . , .

, . . , L N.L:)

, ... !: D

0

Source: https://habr.com/ru/post/1725765/


All Articles