Home Technical Talk

Vertex color BlendMasked cgfx maya shader

polycounter lvl 10
Offline / Send Message
choco polycounter lvl 10
Hey guys,
I've been working on my first cgfx shader to help previewing blended materials in Maya.
It is very similar to the one you can find in this tutorial (UDK) : http://eat3d.com/free/vertex_painting

Basically 2 texture inputs with their normal maps LERPed together with an inverted heightmap used as a blend mask to spice things up.
Vertex colors need to be RGBA. The alpha channel of the vertex colors is used to blend the textures together while the RGB channels can be used to either paint color variation on your meshes or bake AO,GI etc...

I've been building this mainly for CE3 usage since it pretty much has the same setup as the one you can find in the SDK.
Its still not finished yet considering that I'm planning to sync the results in maya with CE3 so that the results translate seamlessly.
On the other hand the UI for the shader isn't very organized yet but it should be very straight forward.


I'm also planning to add support for the following features :
- Detail Normal maps (added in v0.3)
- Specularity (added in v0.3)
- Offset bump mapping
- Image based reflections
- IBL (added in v0.3)

v0.1 : https://dl.dropbox.com/u/53969153/Texturing_Workflow/BlendMasked_vertexcolor_shader_Maya_v0.1.zip

v0.2 : https://dl.dropbox.com/u/53969153/Shaders/vertex_blend_03_colors_CE3.zip
Change log :
-Synced Blend Factor and Falloff values with CE3 blendlayer shader.

v0.3 : https://dl.dropbox.com/u/53969153/Shaders/Cryengine3_VertexBlend_Maya1Light.zip
Change log :

- Rewrote the code from scratch replacing all existing shaderFX generated code.
- Added blinn-phong specular support, with gloss and specular multiplier. The specular map is stored in alpha channel of diffuse.
- Added texture tiling for Diffuse, Normals, Blend Mask, and Detail map
- Added IBL/Cubemap support
- Added option to multiply diffuse color onto the diffuse textures(see "Color Diffuse Textures") & option to multiply vertex colors to diffuse textures;
- Added detail bump mapping(work in progress)


vertex_blend_ce3_04.jpg

Replies

  • Jeff Parrott
    Offline / Send Message
    Jeff Parrott polycounter lvl 19
    Holy.... Going to give this a try now.

    Edit:

    Just tried it out on OsX Maya 2013. Works great. The gradient blends are only viewable on Viewport 2.0. Otherwise it works great though. Thanks! Can't wait for the updates to this.

    Here's a thread on that vertex paint issue: http://www.polycount.com/forum/showthread.php?t=54590
  • choco
    Offline / Send Message
    choco polycounter lvl 10
    Thanks for the feedback Jeff. I've completely synced the maya shader with the one in CE3 which means that the blend factor and blend falloff values used in maya will look exactly the same in CE3.

    Download link : https://dl.dropbox.com/u/53969153/Shaders/vertex_blend_03_colors_CE3.zip
    Just tried it out on OsX Maya 2013. Works great. The gradient blends are only viewable on Viewport 2.0. Otherwise it works great though. Thanks! Can't wait for the updates to this.
    Thats weird because it working in all my viewports in maya 2009/2012/2013.
    Might be a graphics card issue. What hardware are you using ? I could try recompiling the shader to add full support for ATI and nvidia graphics cards.

    blendmasked_ce3_shader_maya_01.jpg

    1. Controls the tiling of "Diffusemap_01_sampler" and "Normalmap_01_sampler"

    2.This is where you put the diffuse map (in the screenshot its the moss floor texture for example).

    3.Controls the tiling of "Diffusemap_02_sampler" and "Normalmap_02_sampler"

    4.This is where you put the other diffuse to blend with diffuse_01 (in the screenshot its the floor tiles texture ).

    5.This is where you put your blend mask which can be a heightmap or a handpainted mask texture (grayscale).
    Usually you would want to use a heightmap generated from the Diffuse_02 texture (floor tiles).

    6. quote from crydev wiki : Blend Factor: Changes the overall blend factor. Use this to fade in and out the blend layer.

    7.quote from crydev wiki : Blend Falloff: Specifies how smooth the transition between the layers should be. Use a high value for a sharp transition.

    8. Shows full vertex color output (RGBA) RGB vertex colors values are multiplied by the blended textures.

    9. Normal sampler for Diffuse_01 texture.

    10. Normal sampler for Diffuse_02 texture.

    11. Obsolete (will be removed in future releases).

    12. This is where you can define the point light in your scene to be used as main light source. Just copy the name of your point light and past it in there.

    13. Color of your light source.

    14. Obsolete (will be removed in future releases).

    15. This is where you define which set of vertex color the shader needs to read.
    Just right click on the empty box and chose the proper vertex color set.


    blendmasked_ce3_shader_maya.jpg

    blendmasked_ce3_shader_ce3.jpg
  • m4dcow
    Offline / Send Message
    m4dcow interpolator
    Nice! Every other month someone asks for something like this (I think the Naughty Dog texture test asks for blended textures in Maya).
  • choco
    Offline / Send Message
    choco polycounter lvl 10
    Yeah I've seen the question come up several times aswell haha, my friend Drew is cleaning up the code and adding some really cool features. I'll put it up here when he's done :)
  • Sean VanGorder
    Awesome work man, I may be needing something like this pretty soon.
  • choco
    Offline / Send Message
    choco polycounter lvl 10
    Drew++ rewrote the whole thing and made it look pro.

    Change log :
    - Rewrote the code from scratch replacing all existing shaderFX generated code.
    - Added blinn-phong specular support, with gloss and specular multiplier. The specular map is stored in alpha channel of diffuse.
    - Added texture tiling for Diffuse, Normals, Blend Mask, and Detail map
    - Added IBL/Cubemap support
    - Added option to multiply diffuse color onto the diffuse textures(see "Color Diffuse Textures") & option to multiply vertex colors to diffuse textures;
    - Added detail bump mapping(work in progress)

    Download v0.3 : https://dl.dropbox.com/u/53969153/Shaders/Cryengine3_VertexBlend_Maya1Light.zip


    Some screenshots :

    vertex_blend_ce3_01.jpg

    vertex_blend_ce3_04.jpg

    vertex_blend_ce3_UI.jpg

    vertex_blend_ce3_03.jpg
  • Froyok
    Offline / Send Message
    Froyok greentooth
    Awesome work !
    I'm gonna test it right now ! It will be be really useful ! :)
  • Eric Chadwick
  • Drew++
    Offline / Send Message
    Drew++ polycounter lvl 14
    Working on a version for 3DS Max.
    [ame="http://www.youtube.com/watch?v=EKL3JG_p5Vk"]Vertex Alpha Blend Shader - 3DS Max [CryEngine 3] - YouTube[/ame]

    Also, I can't seem to get cube maps to display in 3DS Max right now... Both texCUBE, and texCUBElod won't work. No compiler issues. I have not tried using a separate pass for cube map / IBL stuff yet, that might work.

    If anyone has some knowledge on this, give me a holler!
  • e-freak
    looks sweet! good job :)
  • Gheromo
    Offline / Send Message
    Gheromo polycounter lvl 11
    oh man, you are awesome!!! Really wanted this shader for a loooooong time now. :)
  • cw
    Offline / Send Message
    cw polycounter lvl 17
    Drew++ wrote: »
    Working on a version for 3DS Max.

    Also, I can't seem to get cube maps to display in 3DS Max right now... Both texCUBE, and texCUBElod won't work. No compiler issues. I have not tried using a separate pass for cube map / IBL stuff yet, that might work.

    If anyone has some knowledge on this, give me a holler!

    cubemap should work fine in max viewport.

    what max version etc. are you working with - make sure viewport is not set to nitrous, but directx. send me your code if you like I can test it here.
  • kodde
    Offline / Send Message
    kodde polycounter lvl 19
    Looks sweet.
    Is the IBL blur based on pre-blurred mips in the cubemap or how did you approach this?
  • haiddasalami
    Offline / Send Message
    haiddasalami polycounter lvl 14
    kodde wrote: »
    Looks sweet.
    Is the IBL blur based on pre-blurred mips in the cubemap or how did you approach this?

    I think he's using the texCubeLOD function. Anywho nice stuff! :D
  • Drew++
    Offline / Send Message
    Drew++ polycounter lvl 14
    cw wrote: »
    cubemap should work fine in max viewport.

    what max version etc. are you working with - make sure viewport is not set to nitrous, but directx. send me your code if you like I can test it here.

    Using 2010 in this, so there's no Nitrous viewport yet... I tried it in another pass, and it doesn't work there either. Not sure what the problem is since it works in Maya CGFX...
    I'm having someone test it, and if it doesn't work I'll PM you the shader :)
  • Drew++
    Offline / Send Message
    Drew++ polycounter lvl 14
    I solved the problem! I was peaking around at the included Max shaders and noticed this line of code at the top of many of the shaders...
    string ParamID = "0x003"; // Use DXSAS compiler
    
    Making this an individual post in case anyone else is having 3DS Max shader issues. :thumbup:
  • cw
    Offline / Send Message
    cw polycounter lvl 17
    Aha yes! good stuff!
  • Fingus
    Offline / Send Message
    Fingus polycounter lvl 11
    Oh man, this is so much better than setting it up in the hypershade and having to render to preview! Thanks a lot for this you guys.
  • Drew++
    Offline / Send Message
    Drew++ polycounter lvl 14
    Hey guys! I made some changes / fixes to the shader.
    Changes in Version 0.4:
    - New version for 3DS Max
    - Added support for 3 lights
    - (MAYA) added support for ATI/AMD GPUs. Unfortunately, Maya users lose the ability to blur cubemaps for IBL. Instead, load a pre-blurred cubemap. ( problem with texCUBElod not being supported )
    - Maya users note: Tangents in Viewport 2.0 may be broken, so use standard render, or high quality.

    Grab it here for Max and Maya
    http://drewwatts.net/shaders/CryEngine3_VertexBlend_MayaMax.0.4.zip
    or
    https://dl.dropbox.com/u/8510078/CryEngine3_VertexBlend_MayaMax.0.4.zip

    3 Light Support (3DS Max & Maya)
    3Light_3DSMax.jpg
    3Light_Maya.jpg
    Vertex Color ( Multiply )
    vertexColors_3DSMax.jpg
    Max Shader Parameters:
    shaderParams_Max.jpg
    Maya Shader Parameters:
    shaderParams_Maya.jpg

    Just post here with any problems you guys have.
    Thanks!
  • Fishypants
    Offline / Send Message
    Fishypants polycounter lvl 18
    This is awesome! Thanks for the shader! :D
  • Visum
    Offline / Send Message
    Visum polycounter lvl 7
    I just saw this and it's impressive.
    Now...
    Any chance to have similar thing for Maya <-> Unity?
    I would pay (group pay maybe?)

    Cheers
  • poopipe
    Offline / Send Message
    poopipe grand marshal polycounter
    I just saw this and am kicking myself because I spent ages writing one for myself that isn't as good a few months back :(
  • Fingus
    Offline / Send Message
    Fingus polycounter lvl 11
    Implementing this sort of shader is very simple in Unity if you use a visual shader editor like Strumpy. It's a widely used shader effect that has been well documented.

    I made a simple variation of it about a year ago. You can download the .shader and the Strumpy Shader Editor graph in the video description if you wanna take a closer look at it.

    [ame="http://www.youtube.com/watch?v=HDXwSEUYrbI&quot;]Unity Vertex Blend Material - YouTube[/ame]

    And if you wanna make your own there are plenty of tutorials on how do do it for UDK, and the exact same principles apply to unity. Like this one: http://www.laurenscorijn.com/vertex-blending-snow.html

    Keep in mind though, Unity doesn't have a built in vertex painter so you will have to look for a plugin on the Asset Store. The one I used was fairly primitive and I'm sure there are better ones out now.
  • Visum
    Offline / Send Message
    Visum polycounter lvl 7
    Fingus wrote: »
    Implementing this sort of shader is very simple in Unity if you use a visual shader editor like Strumpy. It's a widely used shader effect that has been well documented.

    I made a simple variation of it about a year ago. You can download the .shader and the Strumpy Shader Editor graph in the video description if you wanna take a closer look at it.

    Unity Vertex Blend Material - YouTube

    And if you wanna make your own there are plenty of tutorials on how do do it for UDK, and the exact same principles apply to unity. Like this one: http://www.laurenscorijn.com/vertex-blending-snow.html

    Keep in mind though, Unity doesn't have a built in vertex painter so you will have to look for a plugin on the Asset Store. The one I used was fairly primitive and I'm sure there are better ones out now.

    Thank you very much.
    Will give it a closer look.
  • Sinking
    I know it'S been asked, but is there a version for Maya 2014? Or is there a way to make this work in Maya 2014. I get "Unknown File Error" when I try to load the shader into Hypershade.

    Could someone (if it works in 2014) describe his workflow to get it in Maya? I need to work with this shader yesterday, and can't wait to test it :)
  • Alphavader
    Offline / Send Message
    Alphavader polycounter lvl 11
    /signed - looking forward for a 2014 version
  • GlowingPotato
    Offline / Send Message
    GlowingPotato polycounter lvl 10
    Wow that's really some awesome work.

    So you paint the alpha channel on those vertex to tell the shader where to blend the materials ? So to have a result with high quality more vertex is needed right ?

    Or i'am thinking bananas ?
  • Sinking
    Wow that's really some awesome work.

    So you paint the alpha channel on those vertex to tell the shader where to blend the materials ? So to have a result with high quality more vertex is needed right ?

    Or i'am thinking bananas ?

    You are thinking right. It needs more vertex for a higher resolution, but realtime engines these days can cope better with more geometry than with more materials. With vertex painting you can create a basic material and paint the extra attributes by using the color channels (RGB/A). In a way it is like you are applying masks in Photoshop.

    And with this tool you can blend them nicely and preview them in one take. I'd really like to mess with it, but I guess we won't get a 2014 release - which is a shame. I just want to create awesome art, and that would be an excellent tool for my needs!
  • Drew++
    Offline / Send Message
    Drew++ polycounter lvl 14
    Sinking wrote: »
    I know it'S been asked, but is there a version for Maya 2014? Or is there a way to make this work in Maya 2014. I get "Unknown File Error" when I try to load the shader into Hypershade.

    Could someone (if it works in 2014) describe his workflow to get it in Maya? I need to work with this shader yesterday, and can't wait to test it :)

    I just tried it with Maya 2014 and it's working! Tried it on Viewport 2.0.
    -- Maybe don't use Hypershade, and instead just right click and "Assign New Material" and choose CgFX Shader.

    Also, under Window>Settings/Preferences>Plug-in Manager, make sure cgfxShader.mll is loaded!
  • Sinking
    Drew++ wrote: »
    I just tried it with Maya 2014 and it's working! Tried it on Viewport 2.0.
    -- Maybe don't use Hypershade, and instead just right click and "Assign New Material" and choose CgFX Shader.

    Also, under Window>Settings/Preferences>Plug-in Manager, make sure cgfxShader.mll is loaded!

    Really? That is awesome!

    Could you tell us where you place the shader or how you loaded it? I mean after you download it, where did you put everything in order to make it work?

    Great news! Thanks man.
  • Froyok
    Offline / Send Message
    Froyok greentooth
    The best would be to place the cgfx in your texture folder inside a project (always work with a project in Maya, it's way more clean). This way you shouldn't have problems later when re-opening you scenes.
  • Sinking
    The problem is I have really little experience with the shaders in Maya. I have my textures/project folder in the CrySDK main directory, so I am already keeping the kind of order you propose. I just don't know where to put the shader files. In textures you say? Seems odd, but if this works it would be cool.

    Can't someone just put up an image of where to put the shader and how to load it? I know I should be more knowledgable about this, and I know shader networks from UDK and XSI, but I don't know where anything is stored and loaded in Maya. And I do research (Digital Tutors forums had some info), but a lot of it is contradictory or "Maya 4.0" and the kind. I need fresh info, yo' feel me ;)?
  • Sinking
    Hey - I must say, I asked a lot of questions before actually trying out your replies. I was still modeling and wanted to be sure everything works when I jump into texturing.

    AND THIS IS AMAZING ^^!

    Yes - the cgfx shader wasn't loaded ~ facepalm.

    >>EDIT<< I just can't seem to figure out the export with the cgfx material parameters. I have imagined the *.mtl file would write the shader settings into my Sandbox file. But the blending looks different to that in Maya. Is there a way to export the parameters into Sandbox, i.e. have the material look the same as in Maya?<<
  • Isaiah Sherman
    Offline / Send Message
    Isaiah Sherman polycounter lvl 14
    I seem to be getting somewhere with this, which has me really excited.

    I am on Maya 2015.

    Shader loads fine, I can load up my diffuse maps and a blend map. However, it doesn't seem to recognize any vertex painting I do.

    I also noticed this warning:
    // Warning: cgfxShader : Can't find the source named "" for vertex attribute "vertcol". //


    Here are some screens:

    What my vert paints look like

    Xna96JG.jpg


    My settings
    V2UDpDg.jpg


    What the final product is (notice my vert painting has no visible effect)
    liaq7a1.jpg
  • Isaiah Sherman
    Offline / Send Message
    Isaiah Sherman polycounter lvl 14
    Also, it's be fucking awesome if this was taken a step further to, instead of B&W, use RGB paint channels.

    This would allow more powerful control in UDK / Unity with terrain shaders that call vertex colors.

    When I worked at Sucker Punch we had RGB controls and it was awesome to be able to have that 3rd texture avilable to paint with.
    Red was considered the "base" diffuse
    Blue was the main second texture that utilized a height map
    Green was the third texture, which just applied in an overlay fashion and did not utilize the blend map (ups and downs to this... would like the ability to choose)

    Is there any chance this shader will get continued work?
  • haiddasalami
    Offline / Send Message
    haiddasalami polycounter lvl 14
    The reason it doesnt work is that you dont have "Use vertex colors" checked. Also it blends based off the alpha of the vertex color.
  • Isaiah Sherman
    Offline / Send Message
    Isaiah Sherman polycounter lvl 14
    Hmm... maybe I need to paint vertex alpha then.

    I'm used to painting actual color.
  • Drew++
    Offline / Send Message
    Drew++ polycounter lvl 14
    Hmm... maybe I need to paint vertex alpha then.

    I'm used to painting actual color.

    This was made to match the vertex alpha CryEngine blending in CryEngine 3, as well as some of the other shader options; so you need to paint vertex alpha to blend between two materials. Vertex color is there as a multiplier to the material color. It doesn't affect blending in any way.
  • GlowingPotato
    Offline / Send Message
    GlowingPotato polycounter lvl 10
    Hey guys, i'am using the shader and having a hard time figuring out and issue with normal map.

    Btw, using maya 2015 here.

    If i load my normal maps and check the box "enable normal maps" my maps are loaded... but looks like whenever i move the view, my normals get messed up.

    When i first plug the maps, or reload the shader, or select the plane, the view seams to refresh and the normal map is displayed correctly.

    nhbYckJ.jpg

    But when i move the view, maps are displayed wrong.

    DGOsIHK.jpg

    any advice ?

    Thanks in advance.

    EDIT: tried the older versions, same thing. Maybe something with maya 2015 viewport 2.0 ?
  • kurt_hectic
    Offline / Send Message
    kurt_hectic polycounter lvl 13
    I have 2 questions:

    -does it break Crytek or any other (c)?
    -do the authors allow to use this shader in commercial projects?
Sign In or Register to comment.