Search Home Members Contacts
About Us
Products
Downloads
Community
Support
Pages: [1]
  Print  
Author Topic: Merge effects  (Read 752 times)
Rbn_3D
Community Member
*
Posts: 112


WWW
« on: May 15, 2009, 09:04:21 AM »

Basically I want a shader whiht 2 effects:

1. Textured Phong

2. Reflection Map

I have shaders for phong and for RefMap, but I want to merge it in one only.

I don't have experience in this, please help.

These are the shaders:

Phong:

Code:
//**************************************************************//
//  Effect File exported by RenderMonkey 1.6
//
//  - Although many improvements were made to RenderMonkey FX 
//    file export, there are still situations that may cause   
//    compilation problems once the file is exported, such as 
//    occasional naming conflicts for methods, since FX format
//    does not support any notions of name spaces. You need to
//    try to create workspaces in such a way as to minimize   
//    potential naming conflicts on export.                   
//   
//  - Note that to minimize resulting name collisions in the FX
//    file, RenderMonkey will mangle names for passes, shaders 
//    and function names as necessary to reduce name conflicts.
//**************************************************************//

//--------------------------------------------------------------//
// Textured Phong
//--------------------------------------------------------------//
//--------------------------------------------------------------//
// Pass 0
//--------------------------------------------------------------//
string Textured_Phong_Pass_0_Model : ModelData = "..\\..\\..\\..\\..\\..\\AMD\\RenderMonkey 1.82\\Examples\\Media\\Models\\Sphere.3ds";

float3 fvLightPosition
<
   string UIName = "fvLightPosition";
   string UIWidget = "Numeric";
   bool UIVisible =  true;
   float UIMin = -100.00;
   float UIMax = 100.00;
> = float3( -100.00, 100.00, -100.00 );
float3 fvEyePosition
<
   string UIName = "fvEyePosition";
   string UIWidget = "Numeric";
   bool UIVisible =  false;
   float UIMin = -100.00;
   float UIMax = 100.00;
> = float3( 0.00, 0.00, -100.00 );
float4x4 matView : View;
float4x4 matViewProjection : ViewProjection;

struct VS_INPUT
{
   float4 Position : POSITION0;
   float2 Texcoord : TEXCOORD0;
   float3 Normal :   NORMAL0;
   
};

struct VS_OUTPUT
{
   float4 Position :        POSITION0;
   float2 Texcoord :        TEXCOORD0;
   float3 ViewDirection :   TEXCOORD1;
   float3 LightDirection :  TEXCOORD2;
   float3 Normal :          TEXCOORD3;
   
};

VS_OUTPUT Textured_Phong_Pass_0_Vertex_Shader_vs_main( VS_INPUT Input )
{
   VS_OUTPUT Output;

   Output.Position         = mul( Input.Position, matViewProjection );
   Output.Texcoord         = Input.Texcoord;
   
   float3 fvObjectPosition = mul( Input.Position, matView );
   
   Output.ViewDirection    = fvEyePosition - fvObjectPosition;
   Output.LightDirection   = fvLightPosition - fvObjectPosition;
   Output.Normal           = mul( Input.Normal, matView );
     
   return( Output );
   
}



float4 fvAmbient
<
   string UIName = "fvAmbient";
   string UIWidget = "Color";
   bool UIVisible =  true;
> = float4( 0.37, 0.37, 0.37, 1.00 );
float4 fvSpecular
<
   string UIName = "fvSpecular";
   string UIWidget = "Color";
   bool UIVisible =  true;
> = float4( 0.49, 0.49, 0.49, 1.00 );
float4 fvDiffuse
<
   string UIName = "fvDiffuse";
   string UIWidget = "Color";
   bool UIVisible =  true;
> = float4( 0.89, 0.89, 0.89, 1.00 );
float fSpecularPower
<
   string UIName = "fSpecularPower";
   string UIWidget = "Numeric";
   bool UIVisible =  true;
   float UIMin = 1.00;
   float UIMax = 100.00;
> = float( 25.00 );
texture base_Tex
<
   string ResourceName = "..\\Interior\\Terrazo.dds";
>;
sampler2D baseMap = sampler_state
{
   Texture = (base_Tex);
   ADDRESSU = WRAP;
   ADDRESSV = WRAP;
   MINFILTER = LINEAR;
   MAGFILTER = LINEAR;
   MIPFILTER = LINEAR;
};

struct PS_INPUT
{
   float2 Texcoord :        TEXCOORD0;
   float3 ViewDirection :   TEXCOORD1;
   float3 LightDirection:   TEXCOORD2;
   float3 Normal :          TEXCOORD3;
   
};

float4 Textured_Phong_Pass_0_Pixel_Shader_ps_main( PS_INPUT Input ) : COLOR0
{     
   float3 fvLightDirection = normalize( Input.LightDirection );
   float3 fvNormal         = normalize( Input.Normal );
   float  fNDotL           = dot( fvNormal, fvLightDirection );
   
   float3 fvReflection     = normalize( ( ( 2.0f * fvNormal ) * ( fNDotL ) ) - fvLightDirection );
   float3 fvViewDirection  = normalize( Input.ViewDirection );
   float  fRDotV           = max( 0.0f, dot( fvReflection, fvViewDirection ) );
   
   float4 fvBaseColor      = tex2D( baseMap, Input.Texcoord );
   
   float4 fvTotalAmbient   = fvAmbient * fvBaseColor;
   float4 fvTotalDiffuse   = fvDiffuse * fNDotL * fvBaseColor;
   float4 fvTotalSpecular  = fvSpecular * pow( fRDotV, fSpecularPower );
   
   return( saturate( fvTotalAmbient + fvTotalDiffuse + fvTotalSpecular ) );
     
}



//--------------------------------------------------------------//
// Technique Section for Textured Phong
//--------------------------------------------------------------//
technique Textured_Phong
{
   pass Pass_0
   {
      VertexShader = compile vs_2_0 Textured_Phong_Pass_0_Vertex_Shader_vs_main();
      PixelShader = compile ps_2_0 Textured_Phong_Pass_0_Pixel_Shader_ps_main();
   }

}



Reflection Map
Code:
// Global-Level Semantics

float4x4 matWorldViewProj : WORLDVIEWPROJECTION;
float4x4 matWorld : WORLD;
float3 viewPosition : VIEWPOSITION;

// Vertex Shader Input Structure
struct VS_INPUT 
{
float4 position : POSITION;   // Vertex position in object space
float3 normal : NORMAL;       // Vertex normal in object space
float2 texCoord : TEXCOORD0;   // Vertex texture coordinates
};
 
// Vertex Shader Output Structure
struct VS_OUTPUT
{
float4 position : POSITION;   // Pixel position in clip space
float2 texCoord : TEXCOORD0;  // Pixel texture coordinates
float3 normal : TEXCOORD1;    // Pixel normal vector
float4 Pos : TEXCOORD2;
};
#define PS_INPUT VS_OUTPUT   

float4 materialDiffuse : DIFFUSE;
float4 materialAmbient : AMBIENT;   
float4 materialEmissive : EMISSIVE;
float4 materialSpecular : SPECULAR;
float materialPower : SPECULARPOWER;
       
texture ReflectionMap : TEXTURE2;
sampler sampReflectionMap = sampler_state
{
Texture = (ReflectionMap);
};       
 
VS_OUTPUT VS_main(VS_INPUT IN)
{
VS_OUTPUT OUT;

float4 WPos;
OUT.Pos = IN.position;
OUT.position = mul(IN.position, matWorldViewProj);
WPos = mul(IN.position,matWorld);
OUT.texCoord = IN.texCoord;
OUT.normal = normalize(mul(IN.normal,(float3x3)matWorld));
return OUT;
}
float4 PS_main(PS_INPUT IN) : COLOR

    float4 PPos;
    float4 texPosProj;
    PPos = mul(IN.Pos,matWorldViewProj);
    texPosProj = (PPos + PPos.w) * 0.5;
texPosProj.y *= -1;
texPosProj /= texPosProj.w;
    return tex2Dbias(sampReflectionMap, texPosProj);
}

//--------------------------------------------------------------//
// Technique Section for Plastic
//--------------------------------------------------------------//
technique Universal_Main
{
   pass SinglePass
   {
      VertexShader = compile vs_1_1 VS_main();
      PixelShader = compile ps_2_0 PS_main();
   }
}





Thanks in advance
Logged

Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.3 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks