////////////////////////////////////////////////// ////////////////////////////////////////////// // // ////////////////////////////////////////////////// //////////////////////////////////////////// // parameter declaration // Normal map file name // # define NORMALMAP__FILENAME "brilliantTops2.png" // # define NORMALMAP__FILENAME "circles.png" // # define NORMALMAP__FILENAME "roundedSquares.png" #define NORMALMAP__FILENAME "hexagons.png" // # define NORMALMAP__FILENAME "PCCP.png" // Amount to reflect. The higher the value, the brighter float ReflectionIntensity = 1.0; float NormalMapLoopNum = 48; // Number of iterations. The larger the pattern, the finer the pattern float NormalMapHeightScale = 1.0; // Height correction. Positive and higher, flat at 0 (about -4 to 4) // Reflection sharpness (0.7 to 0.98) float Smoothness = 0.80; // Refractive index (about 1.3-2.5) float IoR = 2.0; // Do you want to darken the part that is not illuminated by light? (0: bright, 1: dark) float TintRate = 0.5; // additional sphere map // For models that do not originally have a sphere map. Comment out with // if not needed. // # define SPHERE_FILENAME "dummySphere.png" // Strength of additional sphere map float SpehreIntensity = 0.5; // enhance the color of the secondary reflection // secondary reflections even in dark colors #define ENABLE_COLOR_EMPHASIZE 1 ////////////////////////////////////////////////// ////////////////////////////////////////////// // parameter declaration // constellation transformation matrix float4x4 WorldViewProjMatrix: WORLDVIEWPROJECTION; float4x4 WorldMatrix: WORLD; float4x4 ViewMatrix: VIEW; float4x4 LightWorldViewProjMatrix: WORLDVIEWPROJECTION ; float3 LightDirection: DIRECTION ; float3 CameraPosition: POSITION ; // Material color float4 MaterialDiffuse: DIFFUSE ; float3 MaterialAmbient: AMBIENT ; float3 MaterialEmmisive: EMISSIVE ; float3 MaterialSpecular: SPECULAR ; float SpecularPower: SPECULARPOWER ; float3 MaterialToon: TOONCOLOR; float4 EdgeColor: EDGECOLOR; float4 GroundShadowColor: GROUNDSHADOWCOLOR; // light color float3 LightDiffuse: DIFFUSE ; float3 LightAmbient: AMBIENT ; float3 LightSpecular: SPECULAR ; static float4 DiffuseColor = MaterialDiffuse * float4 (LightDiffuse, 1.0f); static float3 AmbientColor = MaterialAmbient * LightAmbient + MaterialEmmisive; static float3 SpecularColor = MaterialSpecular * LightSpecular; // Texture material morph value float4 TextureAddValue: ADDINGTEXTURE; float4 TextureMulValue: MULTIPLYINGTEXTURE; float4 SphereAddValue: ADDINGSPHERETEXTURE; float4 SphereMulValue: MULTIPLYINGSPHERETEXTURE; bool use_texture; // texture flag bool use_spheremap; // sphere flag bool use_toon; // toon flag bool use_subtexture; // subtexture flag bool parthf; // perspective flag bool transp; // semi-transparent flag bool spadd; // Sphere map addition synthesis flag #define SKII1 1500 #define SKII2 8000 #define Toon 3 // object texture texture ObjectTexture: MATERIALTEXTURE; sampler ObjTexSampler = sampler_state {     texture = ;     MINFILTER = LINEAR;     MAGFILTER = LINEAR;     MIPFILTER = LINEAR;     ADDRESSU = WRAP;     ADDRESSV = WRAP; }; // Sphere map texture texture ObjectSphereMap: MATERIALSPHEREMAP; sampler ObjSphareSampler = sampler_state {     texture = ;     MINFILTER = LINEAR;     MAGFILTER = LINEAR;     MIPFILTER = LINEAR;     ADDRESSU = WRAP;     ADDRESSV = WRAP; }; // Shadow buffer sampler. "register (s0)" is because MMD uses s0 sampler DefSampler: register (s0); ////////////////////////////////////////////////// //////////////////////////////////////////// static float F0 = saturate (pow ((IoR-1.0) / (IoR + 1.0), 2.0)) + 0.001; static float Roughness0 = saturate ((1-Smoothness) * (1-Smoothness)) * 0.98 + 0.01; static float Roughness = Roughness0 * Roughness0; static float WaveLengthRate = saturate (IoR-1.0) / 40.0; #if defined (SPHERE_FILENAME) texture2D DummySphereMap <     string ResourceName = SPHERE_FILENAME; >; sampler DummySphereMapSamp = sampler_state {     texture = ; FILTER = LINEAR; AddressU = CLAMP; AddressV = CLAMP; }; #endif // Main normal map #define ANISO_NUM 16 texture2D NormalMap <     string ResourceName = NORMALMAP__FILENAME; >; sampler NormalMapSamp = sampler_state {     texture = ; FILTER = LINEAR; AddressU = WRAP; AddressV = WRAP; }; #define PI (3.14159265359) // For metals, F0 has a different value for each rgb inline float CalcFresnel (float NV, float F0) { return F0 + (1.0-F0) * pow (1-NV, 5); } // Specular calculation inline float CalcSpecular (float3 L, float3 N, float3 V, float a) { float3 H = normalize (L + V); float NH = saturate (dot (N, H)); float NL = saturate (dot (N, L)); float LH = saturate (dot (L, H)); float CosSq = (NH * NH) * (a-1) + 1; float D = a / (CosSq * CosSq); float k2 = a * a * 0.25; // = (a * 0.5) ^ 2 float vis = (1.0 / 4.0) / (LH * LH * (1-k2) + k2); return max (NL * D * vis, 0); } float3x3 compute_tangent_frame (float3 Normal, float3 View, float2 UV) { float3 vRx = ddx (View