XNA Creators Club Online
Page 1 of 1 (5 items)
Sort Posts: Previous Next

Normal Map Sample - Exporting opaque data from 3ds max?

Last post 7/5/2008 9:12 PM by jwatte. 4 replies.
  • 7/4/2008 7:50 AM

    Normal Map Sample - Exporting opaque data from 3ds max?

    I'm checking out the normal mapping sample w/ the lizard but I'm running into an issue. It seems 3ds max (ver. 2008) won't export the file name and directory of the normal map, even though its been added to the material of the mesh I'm exporting. When comparing the the FBX file of my export to that of the lizard sample, I'm missing this line below:

    Property: "NormalMap", "Enum", "A+U",0, "NormalMap_norm.tga"

    It seems Max is not exporting this opaque data pointing to the normal map with my file. Has anyone been able to do so? I've attempted to use the Parameter editor in 3ds max w/ no luck. Was the lizard normal mapping sample exported from Maya or 3ds Max? Is a source file available to check out?

    Thanks!

  • 7/4/2008 5:56 PM In reply to

    Re: Normal Map Sample - Exporting opaque data from 3ds max?

    I can export all the maps I want from 3ds Max. However, it only works when using the DirectX Shader material, and the Direct3D Viewport Manager, and exporting using kW X-port to .X. Once you have a shader that works in both Max and your application (see KiloWatt Animation Library for an examples of such shaders), it's really nice, because you see the same result in Max as you'll see in your game.
    Jon Watte, Direct3D MVP
    Tweets, occasionally
    kW X-port 3ds Max .X exporter
    kW Animation source code
  • 7/4/2008 7:13 PM In reply to

    Re: Normal Map Sample - Exporting opaque data from 3ds max?

    I'd prefer to continue using FBX as well as understand how the sample was exported. I assume it wasn't done using a custom exporter. I"ll take a look at the kW X-port today.

    Thanks!

  • 7/5/2008 6:02 PM In reply to

    Re: Normal Map Sample - Exporting opaque data from 3ds max?

    Hey John,

    How would I go about exporting an object w/ a reference to its normal map using your .x exporter? The diffuse bump directx shader didn't seem to work. Is there more extensive documentation online as well?

    Thanks!

  • 7/5/2008 9:12 PM In reply to

    Re: Normal Map Sample - Exporting opaque data from 3ds max?

    There isn't really any good documentation. I would recommend using an effect such as model.fx which ships with the KiloWatt Animation Library. Apply the effect to the object, and then select the diffuse, normal and gloss maps in the effect settings. Once you export (using the 'Export Effect') checkbox, the effect will be included with the model when you import into XNA. Note that you have to set up the effect using Effect.Parameters[, as the BasicEffect can't do anything but a single diffuse map.

    Here's the code for "model.fx" which does per-pixel normal mapping, gloss mapping (where alpha == shininess, rgb == specular level) and diffuse mapping:

     
    // This is used by 3dsmax to load the correct parser 
    string ParamID = "0x003"
     
    float Script : STANDARDSGLOBAL < 
        string UIWidget = "none"
        string ScriptClass = "object"
        string ScriptOrder = "standard"
        string ScriptOutput = "color"
        string Script = "Technique=Default;"
    > = 0.8; // version # 
     
     
    // light direction (world space) 
    float3 LightDirection : Direction<   
        string UIName = "Light Position";  
        string Object = "DirectionalLight"
        string Space = "World"
        int refID = 0; 
    > = {-0.577, -0.577, 0.577}; 
     
    float4 LightColor : LightColor 
        int LightRef = 0; 
        string UIWidget = "None"
    > = float4(0.8f, 0.8f, 0.8f, 0.0f); 
     
    float4 LightAmbient : LightAmbient 
      int LightRef = 0; 
      string UIWidget = "None"
    > = float4(0.2f, 0.2f, 0.2f, 1.0f); 
     
    int SpecularPower < 
        string UIName = "Specular Power"
        string UIType = "IntSpinner"
        float UIMin = 0.0f; 
        float UIMax = 200.0f;    
    >  = 40; 
     
    bool FlipNormal < 
      string UIName = "Flip Normal G Channel"
    > = false
     
    texture DiffuseTexture : DiffuseMap<  
        string UIName = "Diffuse Map "
        int Texcoord = 0; 
        int MapChannel = 1; 
    >; 
     
    texture GlossTexture : SpecularMap<  
        string UIName = "Gloss Map"
        int Texcoord = 0; 
        int MapChannel = 1; 
    >; 
     
    texture NormalTexture : NormalMap<  
        string UIName = "Normal Map"
        int Texcoord = 0; 
        int MapChannel = 1; 
    >; 
     
    float FogDistance < 
      string UIName = "Fog Distance"
      float UIMin = 10; 
      float UIMax = 10000; 
    >; 
     
    float4 FogColor < 
      string UIName = "Fog Color"
      string UIType = "ColorSwatch"
    > = float4(0.7, 0.7, 0.7, 0); 
     
     
    float4x4 WorldViewProjection    : WORLDVIEWPROJECTION; 
    float4x4 World                  : WORLD; 
    float4x4 ViewInverse            : VIEWINVERSE; 
     
    sampler2D DiffuseSampler = 
    sampler_state { 
      Texture = <DiffuseTexture>; 
      MipFilter = LINEAR; 
      MinFilter = ANISOTROPIC; 
      MagFilter = LINEAR; 
      MaxAnisotropy = 8; 
      AddressU = WRAP; 
      AddressV = WRAP; 
    }; 
     
    sampler2D GlossSampler = 
    sampler_state { 
      Texture = <GlossTexture>; 
      MipFilter = LINEAR; 
      MinFilter = LINEAR; 
      MagFilter = LINEAR; 
      MaxAnisotropy = 2; 
    }; 
     
    sampler2D NormalSampler = 
    sampler_state { 
      Texture = <NormalTexture>; 
      MipFilter = LINEAR; 
      MinFilter = LINEAR; 
      MagFilter = LINEAR; 
      MaxAnisotropy = 2; 
    }; 
     
     
    struct VSIn 
        float4 Position     : POSITION; 
        float3 Normal       : NORMAL; 
        float3 Tangent      : TANGENT; 
        float3 BiNormal     : BINORMAL; 
        float2 UV0      : TEXCOORD0; 
    }; 
     
     
    struct VSOut 
        float4 Position       : POSITION; 
        float2 UV0            : TEXCOORD0; 
        float3 Normal         : TEXCOORD1; 
        float3 Tangent          : TEXCOORD2; 
        float3 BiNormal         : TEXCOORD3; 
        float3 ViewDirection  : TEXCOORD4; 
      float  Fog            : COLOR0; 
    }; 
     
     
    VSOut VS(VSIn data) 
      VSOut ret; 
     
      ret.Position = mul(data.Position, WorldViewProjection); 
      ret.UV0 = data.UV0; 
      ret.Normal = mul(normalize(data.Normal), (float3x3)World); 
      ret.Tangent = mul(normalize(data.Tangent), (float3x3)World); 
      ret.BiNormal = mul(normalize(data.BiNormal), (float3x3)World); 
      ret.ViewDirection = mul(data.Position, World) - ViewInverse[3].xyz; 
      ret.Fog = 1 - saturate(length(ret.ViewDirection) / FogDistance); 
     
      return ret; 
     
     
    struct PSIn 
        float4 UV0      : TEXCOORD0; 
        float3 Normal       : TEXCOORD1; 
        float3 Tangent      : TEXCOORD2; 
        float3 BiNormal     : TEXCOORD3; 
        float3 ViewDir      : TEXCOORD4; 
        float Fog     : COLOR0; 
    }; 
     
    struct PSOut 
        float4 Color        : COLOR; 
    }; 
     
    PSOut PS(PSIn data) 
      PSOut ret; 
     
      float4 normal = tex2D(NormalSampler, data.UV0) * 2 - 1; 
      float4 diffuse = tex2D(DiffuseSampler, data.UV0); 
      float4 gloss = tex2D(GlossSampler, data.UV0); 
     
      float3 LightDirN = normalize(LightDirection); 
     
      // Normal 
      float3 N = normalize(data.Normal * normal.b + data.Tangent * normal.g + data.BiNormal * normal.r); 
     
      // Diffuse term 
      float NdotL = saturate(dot(N, LightDirN)); 
     
      float3 vd = data.ViewDir; 
     
      // Reflected angle 
      float3 R = normalize(vd - 2 * dot(N, vd) * N); 
     
      float specularMult = pow(saturate(dot(R, LightDirN)), 2 * SpecularPower * gloss.w); 
     
      float4 temp = float4(gloss.xyz * LightColor.xyz * specularMult, 0) 
          + NdotL * diffuse * LightColor 
          + diffuse * LightAmbient; 
     
      ret.Color = lerp(FogColor, temp, data.Fog); 
     
      return ret; 
     
     
    technique Default 
        string script = "Pass=p0;"
    >  
        pass p0 < 
              string script = "Draw=Geometry;"
        > 
        {        
            AlphaBlendEnable    = FALSE; 
          ZEnable           = TRUE; 
          ZWriteEnable      = TRUE; 
          AlphaTestEnable   = FALSE; 
          CullMode          = CW; 
            VertexShader        = compile vs_2_0 VS(); 
            PixelShader         = compile ps_2_0 PS(); 
        } 

    Jon Watte, Direct3D MVP
    Tweets, occasionally
    kW X-port 3ds Max .X exporter
    kW Animation source code
Page 1 of 1 (5 items) Previous Next