Results 1 to 8 of 8

Thread: Proper way to set texture parameters in <profile_COMMON&g

  1. #1
    Senior Member
    Join Date
    Jan 2006
    Location
    Foster City, CA
    Posts
    540

    Proper way to set texture parameters in <profile_COMMON&g

    I'm trying to figure out how to specify texture parameters such as the wrap mode, min/mag filter, etc, to a texture that's used in a fixed-function material, such as <phong>. It looks like I want to use the <sampler2D> element for that, but I can't find any examples. When I export a textured model from Max it just hooks up the <diffuse> element directly to a <texture> element (via <bind_material>) and doesn't use a sampler.

    In the spec I found this example in the <profile_COMMON> documentation:

    Code :
    <profile_COMMON> 
       <newparam sid="myDiffuseColor"> 
          <float3> 0.2 0.56 0.35 </float3> 
        </newparam> 
        <technique sid="phong1"> 
          <phong> 
            <emission><color>1.0 0.0 0.0 1.0</color></emission> 
            <ambient><color>1.0 0.0 0.0 1.0</color></ambient> 
            <diffuse><param>myDiffuseColor</param></diffuse> 
            <specular><color>1.0 0.0 0.0 1.0</color></specular> 
            <shininess><float>50.0</float></shininess> 
            <reflective><color>1.0 1.0 1.0 1.0</color></reflective> 
            <reflectivity><float>0.5</float></reflectivity> 
            <transparent><color>0.0 0.0 1.0 1.0</color></transparent> 
            <transparency><float>1.0</float></transparency> 
          </phong> 
        </technique> 
    </profile_COMMON>
    Note the <newparam> and <param> usage. So would I do something similar, except inside the <newparam> put a <sampler2D> instead of a <float3>? Also I think the example above is using <param> wrong; in the schema it says that <param> needs a "ref" attribute, and I'm not sure that it's allowed to have content. So would it be <param ref="myDiffuseColor"/> instead? Should the <newparam> element definitely be a child of <profile_COMMON> and not of <technique>? In <sampler*>, what exactly does the <source> element refer to? An <image>?

    Also some more minor errors in the spec:
    <sampler*> isn't listed as a valid parent element of <source>, and material elements such as <diffuse>, <ambient>, etc aren't listed as valid parent elements of <param>.

    Thanks for any help.

  2. #2
    Senior Member
    Join Date
    Aug 2005
    Location
    California
    Posts
    165
    Hey Steven,
    Yeah the textureing is a little confusing and there may be no good samples especially because the DCC tools haven't exported this correctly till jsut recently. I believe the Maya exporter 2.03 which was jsut released late last week does this correctly.. or at least it imports it correctly. I haven't looked at the exports.

    So, you are half right. You do want to use a <sampler2D> but you need to use a <texture> element as a child of <diffuse>, <emission>, etc.

    Heres a quick sample.

    <profile_COMMON>
    <newparam sid="surface">
    <surface type="2D">
    <init_from>IDREF_to_some_image</init_from>
    </surface>
    </newparam>
    <newparam sid="sampler">
    <sampler2D>
    <source>sampler</source>
    <wrap_s>WRAP</wrap_s>
    ...
    </sampler>
    </newparam>
    <technique sid="t1">
    <phong>
    <diffuse>
    <texture texture="sampler" texcoord="UVSET0"/>
    </diffuse>
    </phong>
    </technique>
    </profile_COMMON>

    hope that makes sense for you. Now comes the other part that gets messed up often: Linking the texture to the geometry. It has to do with the texcoord attribute. UVSET0 isn't special, its just a common symbol I've seen around so I'm using it for the example.
    <geometry id="GEO_1">
    ...
    <triangles material="BLAH">
    ...
    <input semantic="TEXCOORD" set="0" offset="2" source="#texcoords"/>
    </triangles>
    <geometry>
    ...
    <node>
    <instance_geometry url="GEO_1">
    <bind_material>
    <technique_common>
    <instance_material symbol="BLAH" target="#mat_using_effect_w_tex">
    <bind_vertex_input semantic="UVSET0" input_semantic="TEXCOORD" input_set="0"/>
    </instance_material>
    </technique_common>
    </bind_material>
    </instance_geometry>
    </node>

    phew! That was probably more info that you needed but it paints the whole picture. Hopefully seeing the xml you can figure out whats going on without much of a problem. If you don't get something just reply back and I can clarify later.

    and the miscelanous stuff... Yes that example is wrong. A param needs a ref attribute, not the ref being the value. Its wrong even more because you need to use the texture element. param is used to reference a color, one that you may want to animate. If you don't want to animate or allow people to set it in the material or instance_material you can just specify the color with the <color> element.

    The newparam element can belong as a child in many places. Its a scoping issue. If defined as a child of <technique> it can only be used as a parameter in that technique. If its a child of the <profile_*> it can be shared by the techniques. If it is a child of the <effect> it can be shared by multiple profiles.

    And finally, <source> doesn't have <sampler_*> as a parent because they are widly different <source> elements. If there is a <source> section in the FX chapter and thats what you are refering to then Yes it is a bug. And the spec bug, yeah thats a bug. Theres a public bugzilla on khronos you can submit a bug report about that.

    -Andy

  3. #3
    Senior Member
    Join Date
    Jan 2006
    Location
    Foster City, CA
    Posts
    540
    Thanks Andy, that makes everything very clear. The only thing that threw me off was the "<source>sampler</source>" inside the <sampler2D>, but I figure you meant "<source>surface</source>".

    It looks like I was writing the <texture> elements and binding texture coordinates incorrectly. I took the output from the Max exporter as an example of how I should do things, but they use an older style that, after looking at your example, I'm not sure is conformant to Collada 1.4. When I changed their output to the texturing style that you have they read it perfectly though, so I guess it's only a matter of time before they change their exporter to output the data in the style you describe.

    When elements are loosely bound by name the spec sometimes isn't perfectly clear about what types of elements you should be binding to. A good example is the <source> element in <sampler*>. Neither the spec nor the schema say anything about what's supposed to be in there, just that it's an NCName. I'll try to bug this in the Khronos bugzilla you mentioned.

    Quote Originally Posted by alorino
    And finally, <source> doesn't have <sampler_*> as a parent because they are widly different <source> elements.
    Heh good point. In the spec there's a direct link to the geometry <source> element though, which as you say is a different <source> element. I'll bug it.

    Thanks a ton for the help.

  4. #4
    Senior Member
    Join Date
    Jan 2006
    Location
    Foster City, CA
    Posts
    540
    Bugs 5, 6, and 7 submitted to the Khronos bugzilla.

  5. #5
    Junior Member
    Join Date
    Apr 2006
    Posts
    27
    I also found no way to add the <source>value</source> element properly.

    Wouldn't it be a good idea a generic SetValue() funtion for all elements as we have the SetAttribute() function ? It would let us solve problems by hand.

  6. #6
    Senior Member
    Join Date
    Jan 2006
    Location
    Foster City, CA
    Posts
    540
    Quote Originally Posted by jairbubbles
    I also found no way to add the <source>value</source> element properly.
    I haven't fixed up my code to use surfaces and samplers yet so I still haven't bumped into that one.

    For anyone else that was also having problems getting texturing set up, at the end of the Collada release notes for 1.4.1 is an excellent example (very similar to alorino's) that shows how to do this. It'd be very helpful if that example was copied into the spec.

  7. #7
    Senior Member
    Join Date
    Aug 2005
    Location
    California
    Posts
    165
    Quote Originally Posted by jairbubbles
    I also found no way to add the <source>value</source> element properly.

    Wouldn't it be a good idea a generic SetValue() funtion for all elements as we have the SetAttribute() function ? It would let us solve problems by hand.
    If you have the source element (type domFx_sampler2D_common_complexType::domSource ) there is a setValue function.

    But a general setValue function would be useful. I'll look into that.

    -Andy

  8. #8
    Senior Member
    Join Date
    Aug 2004
    Location
    California
    Posts
    771
    Quote Originally Posted by sthomas
    For anyone else that was also having problems getting texturing set up, at the end of the Collada release notes for 1.4.1 is an excellent example (very similar to alorino's) that shows how to do this. It'd be very helpful if that example was copied into the spec.
    It'll be in the 1.4.2 specification.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •