SHADER setting-up trees

Discussion in 'Tracks' started by jarodyi, Nov 4, 2014.

  1. MGMetroDave

    MGMetroDave Active Member

    Joined:
    Apr 7, 2019
    Messages:
    141
    Likes Received:
    159
    Hi all! Thanks this is a really great thread.
    I hope you don't mind, I'm just checking I'm not going crazy. I'm basically looking for a normal-map enabled equivalent of the tree shader. Something that behaves the same as ksTree, but allows me to add a normal map? Does such a thing exist? It needs to not self-shadow, but must cast shadows onto other objects. It would also obviously need to support alphatest transparency (AT).
    I know ksTree also sets vertex normals radially and smooths shading, and those would be handy but not essential, as it can be done manually in blender or another 3d editor.
    Also swaying in the wind would be nice in case it was an option. ;-)
    Basically I've done some tests with some specially created tree diffuse and normal map textures using the ksPerPixelAT_NM, manually editing vertex normals. It makes for highly effective looking trees since the trunk and branches appear lit from the correct angles, and different leaves are lit up depending on the normal map, which take into account both the smooth shading between the vertices and the normal map. Honestly, it works pretty well, except...
    Unfortunately I have to turn off casting of shadows, otherwise it casts a shadow on itself, ruining the effect completely, :lol:.
    Does anyone know if there a workaround for this? I tried creating a separate shadow-casting plane similar to the trick to get top-down shadows on trees lit from the top, if that makes sense. I tried various configurations and shapes of planes, but none of them were close to looking right. Does anyone have any suggestions? I'd love to get this working!:(:banghead::ROFLMAO: :lol:
    Thanks in advance...
     
  2. Prototype

    Prototype Well-Known Member

    Joined:
    Dec 24, 2018
    Messages:
    329
    Likes Received:
    588
    Location:
    JHB / SF
    Some shaders like ksPerPixelMultiMap_AT_NMdetail have a "shadowBiasMulti" input which allows you to dial out self shadow ... (?)
     
    MGMetroDave likes this.
  3. MGMetroDave

    MGMetroDave Active Member

    Joined:
    Apr 7, 2019
    Messages:
    141
    Likes Received:
    159
    Ooooh, that sounds promising! I'll give it a try and report back. Thanks for the quick reply!
     
  4. MGMetroDave

    MGMetroDave Active Member

    Joined:
    Apr 7, 2019
    Messages:
    141
    Likes Received:
    159
    Prototype, I owe you! That absolutely was the answer. Thank you very much!

    This is probably common knowledge, but it was new to me, and it might help others coming to this post... ksPerPixelMultiMap_AT_NMDetail requires the alpha map for the cut-out tree to be on the alpha channel of the txNormal texture. However, the shadow, interestingly, seems to be independent. It's taken from the alpha channel of the txDiffuse texture! So that too can be played with.

    Using ksPerPixelMultiMap_AT_NMDetail as suggested by Protype enables you to use the txMaps slot for specular level. Great stuff!

    (Please someone, correct me if I'm wrong... I'm still new to this).

    Thanks again! The ACM forum comes to the rescue once again!
     
    SebSto likes this.
  5. MGMetroDave

    MGMetroDave Active Member

    Joined:
    Apr 7, 2019
    Messages:
    141
    Likes Received:
    159
    Just a few shots to show roughly what I was trying to accomplish. The tree on the right is a standard ksTree (following the usual instructions, hopefully). On the left however is a tree using a normal map and specular map (although everything could use some fine-tuning). I know it's a completely different species and size of tree, but It's more proof of concept at this stage. Hope this is of interest to someone.

    Thanks again, @Prototype for the suggestion of using ksPerPixelMultiMap_AT_NMDetail. It worked a treat after a little work!

    [​IMG]
    [​IMG]
    [​IMG]
    [​IMG]
    [​IMG]
     
    Prototype and luchian like this.
  6. Johnr777

    Johnr777 Moderator

    Joined:
    Jul 26, 2017
    Messages:
    1,047
    Likes Received:
    613
    Interesting! Both trees use the kstreegroup naming, and pivot point at the bottom of the object? The tree on the right is shaded a little weird.
     
  7. Fuzo

    Fuzo Member

    Joined:
    May 24, 2018
    Messages:
    99
    Likes Received:
    18
    Location:
    Bydgoszcz, Poland
    hi guys, which method are you using to create tree walls in 3dsmax? Any tips would be appreciated.
     
  8. Johnr777

    Johnr777 Moderator

    Joined:
    Jul 26, 2017
    Messages:
    1,047
    Likes Received:
    613
    luchian likes this.
  9. Patrice COte

    Patrice COte Active Member

    Joined:
    Jan 3, 2018
    Messages:
    58
    Likes Received:
    139
    While we're on the topic of tree walls.... I have a couple of questions for the pros about normals.

    I made treewalls based on bezier curves and array modifier (in Blender).

    1-If Rely on the naming scheme KSTREE_GROUP_ZZZZ so the editor would auto convert normals to point up, it leads to very bad shading (darkest when sun is high in the sky, overexposed with low Sun angles) which is expected if normals point horizontal... Naming doesn't seem work like for Y trees (unless I'm missing something - which is quite possible!). It does make the "block transform" and merge the many tree wall objects

    tree_wall_1.JPG
    tree_wall_2.JPG

    2-If I add an "edit normals" modifier (+auto smooth normals) to the base object, I can't visualize the modifier effect unless I apply it (it seems). With modifiers are applied, all are pointing up as it should (pink vertex normals pointing up). However, if I keep the same KSTREE_GROUP_ naming , still getting the same bad result in the editor.

    3-Finally, if I do the same a point #2 above but give it a random name, shading is good in the editor. But I loose the blocktransform at import in the editor...

    So, method #3 is the only one that I was able to make work as intended. I can merge all the tree walls object in Blender so it's not so bad if I don't have the block transform. I'm I doing this right? I have very large forest areas to make because of the steep hills, so it's kind of important not to go in the wrong direction.

    tree_wall_3_vertex_per_face.JPG
     
  10. Johnr777

    Johnr777 Moderator

    Joined:
    Jul 26, 2017
    Messages:
    1,047
    Likes Received:
    613
    the kstreegroup naming doesn’t work with tree walls, that only handles regular tree objects. For tree walls, just name like any other object, then make sure normals point up. Some people do normals at the top of the object point up, and the bottom point forward or down for better results... I just do all pointing up.

    a good shader for treewalls is the grass one, the variation layer can make it more random, which helps with the repetition.

    hope this helps!
     
    Patrice COte and MGMetroDave like this.
  11. MGMetroDave

    MGMetroDave Active Member

    Joined:
    Apr 7, 2019
    Messages:
    141
    Likes Received:
    159
    From my limited knowledge (please can someone correct me if I'm wrong), I think KSTREE_GROUP naming is indeed what makes kseditor override the normals and is intended for individual trees, hence the results.

    It takes objects with that name and overrides normals, pointing them outwards based on the origin of the object, then it groups the edited objects as one object ready for use in the game. For individual trees, having individual object origins is essential for the normal overriding to work, which is why we can't merge all our trees into one object in Blender.

    The blocktransform's purpose is to make the trees in that treegroup one object for game purposes after normal editing, since we don't want thousands of individual objects in game.
    Since we don't need more than one origin for tree walls, we don't need it to override normals, and it's fine to merge meshes into fewer objects in Blender.
     
    Last edited: Oct 16, 2019
    Patrice COte likes this.
  12. LilSKi

    LilSKi Well-Known Member

    Joined:
    Apr 6, 2015
    Messages:
    370
    Likes Received:
    329
    For the first row I like to have normals up on top and down or 90* on bottom. The rows after that are all up for the normals.
     
    Patrice COte and MGMetroDave like this.
  13. Fuzo

    Fuzo Member

    Joined:
    May 24, 2018
    Messages:
    99
    Likes Received:
    18
    Location:
    Bydgoszcz, Poland
    guys I was curious how do you create those treewalls, do you extrude it from spline or do you use another approach? How do you align it to curved surface? What modifiers do you use? Some quick tutorial would be really awesome :)
     
  14. Patrice COte

    Patrice COte Active Member

    Joined:
    Jan 3, 2018
    Messages:
    58
    Likes Received:
    139
    I'm still learning, but here's what I did in Blender (I'm sure there are other variants, and more efficient ones for sure)
    1-Create Bezier curve for the wall path. (important to subdivide many times once your happy with path to avoid gap if terrain has lots of elevation change between control points - maybe a modifer could be applied on the curve to get same effect - not sure)
    upload_2019-10-17_22-56-2.png
    2-Add Shrinkwrap modifier to curve so it follows ground
    upload_2019-10-17_22-21-10.png

    3-Create Basic wall panel object (can be split in a few sub panels to better follow ground), and UV unwrap it onto your tree wall texture (I use a montage of many of my individual tree texture to build the tree wall). Leave a few pixels at the top of the unwraping so mipmaps doesn't make a small black line when looking from far away.
    upload_2019-10-17_22-26-53.png

    4-Add the following modifier to you panel object (they must be stacked up in that order from top to bottom)
    Array (fit to bezier curve), Curve, Shrinkwrap to terrain (already done for bezier curve - but doesn't hurt)
    *One of the tricky part is getting the array and curve modifier to work if the object was not located at proper origin
    upload_2019-10-17_22-28-52.png

    5- (obsolete) see next post for better alternative method
    Another modifer is needed on your wall object to have the Vertex Normals pointing up (at the bottom of the stack) : NORMAL EDIT modifer.
    5.1 make to turn ON the normals auto smooth
    5.2 Create a dummy object plane (called REF_NORMAL_UP in the example below) in the X-Y plane.
    5.3 Set NOrmal edit parameters as shown below, don't forget max angle a few degrees below 90deg, if not it will merge (or reverse) one of the side of the tree wall.

    upload_2019-10-17_22-37-49.png

    upload_2019-10-17_22-38-44.png

    6-To get many sub walls (for criss-cross pattern), just duplicate curve and object. Then edit curve as you see fit and change modifier's reference curve to point the new one. It's actually pretty fast one you get the first wall done (which can be an adventure on its own...).

    7-Ideally you want to export a single object for the walls in a given area (for performance reasons), so in order to do that I duplicated all may walls (to keep the editable original just in case) and applied all the modifiers on each one. Then merge into a single object.

    I hope this helps! (If anyone has improvements to suggest, be my guest!)
     
    Last edited: Oct 18, 2019
  15. Patrice COte

    Patrice COte Active Member

    Joined:
    Jan 3, 2018
    Messages:
    58
    Likes Received:
    139
    Forget about step number 5 above.... there's a much better way of editing normals.
    Use the Blend4web addon. It as a real vertex normals editor. So wait until you've merged all the tree walls object togheter. So step 6.5 : edit mode, select all vertex, edit nomals "aboslute" -90 in Z and your done. You can also have lower vertex from first row pointing down by secting them ang setting Z absolute to -90.
    (unit shows meters, but its really degrees)

    upload_2019-10-18_7-44-47.png
     
  16. LilSKi

    LilSKi Well-Known Member

    Joined:
    Apr 6, 2015
    Messages:
    370
    Likes Received:
    329
    I've also used accordion style walls. Sometimes with straight walls you can pick out the straight line. The accordion style does a better job hiding that.

    Screenshot_shelby_cobra_289_lilski_watkins_glen_18-10-119-11-16-32.jpg

    Straight line walls.
    upload_2019-10-18_11-21-37.png


    accordion walls
    Screenshot_shelby_cobra_289_lilski_watkins_glen_18-10-119-11-23-53.jpg
     
  17. Bruno Mendes

    Bruno Mendes New Member

    Joined:
    Jan 6, 2020
    Messages:
    15
    Likes Received:
    2
    Hi Guys, this is my first post here... I've got to say... this forum is incredible!

    I just want to someone have a look at my Y tree to see if it is correct ... I'm saying that because when i try the track in the game the trees don't look good.. Blender file is attached. If the file is ok then at least i know the "problem" is in the shader...

    Many thanks!
     

    Attached Files:

  18. Johnr777

    Johnr777 Moderator

    Joined:
    Jul 26, 2017
    Messages:
    1,047
    Likes Received:
    613
    I dont use blender, so can't see the file you attached. Export to FBX perhaps? or a screenshot of the tree and wireframe, pivot point, etc
     
  19. Bruno Mendes

    Bruno Mendes New Member

    Joined:
    Jan 6, 2020
    Messages:
    15
    Likes Received:
    2
    Thanks mate! Screenshot and Fbx Attached

    Thanks!
     

    Attached Files:

  20. Portland12345

    Portland12345 Member

    Joined:
    Feb 11, 2017
    Messages:
    34
    Likes Received:
    10
    I checked it out its fine.


    Don't think you setup the tree shader correctly in ksEditor.

    Here is how it should be setup so it looks good in game.


    (use dds obviously, as I had no access to your texture file so i just screenshot it and made it quickly with paint)

    [​IMG]










    ................


    in blender 2.8.

    I would advise you enable the addon.

    Import images as planes.

    It will setup the tree, the shader and unwrap everything for you.

    Than you can duplicate and spin it around and you have tree ready for ks editor in 1 second.


    You can make farm of trees in seconds.
     
    Last edited: Jan 7, 2020
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice