Home Technical Talk

Max - Shader - Bake it down?

polycounter lvl 12
Offline / Send Message
Ace-Angel polycounter lvl 12
Hey to all,

I was wondering if there is a way to create a shader (real-time) and bake it down to your UV's in a package like Max?

If yes, how viable is it, and how would I be able to avoid baking certain things like say the Lambert term or Specular? Or is that dependent on the shader itself?

Cheers!

Replies

  • CrazyButcher
    Options
    Offline / Send Message
    CrazyButcher polycounter lvl 18
    it's actually quite simple, inside the vertexshader the clipspace position are calculated (from 3d to a "cube" in the range -1,1). Now instead of doing the transformation using view and projectionmatrix, you simply set the positions from the UV coordinates (*2 -1) directly.

    And yes shader creates typically just a single color, so you would have to modify the fragment/pixel shader to output whatever you want.
  • Drew++
    Options
    Offline / Send Message
    Drew++ polycounter lvl 14
    here it is, just as CrazyButcher explained.
        float2 uv = In.texCoord;
        uv.y = -uv.y;
        
        Out.Position.xy = uv * 2.0 - 1.0;
        Out.Position.z = 0.0; 
        Out.Position.w = 1.0;
    

    I'm not sure how you would render the view to a image though.

    It also might need to be 1:1 ratio, or maybe not... Anyways, that's easily done by multiplying the output position Y by (screen width / screen height)
  • Ace-Angel
    Options
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    Nice! Once that is done, is there a specific setup I need to put in for the baking process itself is it a simple case of assign to mesh and bake on itself?

    Cheers CB!

    EDIT: Cheers Drew for the snippet :D
  • LoTekK
    Options
    Offline / Send Message
    LoTekK polycounter lvl 17
    you could use something like
    local oldWidth = gw.getWinSizeX();
    local oldHeight = gw.getWinSizeY();
    
    gw.setPos 0 0 newWidth newHeight;  //target texture size
    forceCompleteRedraw();
    img = gw.getViewportDib();
    img.filename = yourpath;
    save img;
    gw.setPos 0 0 oldWidth oldHeight;  //restore viewport
    forceCompleteRedraw();
    

    to grab the viewport, and then save that out to a bitmap (of specified size). If you're doing it this way, then you don't want to alter the aspect ratio to be square (since you're actually altering the aspect ratio of the viewport).

    One caveat of this method is there's no straightforward way to get any padding around islands and alpha'd portions, so you'd need to do that in Photoshop. One of the things I did at work for when any sort of alpha was needed was basically have a bit where the script would turn the viewport background black, and replace the shader with a pure white unlit material, and write that into the alpha channel before saving it out.

    Though I suppose you could also use the built in RTT.
  • Ace-Angel
    Options
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    Ah, that makes sense, totally went over my head.

    Cheers!
Sign In or Register to comment.