Sign in to follow this  
Azzazelus_13

HLSL beginer..

Recommended Posts

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
//////////////////////////////////////////////////////////////

//Application to vertex shader
struct A2V
{ 
    float4 position : POSITION0;
    float3 normal   : NORMAL0;
    float2 texCoord : TEXCOORD0;
};

//Vertex shader to pixel shader
struct V2P
{
    float4 position : POSITION0;
    float2 texCoord : TEXCOORD0;
    float3 color    : TEXCOORD1;
};

//////////////////////////////////////////////////////////////
//Vertex Shader
//////////////////////////////////////////////////////////////
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;
}

//////////////////////////////////////////////////////////////
//Pixel Shader
//////////////////////////////////////////////////////////////
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
    {
        vertexshader = compile vs_2_0 VS();
        pixelshader = compile ps_2_0 PS();
    }



}

//I enabled only this techniques
technique PostProcess
{

    pass p0
    {
        vertexshader = compile vs_2_0 VS();
        pixelshader = compile ps_2_0 PS();
    }
    pass p1
    {
        VertexShader = compile vs_2_0 VS();
        PixelShader = compile ps_2_0 MyShader();
    }



}



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



DiffuseEffect->Begin(&Passes, 0);


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

{
 	DiffuseEffect->BeginPass(Pass);
	object_mesh[i]->RenderMesh();
 	DiffuseEffect->EndPass();
}
 
DiffuseEffect->End();
}

Share this post


Link to post
Share on other sites
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 this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this