Need help creating a top level shader

SighmanSighman Posts: 55

Hi,
Does anyone know how to create a top level shader using the Carrara SDK? The cookbook only has samples of sub- shaders. Any help would be appreciated.

Comments

  • Eric WinemillerEric Winemiller Posts: 84
    edited December 1969

    I've built a bunch of them. There's quite a bit of depth there and a few techniques for not rebuilding everything that's already built in to Carrara. If what you want to do is something you can share, I can probably give some specific recommendations. You can also email me or PM me directly. Otherwise, here's the stuff you want to start poking around. I'd start with DoShade if it's not playing with the lighting.

    virtual boolean MCCOMAPI HasExplicitLightingModel (const LightingContext& lightingContext);
    virtual MCCOMErr MCCOMAPI ShadeAndLight2 (LightingDetail& result,const LightingContext& lightingContext,I3DShLightingModel* inDefaultLightingModel,TAbsorptionFunction* absorptionFunction);
    virtual MCCOMErr MCCOMAPI DoShade (ShadingOut& result,ShadingIn& shadingIn);
    virtual void MCCOMAPI CalculateDirectLighting(LightingDetail& result,const LightingContext& lightingContext);
    virtual void MCCOMAPI CalculateReflection(TMCColorRGB& reflectionColor,const LightingContext& lightingContext,const ShadingOut& shading);
    virtual void MCCOMAPI CalculateCaustics(TMCColorRGB& causticColor,const LightingContext& lightingContext,const ShadingOut& shading);
    virtual void MCCOMAPI CalculateIndirectLighting(TMCColorRGB& indirectDiffuseColor, real& ambientOcclusionFactor, const LightingContext& lightingContext,const ShadingOut& shading);
    virtual void MCCOMAPI CalculateTransparency(TMCColorRGB& resColor,real32& outAlpha,const LightingContext& lightingContext,const ShadingOut& shading);
    virtual void MCCOMAPI CalculateAlpha(LightingDetail& result,const LightingContext& lightingContext,const ShadingOut& shading,TAbsorptionFunction* absorptionFunction);
    virtual void MCCOMAPI CalculateSubsurfaceScattering(TMCColorRGB& subsurfaceColor,const TMCColorRGB& currentColor,const LightingContext& lightingContext,const ShadingOut& shading);

    Good luck,

  • SighmanSighman Posts: 55
    edited December 1969

    Eric,

    Thanks for offering to help.

    Actually, I am not building an actual shader for Carrara but rather a pseudo shader that will host shaders for another renderer. I don't know if you are familiar with Luxus for Carrara but it has a top level shader (Lux Surface) that I want to emulate. This pseudo shader will have two components, A Carrara multi-channel shader which will drive the Carrara renderer and my own shader tree that will drive my own renderer.

    My problem is how do you 'tell' Carrara that a shader should appear in the top level shader menu rather than the sub shader menu. From what I can tell a shader is not instantiated until it is selected from the shader menu. This means that the information to tell Carrara where to place the shader must be in the resource files. But where? In the .r file or the .rsr file?

    I looked at the COMP definition for the SimpleLightingModel sample and it has 'Lighting Models # 16' as it's sub family name. Does this have anything to do with where the menu item is placed? What does the '#16' mean if anything? I want my shader to appear at the same level as the 'hair shader'.

    Thanks again for your help...

  • Eric WinemillerEric Winemiller Posts: 84
    edited December 1969

    Sighman said:

    I looked at the COMP definition for the SimpleLightingModel sample and it has 'Lighting Models # 16' as it's sub family name. Does this have anything to do with where the menu item is placed? What does the '#16' mean if anything? I want my shader to appear at the same level as the 'hair shader'.

    You found it, but it's not really documented. You put the # at the end of your group name. Here's the ones I've figured out over time.

    1 Top levels (Multi channel, layers list, etc.)
    2 Projection Mapping
    4 Layers
    8 Single Channel
    16 Lighting models
    32 Terrain distributions
    64 Terrain Layer

    So for example I use these constants in my comps in Shader Ops 2

    #define SHADER_OPS_2_LIGHTING_MODEL_GROUP "Shader Ops 2 Lighting Models # 16"
    #define SHADER_OPS_2_TOP_MOST_GROUP "Shader Ops 2 # 1"

    resource 'COMP' (338) {
    kRID_ShaderFamilyID,
    'SPLM',
    "Shader Ops 2 Light Mangler",
    SHADER_OPS_2_LIGHTING_MODEL_GROUP,
    FIRSTVERSION,
    VERSIONSTRING,
    COPYRIGHT,
    kRDAPIVersion
    };

    resource 'COMP' (109)
    {
    kRID_ShaderFamilyID,
    'SOSN',
    "Space Mangler",
    SHADER_OPS_2_TOP_MOST_GROUP,
    FIRSTVERSION,
    VERSIONSTRING,
    COPYRIGHT,
    kRDAPIVersion
    };

    Similarly, in your pmaps, you say what things can show as a child using those same numbers. The MskI tag below says only show top most shaders in that sub shader.

    'sh00','comp',interpolate, "Mangle","{fmly shdr MskI 1 Subm 1 Sort 1 Mini 1 Drop 3 }",

    There's also a MskE tag that says exclude those types. It's a bit field so just add the numbers to include/exclude multiple groups.

    'Laye','cmp#',interpolate, "Source","{fmly shdr MskE 1087 Subm 1 Sort 1 Mini 1 Drop 3 }",

    Regards,

  • SighmanSighman Posts: 55
    edited December 1969

    Eric,

    That's great information. I will put it to the test this evening.

    Thanks Again

Sign In or Register to comment.