// 3ds max effect file // // Cel Outline Effect // Fred Moreau // www.fredmoreau.net // Special Thanks to Neil Hazzard! // // Original Code from the Glow Effect Delivered with 3dsmax 6 // updated to support 3ds max autoui. // // Copyright (c) Microsoft Corporation. All rights reserved. // //string XFile = "tiger.x"; // model //string BIMG = "lake.bmp"; // Background image //int BCLR = 0xff202080; // background // texture texture Tex0 < string name = "seafloor.dds"; string UIName = "Base Texture"; bool mapCh = 1;>; // transforms float4x3 WorldView : WORLDVIEW; float4x4 Projection : PROJECTION; // light direction (view space) float3 LightDir : Direction < string UIName = "Light Direction"; string Object = "TargetLight";> = normalize(float3(0.0f, 0.0f, 1.0f)); // Outline parameters float4 DiffuseColor < string UIName = "Diffuse Color"; string UIType = "MaxSwatch"; > = float4(1.0f, 1.0f, 1.0f, 1.0f); float4 OutlineColor < string UIName = "Outline Color"; string UIType = "MaxSwatch"; > = float4(0.0f, 0.0f, 0.2f, 1.0f); float OutlineThickness< string UIName = "Outline Thickness"; string UIType = "MaxSpinner"; float UIMin = 0.0f; float UIMax = 10.0f; > = 0.1f; // output structure for VSTexture VertexShader struct VSTEXTURE_OUTPUT { float4 Position : POSITION; float4 Diffuse : COLOR; float2 TexCoord : TEXCOORD0; }; // draws unskinned object with one texture and one directional light. VSTEXTURE_OUTPUT VSTexture ( float4 Position : POSITION, float3 Normal : NORMAL, float2 TexCoord : TEXCOORD0 ) { VSTEXTURE_OUTPUT Out = (VSTEXTURE_OUTPUT)0; float3 L = -LightDir; // light direction (view space) float3 P = mul(Position, WorldView); // position (view space) float3 N = normalize(mul(Normal, (float3x3)WorldView)); // normal (view space) Out.Position = mul(float4(P, 1), Projection); // projected position Out.Diffuse = max(0, dot(N, L)*DiffuseColor); // diffuse Out.TexCoord = TexCoord; // texture coordinates return Out; } // output structure for VSOutLine VertexShader struct VSOutLine_OUTPUT { float4 Position : POSITION; float4 Diffuse : COLOR; }; // draws an inversed normal hull of the unskinned object. VSOutLine_OUTPUT VSOutLine ( float4 Position : POSITION, float3 Normal : NORMAL ) { VSOutLine_OUTPUT Out = (VSOutLine_OUTPUT)0; float3 N = normalize(mul(Normal, (float3x3)WorldView)); // normal (view space) float3 P = mul(Position, WorldView) + OutlineThickness * N; // displaced position (view space) Out.Position = mul(float4(P, 1), Projection); // projected position Out.Diffuse = OutlineColor; return Out; } technique TOutlineAndTexture { pass PTexture { // single texture/one directional light shader VertexShader = compile vs_1_1 VSTexture(); PixelShader = NULL; // texture Texture[0] = (Tex0); // sampler states MinFilter[0] = LINEAR; MagFilter[0] = LINEAR; MipFilter[0] = POINT; // set up texture stage states for single texture modulated by diffuse ColorOp[0] = MODULATE; ColorArg1[0] = TEXTURE; ColorArg2[0] = CURRENT; AlphaOp[0] = DISABLE; ColorOp[1] = DISABLE; AlphaOp[1] = DISABLE; //CullMode = CW; } pass POutLine { // Outline shader VertexShader = compile vs_1_1 VSOutLine(); PixelShader = NULL; // no texture Texture[0] = NULL; // enable alpha blending //AlphaBlendEnable = FALSE; //SrcBlend = ONE; //DestBlend = ONE; // set up texture stage states to use the diffuse color ColorOp[0] = SELECTARG2; ColorArg2[0] = DIFFUSE; AlphaOp[0] = SELECTARG2; AlphaArg2[0] = DIFFUSE; ColorOp[1] = DISABLE; AlphaOp[1] = DISABLE; // flip normals for outline mesh CullMode = CCW; } } technique TOutlineNoTexture { pass PDiffuse { // single texture/one directional light shader VertexShader = compile vs_1_1 VSTexture(); PixelShader = NULL; // texture Texture[0] = NULL; // set up texture stage states for single texture modulated by diffuse ColorOp[0] = SELECTARG2; ColorArg1[0] = DIFFUSE; ColorArg2[0] = CURRENT; AlphaOp[0] = DISABLE; ColorOp[1] = DISABLE; AlphaOp[1] = DISABLE; //CullMode = CW; } pass POutLine { // Outline shader VertexShader = compile vs_1_1 VSOutLine(); PixelShader = NULL; // no texture Texture[0] = NULL; // enable alpha blending //AlphaBlendEnable = FALSE; //SrcBlend = ONE; //DestBlend = ONE; // set up texture stage states to use the diffuse color ColorOp[0] = SELECTARG2; ColorArg2[0] = DIFFUSE; AlphaOp[0] = SELECTARG2; AlphaArg2[0] = DIFFUSE; ColorOp[1] = DISABLE; AlphaOp[1] = DISABLE; // flip normals for outline mesh CullMode = CCW; } }