Learn Shaderforge–create Base Shader together with Keyle

Source: Internet
Author: User
Tags mul

1. Let's try it together. Use Shaderforge to create a basic shader

2. Describes the nodes exposed in the main function of the shader file

1. Use Shaderforge to create a basic shader

The effect is as follows left 1 is node_1311 color effect is pure white, left 2 is node_1311 color effect is red rgb (255,0,0)

The generated code is as follows, adding _keyletexture mapto the Properties property,_texturenormal normal map,_node_1311 Color, The three variables defined in propertity are used in two corresponding pass blocks. The color value of the overlay computed in the Frag (fragment) function, and the yellow area is the code that calculates multiply in shadeforge.

//Shader created with Shader Forge v1.04//Shader Forge (c) Neat Corporation/joachim Holmer-http://www.acegikmo.com/shaderforge///note:manually Altering this data is prevent you from opening it in Shader Forge/*Sf_data;ver:1.04;sub:start;pass:start;ps:flbk:,lico:1,lgpr:1,nrmq:1,limd:1,uamb:true,mssp:true,lmpd:false,lprd : FALSE,RPRD:FALSE,ENCO:FALSE,FRTR:TRUE,VITR:TRUE,DBIL:FALSE,RMGX:TRUE,RPTH:0,HQSC:TRUE,HQLP:FALSE,TESM:0,BLPR : 0,bsrc:0,bdst:1,culm:0,dpts:2,wrdp:true,dith:2,ufog:true,aust:true,igpj:false,qofs:0,qpre:1,rntp:1,fgom:false , fgoc:false,fgod:false,fgor:false,fgmd:0,fgcr:0.5,fgcg:0.5,fgcb:0.5,fgca:1,fgde:0.01,fgrn:0,fgrf:300,ofsf:0, Ofsu:0,f2p0:false;n:type:shaderforge.sfn_final,id:8894,x:32590,y:32620,varname:node_8894,prsc:2|diff-6495-out, Normal-6723-rgb;n:type:shaderforge.sfn_tex2d,id:2068,x:32175,y:32518,ptovrint:false,ptlb:keyletexture,ptin:_ KEYLETEXTURE,CMNT: Add a decal, Varname:node_2068,prsc:2,tex:3da1dd3705158564c97ec7cf99c87747,ntxv:0,isnm:false;n: TYPE:SHADERFORGE.SFN_TEX2D,ID:6723,X:32179,Y:32883,PTOVRINT:FALSE,PTLB:TEXTURENORMAL,PTIN:_TEXTURENORMAL,CMNT: Normal map, Varname:node_6723,prsc:2,tex:105d97327ec4c5146bb18706fffed5cd,ntxv:3,isnm:true;n:type:shaderforge.sfn_ Multiply,id:6495,x:32378,y:32587,varname:node_6495,prsc:2| A-2068-rgb,b-1311-rgb;n:type:shaderforge.sfn_color,id:1311,x:32056,y:32708,ptovrint:false,ptlb:node_1311,ptin: _node_1311,cmnt:mix Color,varname:node_1311,prsc:2,glob:false,c1:1,c2:1,c3:1,c4:1;proporder:2068-6723-1311;pass : End;sub:end;*/Shader"Custom/newshader"{Properties {_keyletexture ("keyletexture", 2D) =" White"{} _texturenormal ("Texturenormal", 2D) ="Bump"{} _node_1311 ("node_1311", Color) = (1,1,1,1)} subshader {Tags {"Rendertype"="Opaque"} LOD $Pass {Name"Forwardbase"Tags {"Lightmode"="Forwardbase"} cgprogram#pragmaVertex vert#pragmaFragment Frag#defineUnity_pass_forwardbase#include"Unitycg.cginc"#include"Autolight.cginc"            #pragmaMulti_compile_fwdbase_fullshadows#pragmaExclude_renderers xbox360 PS3 Flash d3d11_9x#pragmaTarget 3.0uniform float4 _lightcolor0; Uniform sampler2d _keyletexture;            Uniform FLOAT4 _keyletexture_st; Uniform sampler2d _texturenormal;            Uniform FLOAT4 _texturenormal_st;            Uniform FLOAT4 _node_1311; structvertexinput {float4 vertex:position;                FLOAT3 Normal:normal;                FLOAT4 tangent:tangent;            FLOAT2 texcoord0:texcoord0;            }; structvertexoutput {float4 pos:sv_position;                FLOAT2 uv0:texcoord0;                FLOAT4 Posworld:texcoord1;                FLOAT3 Normaldir:texcoord2;                FLOAT3 Tangentdir:texcoord3;                FLOAT3 Binormaldir:texcoord4; Lighting_coords (5,6)            }; Vertexoutput Vert (Vertexinput v) {vertexoutput o= (vertexoutput)0; O.uv0=v.texcoord0; O.normaldir= Mul (_object2world, FLOAT4 (V.normal,0). xyz; O.tangentdir= Normalize (Mul (_object2world, FLOAT4 (V.TANGENT.XYZ,0.0) . xyz); O.binormaldir= Normalize (Cross (o.normaldir, O.tangentdir) *V.TANGENT.W); O.posworld=Mul (_object2world, V.vertex); FLOAT3 Lightcolor=_lightcolor0.rgb; O.pos=Mul (UNITY_MATRIX_MVP, V.vertex); Transfer_vertex_to_fragment (o)returno; } fixed4 Frag (Vertexoutput i): COLOR {i.normaldir=normalize (I.normaldir); float3x3 Tangenttransform=float3x3 (I.tangentdir, I.binormaldir, i.normaldir);///////Vectors:FLOAT3 viewdirection = Normalize (_WORLDSPACECAMERAPOS.XYZ-i.posworld.xyz); FLOAT3 _texturenormal_var= Unpacknormal (tex2d (_texturenormal,transform_tex (I.uv0, _texturenormal)));//Normal MapFLOAT3 normallocal =_texturenormal_var.rgb; FLOAT3 normaldirection= Normalize (Mul (normallocal, tangenttransform));//perturbed normalsFLOAT3 lightdirection =normalize (_WORLDSPACELIGHTPOS0.XYZ); FLOAT3 Lightcolor=_lightcolor0.rgb;//////Lighting:                floatAttenuation =light_attenuation (i); FLOAT3 Attencolor= Attenuation *_lightcolor0.xyz;///////Diffuse:                floatNdotl = Max (0.0, Dot (normaldirection, lightdirection)); FLOAT3 Indirectdiffuse= FLOAT3 (0,0,0); FLOAT3 Directdiffuse= Max (0.0, Ndotl) *Attencolor; Indirectdiffuse+ = Unity_lightmodel_ambient.rgb;//Ambient LightFLOAT4 _keyletexture_var = tex2d (_keyletexture,transform_tex (I.uv0, _keyletexture));//Add a decalFLOAT3 Diffuse = (Directdiffuse + indirectdiffuse) * (_keyletexture_var.rgb*_node_1311.rgb);///Final Color:FLOAT3 Finalcolor =Diffuse; returnFixed4 (Finalcolor,1); } ENDCG} Pass {Name"Forwardadd"Tags {"Lightmode"="Forwardadd"} Blend One one Fog {Color (0,0,0,0)} Cgprogram#pragmaVertex vert#pragmaFragment Frag#defineUnity_pass_forwardadd#include"Unitycg.cginc"#include"Autolight.cginc"            #pragmaMulti_compile_fwdadd_fullshadows#pragmaExclude_renderers xbox360 PS3 Flash d3d11_9x#pragmaTarget 3.0uniform float4 _lightcolor0; Uniform sampler2d _keyletexture;            Uniform FLOAT4 _keyletexture_st; Uniform sampler2d _texturenormal;            Uniform FLOAT4 _texturenormal_st;            Uniform FLOAT4 _node_1311; structvertexinput {float4 vertex:position;                FLOAT3 Normal:normal;                FLOAT4 tangent:tangent;            FLOAT2 texcoord0:texcoord0;            }; structvertexoutput {float4 pos:sv_position;                FLOAT2 uv0:texcoord0;                FLOAT4 Posworld:texcoord1;                FLOAT3 Normaldir:texcoord2;                FLOAT3 Tangentdir:texcoord3;                FLOAT3 Binormaldir:texcoord4; Lighting_coords (5,6)            }; Vertexoutput Vert (Vertexinput v) {vertexoutput o= (vertexoutput)0; O.uv0=v.texcoord0; O.normaldir= Mul (_object2world, FLOAT4 (V.normal,0). xyz; O.tangentdir= Normalize (Mul (_object2world, FLOAT4 (V.TANGENT.XYZ,0.0) . xyz); O.binormaldir= Normalize (Cross (o.normaldir, O.tangentdir) *V.TANGENT.W); O.posworld=Mul (_object2world, V.vertex); FLOAT3 Lightcolor=_lightcolor0.rgb; O.pos=Mul (UNITY_MATRIX_MVP, V.vertex); Transfer_vertex_to_fragment (o)returno; } fixed4 Frag (Vertexoutput i): COLOR {i.normaldir=normalize (I.normaldir); float3x3 Tangenttransform=float3x3 (I.tangentdir, I.binormaldir, i.normaldir);///////Vectors:FLOAT3 viewdirection = Normalize (_WORLDSPACECAMERAPOS.XYZ-i.posworld.xyz); FLOAT3 _texturenormal_var= Unpacknormal (tex2d (_texturenormal,transform_tex (I.uv0, _texturenormal)));//Normal MapFLOAT3 normallocal =_texturenormal_var.rgb; FLOAT3 normaldirection= Normalize (Mul (normallocal, tangenttransform));//perturbed normalsFLOAT3 lightdirection = Normalize (Lerp (_worldspacelightpos0.xyz, _WORLDSPACELIGHTPOS0.XYZ-i.posworld.xyz,_worldspacelightpos0.w)); FLOAT3 Lightcolor=_lightcolor0.rgb;//////Lighting:                floatAttenuation =light_attenuation (i); FLOAT3 Attencolor= Attenuation *_lightcolor0.xyz;///////Diffuse:                floatNdotl = Max (0.0, Dot (normaldirection, lightdirection)); FLOAT3 Directdiffuse= Max (0.0, Ndotl) *Attencolor; FLOAT4 _keyletexture_var= tex2d (_keyletexture,transform_tex (I.uv0, _keyletexture));//Add a decalFLOAT3 Diffuse = Directdiffuse * (_keyletexture_var.rgb*_node_1311.rgb);///Final Color:FLOAT3 Finalcolor =Diffuse; returnFIXED4 (Finalcolor *1,0); } ENDCG}} FallBack"Diffuse"Customeditor"Shaderforgematerialinspector"}

Public nodes in 2.Main

Diffuse (Diffuse reflection)

This is the main hue of our shader, the diffuse color comes from the light, and the middle shadow part is the faint area of the incident light.

Diffuse power (power of diffuse reflection)

This is the power of a weak light, which can be used to simulate the appearance of metal when using a power greater than 1

Specular (Specular reflection)

This is the color of your shader specular highlight, the higher the value, the more gorgeous the color, when the object is black and unaffected by specular.

Gloss (Gloss)

The higher the gloss value, the more shiny the surface of your object looks and vice versa.

Normal (normal map)

I do not explain this, the normal map of the map to record the spatial information, so that your image looks concave and convex, who helped me to draw a beautiful woman's normal map?

Emission (divergence)

As the name implies, the intensity of the reflected light

Transmission (This word I think can compromise some translation such as "permeability")

For example, you are a glass (or a plant), I light a lamp behind you, the person in front of you can see through you the light behind you, if you have more impurities (change the transmission value), then I can see through you light is weaker

Light wrapping (Quad Zhou Guang/surround)

The weakening offset of the angle of the light, which results in similar scattering of light from the ground, is used for smooth objects, into human skin.

Diffuse Ambient Light (ambient diffuse reflectance)

It adds light to your shader, affected by diffuse reflection (diffuse), and is used for image-based illumination

Specular Ambient Light (specular reflection environment)

Similar to diffuse Ambient light, with one more specular effect

Diffuse Ambient occlusion (diffuse reflection ambient occlusion)

As the name implies, to suppress the light emitted by diffuse.

Specular Ambient occlusion (specular reflection ambient occlusion)

As above, in order to suppress the specular reflection of the light

Custom Lighting (User defined light)

Allow user to customize lighting behavior

Alpha (Transparent channel)

This is not much to say, if you do not know this can hit tofu

Alpha Clip (transparent channel trim)

As the name implies, the cropping effect

Refraction (refraction)

Refraction background elements make screen space UV offset

Outline width (stroke width)

Stroke and control the width of the mesh edge offset

Outline Color (stroke color)

Vertex offset (vertex offset)

This can be used for animation shaders, changing the vertex offset offset as the time function changes

DX11 Displacement (DX11 displacement)

Displacements under the DirectX 11 specification can no longer be used in unity

DX11 tessellation (DX11 subdivision surface technology)

Tessellation Subdivision Curved Surface technology is AMD (ATI) years of research and development of multi-generation technology, after many decades of development has finally been adopted as a key technology of DX11, so has always been the focus of propaganda. Unlike ray tracing, the core of today's rasterized graphics rendering technology is to draw a large number of triangles to form a 3D model, while the tessellation technique uses GPU hardware acceleration to split the triangles of the existing 3D model into smaller, more detailed ones, which greatly increase the number of triangles, Makes the surface and edge of the rendered object smoother and finer.

This chapter in order to reduce the complexity of the operation only selected a computational function Multiply, in the Shaderforge right-click arithmetic can be found, can be found through the right side of the shortcut property bar, I wish you a happy study!

Learn shaderforge–create Base Shader with Keyle

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.