Model containing two meshes with different textures.

Jul 1, 2013 at 3:47 AM
I'm having some issues loading a model that has two meshes, where each mesh uses its own texture. My xaml for the model follows, the main issue is that the second texture contains transparency, and I get the error HighDef profile does not support alpha blending or ColorWriteChannels when using rendertarget format Single. I'm pretty sure I'm just not setting something up right, and idea where I have gone south?

Thank you for the help in advance!
<Model Source="{ContentReference RT_Tree01A_LOD1}" xmlns="http://schemas.microsoft.com/nine/2011/xaml" UseModelTextures="False">
  <Model.Meshes>
    <ModelMesh>
      <ModelMesh.Material>
        <MaterialGroup Texture="{ContentReference RTBark1A}">
          <DiffuseMaterialPart />
          <DirectionalLightMaterialPart />
        </MaterialGroup>
      </ModelMesh.Material>
    </ModelMesh>
    <ModelMesh>
      <ModelMesh.Material>
        <MaterialGroup Texture="{ContentReference RTBranch1A}" IsTransparent="true">
          <DiffuseMaterialPart />
          <DirectionalLightMaterialPart />
        </MaterialGroup>
        <!--<BasicMaterial Texture="{ContentReference RTBranch1A}" Alpha="0.5" />-->
      </ModelMesh.Material>
    </ModelMesh> 
  </Model.Meshes>
</Model>
Coordinator
Jul 1, 2013 at 4:23 AM
Have you enabled shadows? Might be caused by shadow maps given the error description.
From: vantubbe
Sent: ‎Monday‎, ‎July‎ ‎1‎, ‎2013 ‎11‎:‎47‎ ‎AM
To: [email removed]

From: vantubbe

I'm having some issues loading a model that has two meshes, where each mesh uses its own texture. My xaml for the model follows, the main issue is that the second texture contains transparency, and I get the error HighDef profile does not support alpha blending or ColorWriteChannels when using rendertarget format Single. I'm pretty sure I'm just not setting something up right, and idea where I have gone south?

Thank you for the help in advance!
<Model Source="{ContentReference RT_Tree01A_LOD1}" xmlns="http://schemas.microsoft.com/nine/2011/xaml" UseModelTextures="False">
  <Model.Meshes>
    <ModelMesh>
      <ModelMesh.Material>
        <MaterialGroup Texture="{ContentReference RTBark1A}">
          <DiffuseMaterialPart />
          <DirectionalLightMaterialPart />
        </MaterialGroup>
      </ModelMesh.Material>
    </ModelMesh>
    <ModelMesh>
      <ModelMesh.Material>
        <MaterialGroup Texture="{ContentReference RTBranch1A}" IsTransparent="true">
          <DiffuseMaterialPart />
          <DirectionalLightMaterialPart />
        </MaterialGroup>
        <!--<BasicMaterial Texture="{ContentReference RTBranch1A}" Alpha="0.5" />-->
      </ModelMesh.Material>
    </ModelMesh> 
  </Model.Meshes>
</Model>
Jul 1, 2013 at 6:23 AM
Edited Jul 1, 2013 at 2:25 PM
So I changed the code and I load the mesh's materials individually now. I basically load the model via new Nine.Graphics.Model(xnaModel) and then set each mesh in the instance to the appropriate material (loaded from xaml) shown below. I can get it to draw because I removed the IsTransparent, but textures are not mapping right for the trunk, and nothing is coming through for the leaves. Pictures below.

Is it not possible to cast shadows from an object that contains transparency? Are there any alternatives so that a tree can cast shadows? Even a simple alpha test for the depth buffer would be plenty good enough.

Thank you for the quick response!

Transparent (leaves) mesh material:
<MaterialGroup Texture="{ContentReference RTBranch1A}" TwoSided="True" xmlns="http://schemas.microsoft.com/nine/2011/xaml">
    <DiffuseMaterialPart />
</MaterialGroup>
Trunk Mesh Material:
<MaterialGroup Texture="{ContentReference RTBark1A}" xmlns="http://schemas.microsoft.com/nine/2011/xaml">
    <DiffuseMaterialPart />
    <NormalMapMaterialPart NormalMap ="{ContentReference RTBark1A_NRM}"/>
</MaterialGroup>
Image
Image
Image

Also, if you look at that last picture, your engine can really keep up with all the stuff I throw at it. It's really an awesome work! Framerate never stutters despite all the stuff on the screen and very little optimization on my end.
Jul 2, 2013 at 12:35 AM
Also, I tried turning off shadows, still got the same error when IsTransparent="True".
Jul 3, 2013 at 3:53 AM
Edited Jul 3, 2013 at 3:59 AM
Okay, finally figured it out. So few things to note.
  • For some reason the samplerstate was causing the leaves not to be drawn, and hence the black boxes.
  • I set the sampler state by having the bark model use BasicMaterial, and could set the samplerstate through that.
  • The leaves would then draw, but obviously still have all the black where the texture is transparent.
  • I added a alphaTestMaterialPart to the MaterialGroup of the leaves, and set the RefAlpha to 100, that clipped away the black regions, and looks good enough
  • Adding alphaTestMaterialPart unfortunatly removed shadow casting from the leaves
  • Setting the SamplerState to LinearWrap fixed the texture mapping issues on the tree trunks
So phew, after all that, only two questions.
  1. If I use a material group for the tree trunk mesh, how do I set the sampler state before the tree is drawn?
  2. Is there any way to have the post clipped leaves cast shadows? I remember doing this when I coded a deferred renderer, I think those leaves just need to be written to the depth map.
Thanks again for all the help so far!

Bark xaml
<BasicMaterial SamplerState="LinearWrap" Texture="{ContentReference RTBark1A}" xmlns="http://schemas.microsoft.com/nine/2011/xaml"  />
Leaves xaml
<MaterialGroup Texture="{ContentReference RTBranch1A}" xmlns="http://schemas.microsoft.com/nine/2011/xaml">
    <DiffuseMaterialPart />
    <ShadowMapMaterialPart />
    <AlphaTestMaterialPart ReferenceAlpha="100" />
</MaterialGroup>
Image