Unity3d Real Plant rendering

Source: Internet
Author: User

Long time no write shader, some unfamiliar, just got a plant shader, share a bit.

First slice:


The key point to note is the transparent part of the fragment shader

Need to be so declared

tags{"Lightmode" = "Forwardbase" "Queue" = "alphatest" "ignoreprojector" = "True" "rendertype" = "Transparentcutout"}Cul L Backzwrite onblend Srcalpha Oneminussrcalpha

Queue queues, determining rendering order

Background-The original render render, used to render the sky box or background
Geometry-Default value, General opaque object
Alphatest-Renders the alpha test pixel
Transparent-Render Transparent objects
Overlay-the last rendered object

"ignoreprojector" = "True" (not affected by projectors)

About Rendertype from here:

Opaque: For most shaders (normal shader, self-light shader, reflection shader, and terrain shader).
Transparent: Shader for translucent shaders (transparent shader, particle shader, font shader, Terrain extra channel).
Transparentcutout: Skin Transparent Shader (Transparent cutout, two-channel vegetation shader).
Background:skybox shaders. Sky Box shader.
Overlay:guitexture, Halo, Flare shaders. Glow shader, Flash shader.
Treeopaque:terrain engine tree bark. The bark of the terrain engine.
Treetransparentcutout:terrain engine tree leaves. The leaves in the terrain engine.
Treebillboard:terrain engine billboarded trees. The Billboard tree in the terrain engine.
Grass:terrain engine Grass. Grass in the terrain engine.
Grassbillboard:terrain engine billboarded grass. Terrain engine where the billboard grass.

It is important to note that the transparent Blend section of the official documentation can be viewed in detail,

But if this is the only transparent part that blocks the back part, we'll add discard to the code behind and drop the pixel directly so it doesn't block the back part.

if (c.a<0.5) discard;



The emphasis here is on physical rendering, previously written in detail:

Since there are two kinds of mapping schemes in the resources, I wrote two kinds of shader for different calculations.

One is the specular texture one is glosstexture.

Big Banana

<span style= "FONT-SIZE:14PX;" >FLOAT3 cc = (C.rgb * (diff+0.2) *_color*_lum + all  * SPECC*_SC  * _scp); return Float4 (CC * 2 + rim, C.A * (1-lu Minance (TRANSC) + _tl));</span>


Polygonatum

FLOAT3 cc = (C.rgb * (diff + 0.2) *_color*_lum + (all + 0.1) * (Saturate (luminance (SPECC)) + 0.1) *_SC*_SCP); return Float4 (CC * 2 + rim, C.A * (1-luminance (TRANSC) + _tl));

You can also extend some things that are better to play, such as writing a wind-blown effect in vertex shader.

All the code to share to GitHub

----------by wolf96


Unity3d Real Plant rendering

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.