Skip to main content
gamedev.net
🔒 Locked 🎮 Unity

effect pool

Started by brekehan Dec 5, 2008 at 2:56 AM 1 replies 1.3k views
Original Post
brekehan
brekehan
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() ) );
    }
}



jollyjeffers
jollyjeffers
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
<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ |
FeverGames
FeverGames
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)));
}

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.