Matcap Rim Lighting for 3ds max viewport shading.
Ver.0.5
Ver.0.85
This shader support for 3dsmax direcX driver and opengl view port with Nitro view port driver DX9 only.
//////////////////////////--Based Shader--/////////////////////////////
// Shader by Charles Hollemeersch http://charles.hollemeersch.net ///
// Edited: 12/13/2009 - Leonardo Covarrubias - For use in Maya  ///
// Public domain.             ///
///////////////////////////////////////////////////////////////////////
//////////////////////////--AddOn Shader--/////////////////////////////
// Shader by JP.Lee  http://leegoonz.blogspot.com ////////////////////
// Edited: 03/05/2014 - Lee JungPyo - For use in 3D studio max  ///
//  Thanks Charles Hollemeersch with Leonardo Covarrubias   ///
//////////////////////////--Customized Author by Leegoonz--////////////
string ParamID = "0x003";
////////////////////////
// Matrices
////////////////////////
float4x4 WorldView            : WORLDVIEW;
float4x4 WorldViewProjection  : WORLDVIEWPROJ;
////////////////////////
// User interface
////////////////////////
float BumpHeight <
 string UIName = "Bumpmap Strength";
 string UIWidget = "slider";
 float UIMin = 0.1;
 float UIMax = 3.0;
 float UIStep = 0.01;
> = 1.0;
float Alpha <
 string UIName = "Global Opacity";
 string UIWidget = "slider";
 float UIMin = 0.0;
 float UIMax = 1.0;
 float UIStep = 0.01;
> = 1.0;
bool flipGreen
<
    string UIName = "Invert Normal Map Green Channel?";
> = false;
texture diffuseMap : Diffuse <
 string UIName = "Diffuse Map";
 string ResourceName = "";
 string ResourceType = "2D";
>;
texture normalMap : Normal <
 string UIName = "Normal Map";
 string ResourceName = "";
 string ResourceType = "2D";
>;
texture litSphereMap : LitSphere <
 string UIName = "LitSphere Map";
 string ResourceName = "./matball01.jpg";
 string ResourceType = "2D";
>;
texture litSphereRim : LitSphere <
 string UIName = "Rim Map";
 string ResourceName = "./matball01.jpg";
 string ResourceType = "2D";
>;
float matCapStrengthUI<
 string UIName = "LightCap Power";
 string UIWidget = "slider";
 float UIMin = 0.1;
 float UIMax = 5.0;
 float UIStep = 0.01;
> = 1.0;
float LightCapRimStrengthUI<
 string UIName = "Rim Power";
 string UIWidget = "slider";
 float UIMin = 0.1;
 float UIMax = 3.0;
 float UIStep = 0.01;
> = 1.0;
float4 RimColor : COLOR <
 string UIName = "Rim Color";
 string UIWidget = "none";
> = { 0.5f, 0.5f, 0.5f , 1.0f};
float contrastMatRimPower<
 string UIName = "LightCap Contrast";
 string UIWidget = "slider";
 float UIMin = -3.0;
 float UIMax = 3.0;
 float UIStep = 0.01;
> = 0.25;
////////////////////////
// Samplers
////////////////////////
sampler DiffuseSampler = sampler_state {
 Texture = ;
 MIPFILTER = LINEAR;
 MINFILTER = LINEAR;
 MAGFILTER = LINEAR;
 AddressU = WRAP;
 AddressV = WRAP;
 SRGBTexture = FALSE;
};
sampler NormalSampler = sampler_state {
 Texture = ;
    MIPFILTER = LINEAR;
    MINFILTER = LINEAR;
    MAGFILTER = LINEAR;
    AddressU  = WRAP;  
    AddressV  = WRAP; 
 
};
sampler LightSampler = sampler_state {
 Texture = ;
    MIPFILTER = LINEAR;
    MINFILTER = LINEAR;
    MAGFILTER = LINEAR;
    AddressU  = CLAMP;  
    AddressV  = CLAMP;
 //SRGBTexture = FALSE;
};
sampler LitSphereRimSampler = sampler_state {
 Texture = ;
 MIPFILTER = LINEAR;
 MINFILTER = LINEAR;
 MAGFILTER = LINEAR;
 AddressU = CLAMP;
 AddressV = CLAMP;
};
////////////////////////
// Exchange structs
////////////////////////
struct a2v 
{
 float4 Position : POSITION; 
 float2 TexCoord : TEXCOORD0;
 float3 Tangent  : TANGENT;
 float3 Binormal : BINORMAL;
 float3 Normal   : NORMAL;
};
struct v2f 
{
 float4 Position : POSITION;
 float2 TexCoord : TEXCOORD0;
 float3 TexCoord1 : TEXCOORD1;
 float3 TexCoord2 : TEXCOORD2;
 float3 TexCoord3 : TEXCOORD3;
};
////////////////////////
// Vertex shader
////////////////////////
v2f BumpReflectVS(a2v IN)
{
 v2f OUT;
 // Pos to NDC
 OUT.Position = mul(float4(IN.Position.xyz,1), WorldViewProjection);
 
 // Texcoords (for normal map)
 OUT.TexCoord.xy = IN.TexCoord;
 
 // Tangent space vectors
 float3 vtan = IN.Tangent;
 float3 vbinorm = IN.Binormal;
 float3 vnorm = IN.Normal;
 OUT.TexCoord1.xyz = mul(vtan,WorldView);
 OUT.TexCoord2.xyz = mul(vbinorm,WorldView);
 OUT.TexCoord3.xyz = mul(vnorm,WorldView);
 
 return OUT;
}
////////////////////////
// Pixel shader
////////////////////////
float4 BumpReflectPS(v2f IN) : COLOR {
 float4 outColor;
 //float4 diffuseTex = tex2D(DiffuseSampler, IN.TexCoord.xy);
 //float4 diffuseTex = pow(tex2D(DiffuseSampler, IN.TexCoord.xy), 2.2);
 float4 diffuseTex = tex2D(DiffuseSampler, IN.TexCoord.xy);
 //diffuseTex = diffuseTex * diffuseTex;    
diffuseTex = pow(diffuseTex , 2.2); 
Input gamma correction formula ::
pow(x , 2.2) = X ^ 2.2
X ^ 2.2 를 풀어 쓰면

이걸 데카르트 좌표계로 보면.
return gamma correction formula ::
pow(x , 1/2.2) = X ^ 0.45454545
 
  
 Game Developer Leegoon copyright all right reserved since 2010.





감마 보정 추가.
ReplyDelete멧켑 텍스처 병합 콘트라스트 변수 추가.
ReplyDeleteLightCap contrast formula change.
ReplyDeleteRemove gamma correction for matcap.