# HLSL beginer..

## Recommended Posts

Azzazelus_13    128
Hy. I just started using shaders. I found am .fx sample from internet wich makes a diffuse directional light. After using that tech. I started learning step by step making shaders. I made another effect that change the image (screen) color to brighter. Now the problem is how I combine them ? In separate files, in different tehniques or multiple passes ? DiffuseLight + Image postproccesing. For example DifusseLight and the resulting image should be brighter.
float4x4 worldViewProj;
float4x4 world;
texture modelTexture;
float3 LightDirection = {-1.707f, 0.707f, 0.707f};
float ambient = 0.1f;
float3 lightColor1;

float4 poz;

// Texture samler
//sampler2D g_samSrcColor;

sampler2D g_samSrcColor = sampler_state
{
Texture = (modelTexture);
MIPFILTER = LINEAR;
MAGFILTER = LINEAR;
MINFILTER = LINEAR;
};

sampler2D modelTextureSampler = sampler_state
{
Texture = (modelTexture);
MIPFILTER = LINEAR;
MAGFILTER = LINEAR;
MINFILTER = LINEAR;
};

float4 MyShader( float2 Tex : TEXCOORD0 ) : COLOR0
{

float4 Color;
Color = tex2D( g_samSrcColor, Tex.xy)*3;

return Color;
}

//////////////////////////////////////////////////////////////
//Structures
//////////////////////////////////////////////////////////////

struct A2V
{
float4 position : POSITION0;
float3 normal   : NORMAL0;
float2 texCoord : TEXCOORD0;
};

struct V2P
{
float4 position : POSITION0;
float2 texCoord : TEXCOORD0;
float3 color    : TEXCOORD1;
};

//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
void VS( in A2V IN, out V2P OUT)
{
OUT.position = mul(IN.position, worldViewProj);
IN.normal    = normalize(mul(IN.normal, world));
OUT.color    = max(dot(IN.normal, normalize(LightDirection)),0.0f) + ambient * lightColor1;
OUT.texCoord = IN.texCoord;
}

//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
float4 PS( in V2P IN) : COLOR
{
float4 TexColor = tex2D( modelTextureSampler, IN.texCoord );
return TexColor * float4(IN.color, 1.0f);
}

//////////////////////////////////////////////////////////////
//Techniques
//////////////////////////////////////////////////////////////

//this is curently OFF..
technique DiffuseDirectional
{
pass p0
{
}

}

//I enabled only this techniques
technique PostProcess
{

pass p0
{
}
pass p1
{
}

}



DiffuseEffect-&gt;SetTechnique("PostProcess");
DiffuseEffect-&gt;SetMatrix("worldViewProj", &(matWorld * View * matProj) );
DiffuseEffect-&gt;SetMatrix("world", &(matWorld) );

DiffuseEffect-&gt;Begin(&Passes, 0);

for (Pass = 0; Pass &lt; 2; Pass++) //two passes, light + postproc.

{
DiffuseEffect-&gt;BeginPass(Pass);
object_mesh[i]-&gt;RenderMesh();
DiffuseEffect-&gt;EndPass();
}

DiffuseEffect-&gt;End();
}



##### Share on other sites
thallish    202
Well as the two things you want to accomplish are different in terms of which area the affect, as in the rendering of the model and change in brightness of the screen I would split them up in two different techniques.

Whether or not they are in the same file is insignificant as far as I know, but it will probably be a good idea to have some structure in your effect files, so one file contains similar techniques or the multiple techniques used for a certain effect like HDR rendering.

##### Share on other sites
Azzazelus_13    128
So I must render the object like "two times" for 2 techniques, right ? Then fill the screen buffer.

##### Share on other sites
thallish    202
No. I would render all objects with the diffuse light effect to a buffer/texture. Then I would take this texture as variable in the brightness effect, change brightness, and then render this to the frame buffer, or another texture if you have more effects to apply.

Post processesing means that after you have rendered all relevant objects to a buffer, you apply certain effects on the resulting image. That is how I interpret it anyway[wink]

## Create an account

Register a new account