Sign in to follow this  

effect pool

This topic is 3293 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I read over how to do in the pplication and it seems right, but don't I have to change the HLSL too? What do I write there? I can't seem to find the details on MSDN.
//--------------------------------------------------------------------------------------
// File: EffectPool.fx
//
// Contains shared effect variables and functions that remain the same every frame
// for all effects.
//--------------------------------------------------------------------------------------

shared cbuffer Matrices
{
   matrix view          : View;
   matrix projection    : Projection;
};

shared cbuffer Lights
{
   struct AmbientLight
   {
      float4 intensity;
      float4 color;
   };
   
   struct DirectionalLight
   {
      bool   enabled;
      float4 direction;
      float4 color;
   };
   
   AmbientLight     ambientLight;
   DirectionalLight directionalLights[8];
};

//--------------------------------------------------------------------------------------
// File: default.fx
//
//--------------------------------------------------------------------------------------

matrix World : World;

Texture2D textureDiffuse;

SamplerState samplerLinear
{
   Filter = MIN_MAG_MIP_LINEAR;
   AddressU = Wrap;
   AddressV = Wrap;
};


//////// CONNECTOR DATA STRUCTURES ///////////

/* Data from application vertex buffer */
struct VS_INPUT
{
   float3 position : POSITION;
   float3 normal	 : NORMAL;
   float2 uv		 : TEXCOORD0;
   
};

/* Data passed from vertex shader to pixel shader */
struct PS_INPUT
{
   float4 position : SV_POSITION;
   float3 normal   : NORMAL;
   float2 uv       : TEXCOORD0;
};


//--------------------------------------------------------------------------------------
// Vertex Shader
//--------------------------------------------------------------------------------------

//--------------------------------------------------------------------------------------
// Simply transforms positions and normals
// 
PS_INPUT VS( VS_INPUT input )
{
   PS_INPUT output = (PS_INPUT)0;
   
   // Transform the position
   matrix worldViewProjection = mul(world, view);
   worldViewProjection = mul(worldViewProjection, projection);
   
   output.position = mul(input.position, worldViewProjection );
   
   // Transform the normal
   output.normal = mul(input.normal, world);
   normalize(output.normal);
   
   // Copy the UV 
   output.uv = input.uv;
   
   return output;
}


//--------------------------------------------------------------------------------------
// Pixel Shaders
//--------------------------------------------------------------------------------------

//--------------------------------------------------------------------------------------
// Shades an object using 2 colored directional lights
//
float4 PS( PS_INPUT input ) : SV_Target
{  
   finalColor = textureDiffuse.Sample(samplerLinear, input.uv);
   finalColor.a = 1;
   
   return finalColor;
}

//--------------------------------------------------------------------------------------
// Techniques
//--------------------------------------------------------------------------------------

//--------------------------------------------------------------------------------------
// Renders an object using 2 directional lights
//
technique10 Render
{
    pass P0
    {
        SetVertexShader( CompileShader( vs_4_0, VS() ) );
        SetGeometryShader( NULL );
        SetPixelShader( CompileShader( ps_4_0, PS() ) );
    }
}



Share this post


Link to post
Share on other sites
As far as I remember you don't need to change the HLSL. Effect pools are merely hints to the runtime/compiler to share a ID3D10EffectConstantBuffer between instances of an ID3D10Effect. The actual functioning of the effect doesn't change - just the runtime behaviour optimization...

Is something specific not working?


hth
Jack

Share this post


Link to post
Share on other sites
to use hlsl and effect pools you need to put shared before your shared variables. also i found that the first shader created with the effect pool is that one that decides what are shared variables or not.

so:

float4x4 world;
shared float4x4 view;
shared float4x4 projection;

then you compile the next shader

float4x4 world;
shared float4x4 view;
shared float4x4 projection;

shader ()
{
pos = mul(inpos, (mul(world, mul(view, projection)));
}

Share this post


Link to post
Share on other sites

This topic is 3293 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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