Search Unity

Shader Forge - A visual, node-based shader editor

Discussion in 'Assets and Asset Store' started by Acegikmo, Jan 11, 2014.

  1. GMM

    GMM

    Joined:
    Sep 24, 2012
    Posts:
    301
    Can someone explain just what the "Direct3D 11 for Windows RT" target render does? I am making a very simple shader that emits a single color, yet the shader comes out black on my Surface RT.

    Has anyone tried using Shader Forge with the Surface RT?
     
  2. snowwolf

    snowwolf

    Joined:
    Dec 7, 2012
    Posts:
    1
    How can i make a refraction mask with nodes ?
    My problem with refraction and it's solution described here
    See Example 19-2.
     
  3. Chaoss

    Chaoss

    Joined:
    Jul 8, 2011
    Posts:
    327
    So I've managed to make the start of a screen-based reflection shader using the Scene Color node, I've sort of managed to get the panning of the 'scene' texture so the reflection reacts to the direction of the camera and it would pass as acceptable in most of the use cases I have for it, but there is an issue where it doesn't work on any surface that's not facing upward. I'd like to be able to use this as a glass shader on buildings.

    I am aware of the limitations and the accompanying artifacts which I have plans on how to cover up, But I'd like to get the shader working in it's current state before i pretty it up

    I somehow need to translate UV's or something and ANY clues would be a really big help as I am pretty clueless from here on out and don't really know where to start.



    Someone had successfuly modded my shader to work a few pages back but did not post the solution, and has not responded to IM's or this thread. I really really really need help with this.

    I am trying to achieve this (the solution that guy had posted)
     
  4. anton1987ru

    anton1987ru

    Joined:
    Nov 16, 2012
    Posts:
    15
    Code (CSharp):
    1.  
    2. // Shader created with Shader Forge Beta 0.28
    3. // Shader Forge (c) Joachim Holmer - http://www.acegikmo.com/shaderforge/
    4. // Note: Manually altering this data may prevent you from opening it in Shader Forge
    5. /*SF_DATA;ver:0.28;sub:START;pass:START;ps:flbk:,lico:1,lgpr:1,nrmq:1,limd:2,uamb:True,mssp:True,lmpd:False,lprd:False,enco:False,frtr:True,vitr:True,dbil:False,rmgx:True,hqsc:True,hqlp:False,blpr:0,bsrc:0,bdst:1,culm:0,dpts:0,wrdp:True,ufog:True,aust:False,igpj:False,qofs:0,qpre:4,rntp:2,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:1,x:32101,y:32743|diff-2293-RGB,spec-2616-OUT,gloss-2617-OUT,normal-2301-RGB,amdfl-2532-OUT,refract-2593-OUT;n:type:ShaderForge.SFN_SceneColor,id:2282,x:32947,y:33045|UVIN-2283-OUT;n:type:ShaderForge.SFN_Append,id:2283,x:33125,y:33048|A-2288-U,B-2284-OUT;n:type:ShaderForge.SFN_ComponentMask,id:2284,x:33342,y:33096,cc1:1,cc2:-1,cc3:-1,cc4:-1|IN-2285-UVOUT;n:type:ShaderForge.SFN_Panner,id:2285,x:33508,y:33095,spu:0,spv:2|UVIN-2286-OUT,DIST-2289-OUT;n:type:ShaderForge.SFN_Append,id:2286,x:33774,y:33045|A-2288-U,B-2287-OUT;n:type:ShaderForge.SFN_OneMinus,id:2287,x:34000,y:33064|IN-2288-V;n:type:ShaderForge.SFN_ScreenPos,id:2288,x:34068,y:32732,sctp:2;n:type:ShaderForge.SFN_Negate,id:2289,x:33781,y:33183|IN-2290-OUT;n:type:ShaderForge.SFN_ComponentMask,id:2290,x:33973,y:33181,cc1:1,cc2:-1,cc3:-1,cc4:-1|IN-2291-XYZ;n:type:ShaderForge.SFN_Transform,id:2291,x:34169,y:33181,tffrom:0,tfto:3|IN-2292-OUT;n:type:ShaderForge.SFN_Vector3,id:2292,x:34393,y:33179,v1:0,v2:0,v3:0;n:type:ShaderForge.SFN_Tex2d,id:2293,x:32372,y:32602,ptlb:Texture map,ptin:_Texturemap,tex:b66bceaf0cc0ace4e9bdc92f14bba709,ntxv:0,isnm:False;n:type:ShaderForge.SFN_Tex2d,id:2301,x:33432,y:32724,ptlb:Normal+distortion,ptin:_Normaldistortion,tex:bbab0a6f7bae9cf42bf057d8ee2755f6,ntxv:3,isnm:True;n:type:ShaderForge.SFN_Slider,id:2499,x:32872,y:33269,ptlb:Reflection,ptin:_Reflection,min:0,cur:0.4188645,max:2;n:type:ShaderForge.SFN_Multiply,id:2532,x:32700,y:33102|A-2282-RGB,B-2499-OUT;n:type:ShaderForge.SFN_ComponentMask,id:2592,x:33160,y:32816,cc1:0,cc2:1,cc3:-1,cc4:-1|IN-2301-RGB;n:type:ShaderForge.SFN_Multiply,id:2593,x:32578,y:32911|A-2592-OUT,B-2605-OUT;n:type:ShaderForge.SFN_Slider,id:2605,x:32847,y:32943,ptlb:Distortion,ptin:_Distortion,min:0,cur:0.5092709,max:1;n:type:ShaderForge.SFN_Slider,id:2616,x:32614,y:32656,ptlb:Specular,ptin:_Specular,min:0,cur:0.7074232,max:1;n:type:ShaderForge.SFN_Fresnel,id:2617,x:32401,y:32802|EXP-2616-OUT;proporder:2293-2301-2499-2605-2616;pass:END;sub:END;*/
    6.  
    7. Shader "Shader Forge/Realtime Screen Space Reflection" {
    8.     Properties {
    9.         _Texturemap ("Texture map", 2D) = "white" {}
    10.         _Normaldistortion ("Normal+distortion", 2D) = "bump" {}
    11.         _Reflection ("Reflection", Range(0, 2)) = 0.4188645
    12.         _Distortion ("Distortion", Range(0, 1)) = 0.5092709
    13.         _Specular ("Specular", Range(0, 1)) = 0.7074232
    14.     }
    15.     SubShader {
    16.         Tags {
    17.             "Queue"="Overlay"
    18.             "RenderType"="Transparent"
    19.         }
    20.         GrabPass{ }
    21.         Pass {
    22.             Name "ForwardBase"
    23.             Tags {
    24.                 "LightMode"="ForwardBase"
    25.             }
    26.             ZTest Less
    27.            
    28.            
    29.             CGPROGRAM
    30.             #pragma vertex vert
    31.             #pragma fragment frag
    32.             #define UNITY_PASS_FORWARDBASE
    33.             #include "UnityCG.cginc"
    34.             #include "AutoLight.cginc"
    35.             #pragma multi_compile_fwdbase_fullshadows
    36.             #pragma exclude_renderers xbox360 ps3 flash d3d11_9x
    37.             #pragma target 3.0
    38.             uniform float4 _LightColor0;
    39.             uniform sampler2D _GrabTexture;
    40.             uniform sampler2D _Texturemap; uniform float4 _Texturemap_ST;
    41.             uniform sampler2D _Normaldistortion; uniform float4 _Normaldistortion_ST;
    42.             uniform float _Reflection;
    43.             uniform float _Distortion;
    44.             uniform float _Specular;
    45.             struct VertexInput {
    46.                 float4 vertex : POSITION;
    47.                 float3 normal : NORMAL;
    48.                 float4 tangent : TANGENT;
    49.                 float4 uv0 : TEXCOORD0;
    50.             };
    51.             struct VertexOutput {
    52.                 float4 pos : SV_POSITION;
    53.                 float4 uv0 : TEXCOORD0;
    54.                 float4 posWorld : TEXCOORD1;
    55.                 float3 normalDir : TEXCOORD2;
    56.                 float3 tangentDir : TEXCOORD3;
    57.                 float3 binormalDir : TEXCOORD4;
    58.                 float4 screenPos : TEXCOORD5;
    59.                 LIGHTING_COORDS(6,7)
    60.             };
    61.             VertexOutput vert (VertexInput v) {
    62.                 VertexOutput o;
    63.                 o.uv0 = v.uv0;
    64.                 o.normalDir = mul(float4(v.normal,0), _World2Object).xyz;
    65.                 o.tangentDir = normalize( mul( _Object2World, float4( v.tangent.xyz, 0.0 ) ).xyz );
    66.                 o.binormalDir = normalize(cross(o.normalDir, o.tangentDir) * v.tangent.w);
    67.                 o.posWorld = mul(_Object2World, v.vertex);
    68.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    69.                 o.screenPos = o.pos;
    70.                 TRANSFER_VERTEX_TO_FRAGMENT(o)
    71.                 return o;
    72.             }
    73.             fixed4 frag(VertexOutput i) : COLOR {
    74.                 #if UNITY_UV_STARTS_AT_TOP
    75.                     float grabSign = -_ProjectionParams.x;
    76.                 #else
    77.                     float grabSign = _ProjectionParams.x;
    78.                 #endif
    79.                 i.normalDir = normalize(i.normalDir);
    80.                 float3x3 tangentTransform = float3x3( i.tangentDir, i.binormalDir, i.normalDir);
    81.                 float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
    82. /////// Normals:
    83.                 float2 node_2631 = i.uv0;
    84.                 float3 node_2301 = UnpackNormal(tex2D(_Normaldistortion,TRANSFORM_TEX(node_2631.rg, _Normaldistortion)));
    85.                 float3 normalLocal = node_2301.rgb;
    86.                 float3 normalDirection =  normalize(mul( normalLocal, tangentTransform )); // Perturbed normals
    87.                 i.screenPos = float4( i.screenPos.xy / i.screenPos.w, 0, 0 );
    88.                 i.screenPos.y *= _ProjectionParams.x;
    89.                 float2 sceneUVs = float2(1,grabSign)*i.screenPos.xy*0.5+0.5 + (node_2301.rgb.rg*_Distortion);
    90.                 float4 sceneColor = tex2D(_GrabTexture, sceneUVs);
    91.                 float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz);
    92. ////// Lighting:
    93.                 float attenuation = LIGHT_ATTENUATION(i);
    94.                 float3 attenColor = attenuation * _LightColor0.xyz;
    95. /////// Diffuse:
    96.                 float NdotL = dot( normalDirection, lightDirection );
    97.                 float3 diffuse = max( 0.0, NdotL) * attenColor + UNITY_LIGHTMODEL_AMBIENT.xyz;
    98. ///////// Gloss:
    99.                 float node_2616 = _Specular;
    100.                 float gloss = exp2(pow(1.0-max(0,dot(normalDirection, viewDirection)),node_2616)*10.0+1.0);
    101. ////// Specular:
    102.                 NdotL = max(0.0, NdotL);
    103.                 float3 specularColor = float3(node_2616,node_2616,node_2616);
    104.                 float3 specular = (floor(attenuation) * _LightColor0.xyz) * pow(max(0,dot(reflect(-lightDirection, normalDirection),viewDirection)),gloss) * specularColor;
    105.                 float3 finalColor = 0;
    106.                 float3 diffuseLight = diffuse;
    107.                 float2 node_2288 = sceneUVs;
    108.                 diffuseLight += (tex2D(_GrabTexture, float2(node_2288.r,(float2(node_2288.r,(1.0 - node_2288.g))+(-1*mul( UNITY_MATRIX_V, float4(float3(0,0,0),0) ).xyz.rgb.g)*float2(0,2)).g)).rgb*_Reflection); // Diffuse Ambient Light
    109.                 finalColor += diffuseLight * tex2D(_Texturemap,TRANSFORM_TEX(node_2631.rg, _Texturemap)).rgb;
    110.                 finalColor += specular;
    111. /// Final Color:
    112.                 return fixed4(lerp(sceneColor.rgb, finalColor,1),1);
    113.             }
    114.             ENDCG
    115.         }
    116.         Pass {
    117.             Name "ForwardAdd"
    118.             Tags {
    119.                 "LightMode"="ForwardAdd"
    120.             }
    121.             Blend One One
    122.             ZTest Less
    123.            
    124.            
    125.             Fog { Color (0,0,0,0) }
    126.             CGPROGRAM
    127.             #pragma vertex vert
    128.             #pragma fragment frag
    129.             #define UNITY_PASS_FORWARDADD
    130.             #include "UnityCG.cginc"
    131.             #include "AutoLight.cginc"
    132.             #pragma multi_compile_fwdadd_fullshadows
    133.             #pragma exclude_renderers xbox360 ps3 flash d3d11_9x
    134.             #pragma target 3.0
    135.             uniform float4 _LightColor0;
    136.             uniform sampler2D _GrabTexture;
    137.             uniform sampler2D _Texturemap; uniform float4 _Texturemap_ST;
    138.             uniform sampler2D _Normaldistortion; uniform float4 _Normaldistortion_ST;
    139.             uniform float _Distortion;
    140.             uniform float _Specular;
    141.             struct VertexInput {
    142.                 float4 vertex : POSITION;
    143.                 float3 normal : NORMAL;
    144.                 float4 tangent : TANGENT;
    145.                 float4 uv0 : TEXCOORD0;
    146.             };
    147.             struct VertexOutput {
    148.                 float4 pos : SV_POSITION;
    149.                 float4 uv0 : TEXCOORD0;
    150.                 float4 posWorld : TEXCOORD1;
    151.                 float3 normalDir : TEXCOORD2;
    152.                 float3 tangentDir : TEXCOORD3;
    153.                 float3 binormalDir : TEXCOORD4;
    154.                 float4 screenPos : TEXCOORD5;
    155.                 LIGHTING_COORDS(6,7)
    156.             };
    157.             VertexOutput vert (VertexInput v) {
    158.                 VertexOutput o;
    159.                 o.uv0 = v.uv0;
    160.                 o.normalDir = mul(float4(v.normal,0), _World2Object).xyz;
    161.                 o.tangentDir = normalize( mul( _Object2World, float4( v.tangent.xyz, 0.0 ) ).xyz );
    162.                 o.binormalDir = normalize(cross(o.normalDir, o.tangentDir) * v.tangent.w);
    163.                 o.posWorld = mul(_Object2World, v.vertex);
    164.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    165.                 o.screenPos = o.pos;
    166.                 TRANSFER_VERTEX_TO_FRAGMENT(o)
    167.                 return o;
    168.             }
    169.             fixed4 frag(VertexOutput i) : COLOR {
    170.                 #if UNITY_UV_STARTS_AT_TOP
    171.                     float grabSign = -_ProjectionParams.x;
    172.                 #else
    173.                     float grabSign = _ProjectionParams.x;
    174.                 #endif
    175.                 i.normalDir = normalize(i.normalDir);
    176.                 float3x3 tangentTransform = float3x3( i.tangentDir, i.binormalDir, i.normalDir);
    177.                 float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
    178. /////// Normals:
    179.                 float2 node_2632 = i.uv0;
    180.                 float3 node_2301 = UnpackNormal(tex2D(_Normaldistortion,TRANSFORM_TEX(node_2632.rg, _Normaldistortion)));
    181.                 float3 normalLocal = node_2301.rgb;
    182.                 float3 normalDirection =  normalize(mul( normalLocal, tangentTransform )); // Perturbed normals
    183.                 i.screenPos = float4( i.screenPos.xy / i.screenPos.w, 0, 0 );
    184.                 i.screenPos.y *= _ProjectionParams.x;
    185.                 float2 sceneUVs = float2(1,grabSign)*i.screenPos.xy*0.5+0.5 + (node_2301.rgb.rg*_Distortion);
    186.                 float4 sceneColor = tex2D(_GrabTexture, sceneUVs);
    187.                 float3 lightDirection = normalize(lerp(_WorldSpaceLightPos0.xyz, _WorldSpaceLightPos0.xyz - i.posWorld.xyz,_WorldSpaceLightPos0.w));
    188. ////// Lighting:
    189.                 float attenuation = LIGHT_ATTENUATION(i);
    190.                 float3 attenColor = attenuation * _LightColor0.xyz;
    191. /////// Diffuse:
    192.                 float NdotL = dot( normalDirection, lightDirection );
    193.                 float3 diffuse = max( 0.0, NdotL) * attenColor;
    194. ///////// Gloss:
    195.                 float node_2616 = _Specular;
    196.                 float gloss = exp2(pow(1.0-max(0,dot(normalDirection, viewDirection)),node_2616)*10.0+1.0);
    197. ////// Specular:
    198.                 NdotL = max(0.0, NdotL);
    199.                 float3 specularColor = float3(node_2616,node_2616,node_2616);
    200.                 float3 specular = attenColor * pow(max(0,dot(reflect(-lightDirection, normalDirection),viewDirection)),gloss) * specularColor;
    201.                 float3 finalColor = 0;
    202.                 float3 diffuseLight = diffuse;
    203.                 finalColor += diffuseLight * tex2D(_Texturemap,TRANSFORM_TEX(node_2632.rg, _Texturemap)).rgb;
    204.                 finalColor += specular;
    205. /// Final Color:
    206.                 return fixed4(finalColor * 1,0);
    207.             }
    208.             ENDCG
    209.         }
    210.     }
    211.     FallBack "Diffuse"
    212.     CustomEditor "ShaderForgeMaterialInspector"
    213. }
    214.  
    215. }
     
  5. Chaoss

    Chaoss

    Joined:
    Jul 8, 2011
    Posts:
    327
    Ah that works, but it doesn't take the direction of the object into account, as in a vertical wall doesn't reflect the environment as it should.
     
  6. J_P_

    J_P_

    Joined:
    Jan 9, 2010
    Posts:
    1,027
    Is this still supposed to work? Right click just brings up the right click menu for me.
     
  7. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,174
    Are you holding alt first?
     
  8. anton1987ru

    anton1987ru

    Joined:
    Nov 16, 2012
    Posts:
    15
    Hm try this Shader , this give you better result.
    Code (CSharp):
    1. // Shader created with Shader Forge Beta 0.34
    2. // Shader Forge (c) Joachim Holmer - http://www.acegikmo.com/shaderforge/
    3. // Note: Manually altering this data may prevent you from opening it in Shader Forge
    4. /*SF_DATA;ver:0.34;sub:START;pass:START;ps:flbk:,lico:1,lgpr:1,nrmq:0,limd:3,uamb:True,mssp:False,lmpd:False,lprd:False,enco:False,frtr:True,vitr:True,dbil:False,rmgx:True,rpth:0,hqsc:True,hqlp:False,blpr:0,bsrc:0,bdst:0,culm:0,dpts:2,wrdp:True,ufog:False,aust:False,igpj:False,qofs:0,qpre:4,rntp:1,fgom:True,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:1,x:32719,y:32712|diff-2-RGB,spec-705-OUT,gloss-727-OUT,normal-86-RGB,amdfl-661-OUT,amspl-643-OUT;n:type:ShaderForge.SFN_Tex2d,id:2,x:33277,y:32478,ptlb:Texture,ptin:_Texture,tex:b66bceaf0cc0ace4e9bdc92f14bba709,ntxv:0,isnm:False;n:type:ShaderForge.SFN_Multiply,id:16,x:33680,y:32602|A-18-OUT,B-17-OUT;n:type:ShaderForge.SFN_ToggleProperty,id:17,x:33910,y:32691,ptlb:Gloss,ptin:_Gloss,on:True;n:type:ShaderForge.SFN_Slider,id:18,x:33896,y:32598,ptlb:Glossnes,ptin:_Glossnes,min:0,cur:0.2621359,max:1;n:type:ShaderForge.SFN_Tex2d,id:86,x:33688,y:32785,ptlb:Normal,ptin:_Normal,ntxv:3,isnm:True;n:type:ShaderForge.SFN_SceneColor,id:144,x:33634,y:33074|UVIN-154-OUT;n:type:ShaderForge.SFN_Append,id:154,x:33834,y:33068|A-164-U,B-314-OUT;n:type:ShaderForge.SFN_Transform,id:156,x:35461,y:33246,tffrom:3,tfto:1|IN-219-OUT;n:type:ShaderForge.SFN_ComponentMask,id:157,x:35193,y:33327,cc1:1,cc2:-1,cc3:-1,cc4:-1|IN-156-XYZ;n:type:ShaderForge.SFN_Negate,id:158,x:34996,y:33255|IN-157-OUT;n:type:ShaderForge.SFN_Panner,id:159,x:34797,y:33171,spu:0,spv:2|UVIN-161-OUT,DIST-158-OUT;n:type:ShaderForge.SFN_ComponentMask,id:160,x:34614,y:33171,cc1:1,cc2:-1,cc3:-1,cc4:-1|IN-159-UVOUT;n:type:ShaderForge.SFN_Append,id:161,x:35000,y:33114|A-164-U,B-162-OUT;n:type:ShaderForge.SFN_OneMinus,id:162,x:35322,y:33102|IN-164-V;n:type:ShaderForge.SFN_ScreenPos,id:164,x:35571,y:32913,sctp:2;n:type:ShaderForge.SFN_Tangent,id:219,x:35679,y:33175;n:type:ShaderForge.SFN_Fresnel,id:238,x:34429,y:33150|EXP-160-OUT;n:type:ShaderForge.SFN_OneMinus,id:313,x:34241,y:33191|IN-238-OUT;n:type:ShaderForge.SFN_Append,id:314,x:34051,y:33162|A-238-OUT,B-313-OUT;n:type:ShaderForge.SFN_Binormal,id:417,x:36270,y:33238;n:type:ShaderForge.SFN_ViewVector,id:438,x:36602,y:32973;n:type:ShaderForge.SFN_Slider,id:642,x:33147,y:33286,ptlb:specular reflections,ptin:_specularreflections,min:0,cur:0.1456311,max:1;n:type:ShaderForge.SFN_Multiply,id:643,x:33033,y:33038|A-144-RGB,B-642-OUT,C-687-OUT;n:type:ShaderForge.SFN_Multiply,id:661,x:33038,y:32910|A-662-OUT,B-144-RGB,C-687-OUT;n:type:ShaderForge.SFN_Slider,id:662,x:33296,y:32908,ptlb:Diffuse reflect,ptin:_Diffusereflect,min:0,cur:0.6213592,max:1;n:type:ShaderForge.SFN_ToggleProperty,id:687,x:33378,y:33145,ptlb:Activate Reflections,ptin:_ActivateReflections,on:True;n:type:ShaderForge.SFN_Slider,id:705,x:33220,y:32699,ptlb:Specular,ptin:_Specular,min:0,cur:0.6796116,max:1;n:type:ShaderForge.SFN_Fresnel,id:727,x:33515,y:32541|EXP-16-OUT;proporder:2-86-705-17-18-687-642-662;pass:END;sub:END;*/
    5.  
    6. Shader "Antony Shaders/Screen Space Fernel Reflections beta" {
    7.     Properties {
    8.         _Texture ("Texture", 2D) = "white" {}
    9.         _Normal ("Normal", 2D) = "bump" {}
    10.         _Specular ("Specular", Range(0, 1)) = 0.6796116
    11.         [MaterialToggle] _Gloss ("Gloss", Float ) = 0
    12.         _Glossnes ("Glossnes", Range(0, 1)) = 0.2621359
    13.         [MaterialToggle] _ActivateReflections ("Activate Reflections", Float ) = 0
    14.         _specularreflections ("specular reflections", Range(0, 1)) = 0.1456311
    15.         _Diffusereflect ("Diffuse reflect", Range(0, 1)) = 0.6213592
    16.     }
    17.     SubShader {
    18.         Tags {
    19.             "Queue"="Overlay"
    20.             "RenderType"="Opaque"
    21.         }
    22.         LOD 200
    23.         GrabPass{ }
    24.         Pass {
    25.             Name "ForwardBase"
    26.             Tags {
    27.                 "LightMode"="ForwardBase"
    28.             }
    29.          
    30.          
    31.             Fog {Mode Off}
    32.             CGPROGRAM
    33.             #pragma vertex vert
    34.             #pragma fragment frag
    35.             #define UNITY_PASS_FORWARDBASE
    36.             #include "UnityCG.cginc"
    37.             #include "AutoLight.cginc"
    38.             #pragma multi_compile_fwdbase_fullshadows
    39.             #pragma exclude_renderers xbox360 ps3 flash d3d11_9x
    40.             #pragma target 3.0
    41.             uniform float4 _LightColor0;
    42.             uniform sampler2D _GrabTexture;
    43.             uniform sampler2D _Texture; uniform float4 _Texture_ST;
    44.             uniform fixed _Gloss;
    45.             uniform float _Glossnes;
    46.             uniform sampler2D _Normal; uniform float4 _Normal_ST;
    47.             uniform float _specularreflections;
    48.             uniform float _Diffusereflect;
    49.             uniform fixed _ActivateReflections;
    50.             uniform float _Specular;
    51.             struct VertexInput {
    52.                 float4 vertex : POSITION;
    53.                 float3 normal : NORMAL;
    54.                 float4 tangent : TANGENT;
    55.                 float2 texcoord0 : TEXCOORD0;
    56.             };
    57.             struct VertexOutput {
    58.                 float4 pos : SV_POSITION;
    59.                 float2 uv0 : TEXCOORD0;
    60.                 float4 posWorld : TEXCOORD1;
    61.                 float3 normalDir : TEXCOORD2;
    62.                 float3 tangentDir : TEXCOORD3;
    63.                 float3 binormalDir : TEXCOORD4;
    64.                 float4 screenPos : TEXCOORD5;
    65.                 LIGHTING_COORDS(6,7)
    66.             };
    67.             VertexOutput vert (VertexInput v) {
    68.                 VertexOutput o;
    69.                 o.uv0 = v.texcoord0;
    70.                 o.normalDir = mul(float4(v.normal,0), _World2Object).xyz;
    71.                 o.tangentDir = normalize( mul( _Object2World, float4( v.tangent.xyz, 0.0 ) ).xyz );
    72.                 o.binormalDir = normalize(cross(o.normalDir, o.tangentDir) * v.tangent.w);
    73.                 o.posWorld = mul(_Object2World, v.vertex);
    74.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    75.                 o.screenPos = o.pos;
    76.                 TRANSFER_VERTEX_TO_FRAGMENT(o)
    77.                 return o;
    78.             }
    79.             fixed4 frag(VertexOutput i) : COLOR {
    80.                 #if UNITY_UV_STARTS_AT_TOP
    81.                     float grabSign = -_ProjectionParams.x;
    82.                 #else
    83.                     float grabSign = _ProjectionParams.x;
    84.                 #endif
    85.                 float3x3 tangentTransform = float3x3( i.tangentDir, i.binormalDir, i.normalDir);
    86.                 float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
    87. /////// Normals:
    88.                 float2 node_847 = i.uv0;
    89.                 float3 normalLocal = UnpackNormal(tex2D(_Normal,TRANSFORM_TEX(node_847.rg, _Normal))).rgb;
    90.                 float3 normalDirection =  normalize(mul( normalLocal, tangentTransform )); // Perturbed normals
    91.                 i.screenPos = float4( i.screenPos.xy / i.screenPos.w, 0, 0 );
    92.                 i.screenPos.y *= _ProjectionParams.x;
    93.                 float2 sceneUVs = float2(1,grabSign)*i.screenPos.xy*0.5+0.5;
    94.                 float4 sceneColor = tex2D(_GrabTexture, sceneUVs);
    95.                 float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz);
    96.                 float3 halfDirection = normalize(viewDirection+lightDirection);
    97. ////// Lighting:
    98.                 float attenuation = LIGHT_ATTENUATION(i);
    99.                 float3 attenColor = attenuation * _LightColor0.xyz;
    100.                 float Pi = 3.141592654;
    101.                 float InvPi = 0.31830988618;
    102. /////// Diffuse:
    103.                 float NdotL = dot( normalDirection, lightDirection );
    104.                 float3 diffuse = max( 0.0, NdotL)*InvPi * attenColor + UNITY_LIGHTMODEL_AMBIENT.rgb;
    105. ///////// Gloss:
    106.                 float gloss = pow(1.0-max(0,dot(normalDirection, viewDirection)),(_Glossnes*_Gloss));
    107.                 float specPow = exp2( gloss * 10.0+1.0);
    108. ////// Specular:
    109.                 NdotL = max(0.0, NdotL);
    110.                 float2 node_164 = sceneUVs;
    111.                 float node_238 = pow(1.0-max(0,dot(normalDirection, viewDirection)),(float2(node_164.r,(1.0 - node_164.g))+(-1*mul( float4(i.tangentDir,0), UNITY_MATRIX_MV ).xyz.rgb.g)*float2(0,2)).g);
    112.                 float4 node_144 = tex2D(_GrabTexture, float3(node_164.r,float2(node_238,(1.0 - node_238))));
    113.                 float3 specularColor = float3(_Specular,_Specular,_Specular);
    114.                 float specularMonochrome = dot(specularColor,float3(0.3,0.59,0.11));
    115.                 float HdotL = max(0.0,dot(halfDirection,lightDirection));
    116.                 float3 fresnelTerm = specularColor + ( 1.0 - specularColor ) * pow((1.0 - HdotL),5);
    117.                 float NdotV = max(0.0,dot( normalDirection, viewDirection ));
    118.                 float3 fresnelTermAmb = specularColor + ( 1.0 - specularColor ) * ( pow((1.0 - NdotV),5) / (4-3*gloss) );
    119.                 float alpha = 1.0 / ( sqrt( (Pi/4.0) * specPow + Pi/2.0 ) );
    120.                 float visTerm = ( NdotL * ( 1.0 - alpha ) + alpha ) * ( NdotV * ( 1.0 - alpha ) + alpha );
    121.                 visTerm = 1.0 / visTerm;
    122.                 float normTerm = (specPow + 8.0 ) / (8.0 * Pi);
    123.                 float3 specularAmb = (node_144.rgb*_specularreflections*_ActivateReflections) * fresnelTermAmb;
    124.                 float3 specular = attenColor*NdotL * pow(max(0,dot(halfDirection,normalDirection)),specPow)*fresnelTerm*visTerm*normTerm + specularAmb;
    125.                 float3 finalColor = 0;
    126.                 float3 diffuseLight = diffuse;
    127.                 diffuseLight += (_Diffusereflect*node_144.rgb*_ActivateReflections); // Diffuse Ambient Light
    128.                 diffuseLight *= 1-specularMonochrome;
    129.                 finalColor += diffuseLight * tex2D(_Texture,TRANSFORM_TEX(node_847.rg, _Texture)).rgb;
    130.                 finalColor += specular;
    131. /// Final Color:
    132.                 return fixed4(finalColor,1);
    133.             }
    134.             ENDCG
    135.         }
    136.         Pass {
    137.             Name "ForwardAdd"
    138.             Tags {
    139.                 "LightMode"="ForwardAdd"
    140.             }
    141.             Blend One One
    142.          
    143.          
    144.             Fog { Color (0,0,0,0) }
    145.             CGPROGRAM
    146.             #pragma vertex vert
    147.             #pragma fragment frag
    148.             #define UNITY_PASS_FORWARDADD
    149.             #include "UnityCG.cginc"
    150.             #include "AutoLight.cginc"
    151.             #pragma multi_compile_fwdadd_fullshadows
    152.             #pragma exclude_renderers xbox360 ps3 flash d3d11_9x
    153.             #pragma target 3.0
    154.             uniform float4 _LightColor0;
    155.             uniform sampler2D _Texture; uniform float4 _Texture_ST;
    156.             uniform fixed _Gloss;
    157.             uniform float _Glossnes;
    158.             uniform sampler2D _Normal; uniform float4 _Normal_ST;
    159.             uniform float _Specular;
    160.             struct VertexInput {
    161.                 float4 vertex : POSITION;
    162.                 float3 normal : NORMAL;
    163.                 float4 tangent : TANGENT;
    164.                 float2 texcoord0 : TEXCOORD0;
    165.             };
    166.             struct VertexOutput {
    167.                 float4 pos : SV_POSITION;
    168.                 float2 uv0 : TEXCOORD0;
    169.                 float4 posWorld : TEXCOORD1;
    170.                 float3 normalDir : TEXCOORD2;
    171.                 float3 tangentDir : TEXCOORD3;
    172.                 float3 binormalDir : TEXCOORD4;
    173.                 LIGHTING_COORDS(5,6)
    174.             };
    175.             VertexOutput vert (VertexInput v) {
    176.                 VertexOutput o;
    177.                 o.uv0 = v.texcoord0;
    178.                 o.normalDir = mul(float4(v.normal,0), _World2Object).xyz;
    179.                 o.tangentDir = normalize( mul( _Object2World, float4( v.tangent.xyz, 0.0 ) ).xyz );
    180.                 o.binormalDir = normalize(cross(o.normalDir, o.tangentDir) * v.tangent.w);
    181.                 o.posWorld = mul(_Object2World, v.vertex);
    182.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    183.                 TRANSFER_VERTEX_TO_FRAGMENT(o)
    184.                 return o;
    185.             }
    186.             fixed4 frag(VertexOutput i) : COLOR {
    187.                 float3x3 tangentTransform = float3x3( i.tangentDir, i.binormalDir, i.normalDir);
    188.                 float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
    189. /////// Normals:
    190.                 float2 node_848 = i.uv0;
    191.                 float3 normalLocal = UnpackNormal(tex2D(_Normal,TRANSFORM_TEX(node_848.rg, _Normal))).rgb;
    192.                 float3 normalDirection =  normalize(mul( normalLocal, tangentTransform )); // Perturbed normals
    193.                 float3 lightDirection = normalize(lerp(_WorldSpaceLightPos0.xyz, _WorldSpaceLightPos0.xyz - i.posWorld.xyz,_WorldSpaceLightPos0.w));
    194.                 float3 halfDirection = normalize(viewDirection+lightDirection);
    195. ////// Lighting:
    196.                 float attenuation = LIGHT_ATTENUATION(i);
    197.                 float3 attenColor = attenuation * _LightColor0.xyz;
    198.                 float Pi = 3.141592654;
    199.                 float InvPi = 0.31830988618;
    200. /////// Diffuse:
    201.                 float NdotL = dot( normalDirection, lightDirection );
    202.                 float3 diffuse = max( 0.0, NdotL)*InvPi * attenColor;
    203. ///////// Gloss:
    204.                 float gloss = pow(1.0-max(0,dot(normalDirection, viewDirection)),(_Glossnes*_Gloss));
    205.                 float specPow = exp2( gloss * 10.0+1.0);
    206. ////// Specular:
    207.                 NdotL = max(0.0, NdotL);
    208.                 float3 specularColor = float3(_Specular,_Specular,_Specular);
    209.                 float specularMonochrome = dot(specularColor,float3(0.3,0.59,0.11));
    210.                 float HdotL = max(0.0,dot(halfDirection,lightDirection));
    211.                 float3 fresnelTerm = specularColor + ( 1.0 - specularColor ) * pow((1.0 - HdotL),5);
    212.                 float NdotV = max(0.0,dot( normalDirection, viewDirection ));
    213.                 float alpha = 1.0 / ( sqrt( (Pi/4.0) * specPow + Pi/2.0 ) );
    214.                 float visTerm = ( NdotL * ( 1.0 - alpha ) + alpha ) * ( NdotV * ( 1.0 - alpha ) + alpha );
    215.                 visTerm = 1.0 / visTerm;
    216.                 float normTerm = (specPow + 8.0 ) / (8.0 * Pi);
    217.                 float3 specular = attenColor*NdotL * pow(max(0,dot(halfDirection,normalDirection)),specPow)*fresnelTerm*visTerm*normTerm;
    218.                 float3 finalColor = 0;
    219.                 float3 diffuseLight = diffuse;
    220.                 diffuseLight *= 1-specularMonochrome;
    221.                 finalColor += diffuseLight * tex2D(_Texture,TRANSFORM_TEX(node_848.rg, _Texture)).rgb;
    222.                 finalColor += specular;
    223. /// Final Color:
    224.                 return fixed4(finalColor * 1,0);
    225.             }
    226.             ENDCG
    227.         }
    228.     }
    229.     FallBack "Diffuse"
    230.     CustomEditor "ShaderForgeMaterialInspector"
    231. }
    232.  
     
  9. Chaoss

    Chaoss

    Joined:
    Jul 8, 2011
    Posts:
    327
    I tried
    I tried this but the reflections looked really warped
     
  10. anton1987ru

    anton1987ru

    Joined:
    Nov 16, 2012
    Posts:
    15
    Finaly i create normal projection SSR with non planar support reflection :D:) :rolleyes: YEAHH!!!
     
    Last edited: Jun 9, 2014
  11. Chaoss

    Chaoss

    Joined:
    Jul 8, 2011
    Posts:
    327
    Your solution looks ok, but does it work on walls? also in the video the reflections 'warp' quite a lot whereas other solutions have no such issue
     
    Play_Edu likes this.
  12. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Not yet, I've been very busy with things lately. I'll see if I can get it in soon. Part of the problem is that having that sort of requires you to have even more inputs into the main node, which may become a bit too cluttered after a while. But I'll see if I can have another look at it soon.


    There's currently no cubemap asset node, but it is a requested feature that may come at some point. You might be able to hack something into the code node though :)
    http://shaderforge.userecho.com/topic/298042-cubemap-support-for-texture-asset-node/


    Customizing the lights in the preview window is also quite a requested feature. We'll see what happens there down the line, but it's not a very high-prio thing. Also: http://shaderforge.userecho.com/topic/251159-move-the-light-source-in-the-preview-window/

    Disconnected display name/internal name may come at some point: http://shaderforge.userecho.com/topic/309545-property-display-names-different-to-variable-names/


    The instruction counter depends on what your shader does and which is your target platform. Some platforms and features don't provide sensible instruction count data.

    You need to enable both D3D 11 RT as well as making sure Shader Model 2.0 forcing is on in the experimental settings
     
  13. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    $80 is the discounted price as it is :)

    Exactly. This is a limitation of the deferred pre-pass system. You may be able to hack it into a custom deferred lighting solution, but that makes *all* deferred shaders use half-lambert

    I'm here! Sorry for the late response, I've been quite busy these last few weeks :)
     
  14. nrlnd

    nrlnd

    Joined:
    Mar 13, 2012
    Posts:
    12
    Well i am more of an visual artist (ei not that much of a coder) i am noodle based ; )
    It's true as you say i also had a chat with the developer of unity/syphon bridge and it would be hard to implement into sf.
    But it works if you go scripting. Would had been wonderful was to have a input node for the incoming syphon stream
    into sf so you could assign the textures to different nodes bump spec etc without entering any code.

    "Or do you want support for render textures that receive images via Syphon - which in turn would be used by a shader to map that image onto whatever 3d-object of your choice?"

    Yes this is exactly what i am up to. So well . If you had a syphon node you would be able to hook it up to cubemap , spec, emission .. etc As you say you can do this with script now. I am being lazy thats all ; )


    http://vdmx.vidvox.net/blog/behind-the-scenes-of-data-by-wolfshirt

    Thanks for the fast response : )


     
  15. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Hi sorry I'm late but regarding branching - POW is really, really expensive on mobile hardware so the best equivalent to if on a gpu is always step where possible. If you can rework to using step, it's practically free.
     
  16. bmccall1

    bmccall1

    Joined:
    Jul 28, 2013
    Posts:
    120
    No problem! Your community spoke very highly of you and I bought the asset last friday. Unfortunately I haven't had a chance to play with it because I'm buried in inventory guis. Basically the polar opposite of playing with cool graphics :(
     
  17. anton1987ru

    anton1987ru

    Joined:
    Nov 16, 2012
    Posts:
    15
    yes , i try fix wall problem and warp effect in next update . btw here is the code
    Code (CSharp):
    1. // Shader created with Shader Forge Beta 0.34
    2. // Shader Forge (c) Joachim Holmer - http://www.acegikmo.com/shaderforge/
    3. // Note: Manually altering this data may prevent you from opening it in Shader Forge
    4. /*SF_DATA;ver:0.34;sub:START;pass:START;ps:flbk:,lico:1,lgpr:1,nrmq:1,limd:1,uamb:True,mssp:True,lmpd:False,lprd:False,enco:False,frtr:False,vitr:False,dbil:False,rmgx:True,rpth:0,hqsc:True,hqlp:False,blpr:0,bsrc:0,bdst:0,culm:0,dpts:2,wrdp:True,ufog:False,aust:False,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:1,x:32166,y:32683|diff-73-RGB,spec-75-OUT,gloss-75-OUT,normal-70-RGB,amdfl-831-OUT,amspl-840-OUT,refract-134-OUT;n:type:ShaderForge.SFN_Transform,id:32,x:35219,y:33384,tffrom:3,tfto:0|IN-159-OUT;n:type:ShaderForge.SFN_ComponentMask,id:33,x:35047,y:33384,cc1:1,cc2:-1,cc3:-1,cc4:-1|IN-32-XYZ;n:type:ShaderForge.SFN_SceneColor,id:34,x:33185,y:33110|UVIN-40-OUT;n:type:ShaderForge.SFN_OneMinus,id:36,x:35446,y:33121|IN-50-OUT;n:type:ShaderForge.SFN_Append,id:37,x:35074,y:33107|A-44-V,B-36-OUT;n:type:ShaderForge.SFN_Panner,id:38,x:34700,y:33148,spu:0,spv:2|UVIN-37-OUT,DIST-33-OUT;n:type:ShaderForge.SFN_ComponentMask,id:39,x:34207,y:33145,cc1:0,cc2:-1,cc3:-1,cc4:-1|IN-1377-OUT;n:type:ShaderForge.SFN_Append,id:40,x:33968,y:33100|A-44-U,B-39-OUT;n:type:ShaderForge.SFN_ScreenPos,id:44,x:35893,y:32912,sctp:2;n:type:ShaderForge.SFN_ViewVector,id:45,x:35831,y:33293;n:type:ShaderForge.SFN_Negate,id:46,x:35639,y:33293|IN-45-OUT;n:type:ShaderForge.SFN_Fresnel,id:50,x:35689,y:33121|EXP-44-V;n:type:ShaderForge.SFN_Tex2d,id:70,x:34084,y:32530,ptlb:norm,ptin:_norm,tex:bbab0a6f7bae9cf42bf057d8ee2755f6,ntxv:3,isnm:True;n:type:ShaderForge.SFN_Tex2d,id:73,x:33841,y:32334,ptlb:tex,ptin:_tex,tex:b66bceaf0cc0ace4e9bdc92f14bba709,ntxv:0,isnm:False;n:type:ShaderForge.SFN_Fresnel,id:75,x:33053,y:32502|EXP-77-OUT;n:type:ShaderForge.SFN_Slider,id:77,x:33242,y:32528,ptlb:Gloss,ptin:_Gloss,min:0,cur:3.932331,max:10;n:type:ShaderForge.SFN_ComponentMask,id:112,x:33651,y:32756,cc1:0,cc2:1,cc3:2,cc4:-1|IN-942-OUT;n:type:ShaderForge.SFN_Slider,id:133,x:33595,y:32940,ptlb:Distortion,ptin:_Distortion,min:0,cur:0.5263158,max:1;n:type:ShaderForge.SFN_Multiply,id:134,x:33266,y:32807|A-112-OUT,B-133-OUT;n:type:ShaderForge.SFN_NormalVector,id:158,x:35831,y:33492,pt:False;n:type:ShaderForge.SFN_Multiply,id:159,x:35430,y:33401|A-46-OUT,B-166-OUT;n:type:ShaderForge.SFN_Negate,id:166,x:35639,y:33492|IN-158-OUT;n:type:ShaderForge.SFN_Slider,id:724,x:32615,y:33037,ptlb:Specular reflecion,ptin:_Specularreflecion,min:0,cur:1,max:1;n:type:ShaderForge.SFN_Slider,id:731,x:32609,y:32681,ptlb:Diffuse Reflection,ptin:_DiffuseReflection,min:0,cur:0.3609022,max:1;n:type:ShaderForge.SFN_ToggleProperty,id:732,x:32937,y:32746,ptlb:Activate reflections,ptin:_Activatereflections,on:True;n:type:ShaderForge.SFN_Multiply,id:734,x:32755,y:32786|A-732-OUT,B-34-RGB;n:type:ShaderForge.SFN_Multiply,id:831,x:32496,y:32762|A-734-OUT,B-731-OUT;n:type:ShaderForge.SFN_Multiply,id:840,x:32496,y:32892|A-734-OUT,B-724-OUT;n:type:ShaderForge.SFN_Multiply,id:942,x:33836,y:32631|A-70-RGB,B-949-OUT;n:type:ShaderForge.SFN_ToggleProperty,id:949,x:34030,y:32750,ptlb:Normal map activator,ptin:_Normalmapactivator,on:True;n:type:ShaderForge.SFN_Frac,id:1342,x:34619,y:33372|IN-1362-OUT;n:type:ShaderForge.SFN_ValueProperty,id:1362,x:34830,y:33475,ptlb:Depth kernel,ptin:_Depthkernel,glob:False,v1:0.69;n:type:ShaderForge.SFN_Dot,id:1377,x:34407,y:33228,dt:1|A-38-UVOUT,B-1342-OUT;proporder:73-70-949-77-133-732-731-724-1362;pass:END;sub:END;*/
    5.  
    6. Shader "Custom/Mirror" {
    7.     Properties {
    8.         _tex ("tex", 2D) = "white" {}
    9.         _norm ("norm", 2D) = "bump" {}
    10.         [MaterialToggle] _Normalmapactivator ("Normal map activator", Float ) = 0
    11.         _Gloss ("Gloss", Range(0, 10)) = 3.932331
    12.         _Distortion ("Distortion", Range(0, 1)) = 0.5263158
    13.         [MaterialToggle] _Activatereflections ("Activate reflections", Float ) = 0
    14.         _DiffuseReflection ("Diffuse Reflection", Range(0, 1)) = 0.3609022
    15.         _Specularreflecion ("Specular reflecion", Range(0, 1)) = 1
    16.         _Depthkernel ("Depth kernel", Float ) = 0.69
    17.     }
    18.     SubShader {
    19.         Tags {
    20.             "RenderType"="Opaque"
    21.         }
    22.         LOD 200
    23.         GrabPass{ }
    24.         Pass {
    25.             Name "ForwardBase"
    26.             Tags {
    27.                 "LightMode"="ForwardBase"
    28.             }
    29.            
    30.            
    31.             Fog {Mode Off}
    32.             CGPROGRAM
    33.             #pragma vertex vert
    34.             #pragma fragment frag
    35.             #define UNITY_PASS_FORWARDBASE
    36.             #include "UnityCG.cginc"
    37.             #include "AutoLight.cginc"
    38.             #pragma multi_compile_fwdbase_fullshadows
    39.             #pragma exclude_renderers xbox360 ps3 flash d3d11_9x
    40.             #pragma target 3.0
    41.             uniform float4 _LightColor0;
    42.             uniform sampler2D _GrabTexture;
    43.             uniform sampler2D _norm; uniform float4 _norm_ST;
    44.             uniform sampler2D _tex; uniform float4 _tex_ST;
    45.             uniform float _Gloss;
    46.             uniform float _Distortion;
    47.             uniform float _Specularreflecion;
    48.             uniform float _DiffuseReflection;
    49.             uniform fixed _Activatereflections;
    50.             uniform fixed _Normalmapactivator;
    51.             uniform float _Depthkernel;
    52.             struct VertexInput {
    53.                 float4 vertex : POSITION;
    54.                 float3 normal : NORMAL;
    55.                 float4 tangent : TANGENT;
    56.                 float2 texcoord0 : TEXCOORD0;
    57.             };
    58.             struct VertexOutput {
    59.                 float4 pos : SV_POSITION;
    60.                 float2 uv0 : TEXCOORD0;
    61.                 float4 posWorld : TEXCOORD1;
    62.                 float3 normalDir : TEXCOORD2;
    63.                 float3 tangentDir : TEXCOORD3;
    64.                 float3 binormalDir : TEXCOORD4;
    65.                 float4 screenPos : TEXCOORD5;
    66.                 LIGHTING_COORDS(6,7)
    67.             };
    68.             VertexOutput vert (VertexInput v) {
    69.                 VertexOutput o;
    70.                 o.uv0 = v.texcoord0;
    71.                 o.normalDir = mul(float4(v.normal,0), _World2Object).xyz;
    72.                 o.tangentDir = normalize( mul( _Object2World, float4( v.tangent.xyz, 0.0 ) ).xyz );
    73.                 o.binormalDir = normalize(cross(o.normalDir, o.tangentDir) * v.tangent.w);
    74.                 o.posWorld = mul(_Object2World, v.vertex);
    75.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    76.                 o.screenPos = o.pos;
    77.                 TRANSFER_VERTEX_TO_FRAGMENT(o)
    78.                 return o;
    79.             }
    80.             fixed4 frag(VertexOutput i) : COLOR {
    81.                 #if UNITY_UV_STARTS_AT_TOP
    82.                     float grabSign = -_ProjectionParams.x;
    83.                 #else
    84.                     float grabSign = _ProjectionParams.x;
    85.                 #endif
    86.                 i.normalDir = normalize(i.normalDir);
    87.                 float3x3 tangentTransform = float3x3( i.tangentDir, i.binormalDir, i.normalDir);
    88.                 float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
    89. /////// Normals:
    90.                 float2 node_1390 = i.uv0;
    91.                 float3 node_70 = UnpackNormal(tex2D(_norm,TRANSFORM_TEX(node_1390.rg, _norm)));
    92.                 float3 normalLocal = node_70.rgb;
    93.                 float3 normalDirection =  normalize(mul( normalLocal, tangentTransform )); // Perturbed normals
    94.                 i.screenPos = float4( i.screenPos.xy / i.screenPos.w, 0, 0 );
    95.                 i.screenPos.y *= _ProjectionParams.x;
    96.                 float2 sceneUVs = float2(1,grabSign)*i.screenPos.xy*0.5+0.5 + ((node_70.rgb*_Normalmapactivator).rgb*_Distortion).rg;
    97.                 float4 sceneColor = tex2D(_GrabTexture, sceneUVs);
    98.                 float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz);
    99.                 float3 halfDirection = normalize(viewDirection+lightDirection);
    100. ////// Lighting:
    101.                 float attenuation = LIGHT_ATTENUATION(i);
    102.                 float3 attenColor = attenuation * _LightColor0.xyz;
    103. /////// Diffuse:
    104.                 float NdotL = dot( normalDirection, lightDirection );
    105.                 float3 diffuse = max( 0.0, NdotL) * attenColor + UNITY_LIGHTMODEL_AMBIENT.rgb;
    106. ///////// Gloss:
    107.                 float node_75 = pow(1.0-max(0,dot(normalDirection, viewDirection)),_Gloss);
    108.                 float gloss = node_75;
    109.                 float specPow = exp2( gloss * 10.0+1.0);
    110. ////// Specular:
    111.                 NdotL = max(0.0, NdotL);
    112.                 float2 node_44 = sceneUVs;
    113.                 float3 node_734 = (_Activatereflections*tex2D(_GrabTexture, float2(node_44.r,max(0,dot((float2(node_44.g,(1.0 - pow(1.0-max(0,dot(normalDirection, viewDirection)),node_44.g)))+mul( float4(((-1*viewDirection)*(-1*i.normalDir)),0), UNITY_MATRIX_V ).xyz.rgb.g*float2(0,2)),frac(_Depthkernel))).r)).rgb);
    114.                 float3 specularColor = float3(node_75,node_75,node_75);
    115.                 float3 specularAmb = (node_734*_Specularreflecion) * specularColor;
    116.                 float3 specular = (floor(attenuation) * _LightColor0.xyz) * pow(max(0,dot(halfDirection,normalDirection)),specPow) * specularColor + specularAmb;
    117.                 float3 finalColor = 0;
    118.                 float3 diffuseLight = diffuse;
    119.                 diffuseLight += (node_734*_DiffuseReflection); // Diffuse Ambient Light
    120.                 finalColor += diffuseLight * tex2D(_tex,TRANSFORM_TEX(node_1390.rg, _tex)).rgb;
    121.                 finalColor += specular;
    122. /// Final Color:
    123.                 return fixed4(lerp(sceneColor.rgb, finalColor,1),1);
    124.             }
    125.             ENDCG
    126.         }
    127.         Pass {
    128.             Name "ForwardAdd"
    129.             Tags {
    130.                 "LightMode"="ForwardAdd"
    131.             }
    132.             Blend One One
    133.            
    134.            
    135.             Fog { Color (0,0,0,0) }
    136.             CGPROGRAM
    137.             #pragma vertex vert
    138.             #pragma fragment frag
    139.             #define UNITY_PASS_FORWARDADD
    140.             #include "UnityCG.cginc"
    141.             #include "AutoLight.cginc"
    142.             #pragma multi_compile_fwdadd_fullshadows
    143.             #pragma exclude_renderers xbox360 ps3 flash d3d11_9x
    144.             #pragma target 3.0
    145.             uniform float4 _LightColor0;
    146.             uniform sampler2D _GrabTexture;
    147.             uniform sampler2D _norm; uniform float4 _norm_ST;
    148.             uniform sampler2D _tex; uniform float4 _tex_ST;
    149.             uniform float _Gloss;
    150.             uniform float _Distortion;
    151.             uniform fixed _Normalmapactivator;
    152.             struct VertexInput {
    153.                 float4 vertex : POSITION;
    154.                 float3 normal : NORMAL;
    155.                 float4 tangent : TANGENT;
    156.                 float2 texcoord0 : TEXCOORD0;
    157.             };
    158.             struct VertexOutput {
    159.                 float4 pos : SV_POSITION;
    160.                 float2 uv0 : TEXCOORD0;
    161.                 float4 posWorld : TEXCOORD1;
    162.                 float3 normalDir : TEXCOORD2;
    163.                 float3 tangentDir : TEXCOORD3;
    164.                 float3 binormalDir : TEXCOORD4;
    165.                 float4 screenPos : TEXCOORD5;
    166.                 LIGHTING_COORDS(6,7)
    167.             };
    168.             VertexOutput vert (VertexInput v) {
    169.                 VertexOutput o;
    170.                 o.uv0 = v.texcoord0;
    171.                 o.normalDir = mul(float4(v.normal,0), _World2Object).xyz;
    172.                 o.tangentDir = normalize( mul( _Object2World, float4( v.tangent.xyz, 0.0 ) ).xyz );
    173.                 o.binormalDir = normalize(cross(o.normalDir, o.tangentDir) * v.tangent.w);
    174.                 o.posWorld = mul(_Object2World, v.vertex);
    175.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    176.                 o.screenPos = o.pos;
    177.                 TRANSFER_VERTEX_TO_FRAGMENT(o)
    178.                 return o;
    179.             }
    180.             fixed4 frag(VertexOutput i) : COLOR {
    181.                 #if UNITY_UV_STARTS_AT_TOP
    182.                     float grabSign = -_ProjectionParams.x;
    183.                 #else
    184.                     float grabSign = _ProjectionParams.x;
    185.                 #endif
    186.                 i.normalDir = normalize(i.normalDir);
    187.                 float3x3 tangentTransform = float3x3( i.tangentDir, i.binormalDir, i.normalDir);
    188.                 float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
    189. /////// Normals:
    190.                 float2 node_1391 = i.uv0;
    191.                 float3 node_70 = UnpackNormal(tex2D(_norm,TRANSFORM_TEX(node_1391.rg, _norm)));
    192.                 float3 normalLocal = node_70.rgb;
    193.                 float3 normalDirection =  normalize(mul( normalLocal, tangentTransform )); // Perturbed normals
    194.                 i.screenPos = float4( i.screenPos.xy / i.screenPos.w, 0, 0 );
    195.                 i.screenPos.y *= _ProjectionParams.x;
    196.                 float2 sceneUVs = float2(1,grabSign)*i.screenPos.xy*0.5+0.5 + ((node_70.rgb*_Normalmapactivator).rgb*_Distortion).rg;
    197.                 float4 sceneColor = tex2D(_GrabTexture, sceneUVs);
    198.                 float3 lightDirection = normalize(lerp(_WorldSpaceLightPos0.xyz, _WorldSpaceLightPos0.xyz - i.posWorld.xyz,_WorldSpaceLightPos0.w));
    199.                 float3 halfDirection = normalize(viewDirection+lightDirection);
    200. ////// Lighting:
    201.                 float attenuation = LIGHT_ATTENUATION(i);
    202.                 float3 attenColor = attenuation * _LightColor0.xyz;
    203. /////// Diffuse:
    204.                 float NdotL = dot( normalDirection, lightDirection );
    205.                 float3 diffuse = max( 0.0, NdotL) * attenColor;
    206. ///////// Gloss:
    207.                 float node_75 = pow(1.0-max(0,dot(normalDirection, viewDirection)),_Gloss);
    208.                 float gloss = node_75;
    209.                 float specPow = exp2( gloss * 10.0+1.0);
    210. ////// Specular:
    211.                 NdotL = max(0.0, NdotL);
    212.                 float3 specularColor = float3(node_75,node_75,node_75);
    213.                 float3 specular = attenColor * pow(max(0,dot(halfDirection,normalDirection)),specPow) * specularColor;
    214.                 float3 finalColor = 0;
    215.                 float3 diffuseLight = diffuse;
    216.                 finalColor += diffuseLight * tex2D(_tex,TRANSFORM_TEX(node_1391.rg, _tex)).rgb;
    217.                 finalColor += specular;
    218. /// Final Color:
    219.                 return fixed4(finalColor * 1,0);
    220.             }
    221.             ENDCG
    222.         }
    223.     }
    224.     FallBack "Diffuse"
    225.     CustomEditor "ShaderForgeMaterialInspector"
    226. }
    227.  
     
  18. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Ah, yes, you could also create the same thing using multiply which is much cheaper. Not sure why I didn't do that when I wrote the post..

    On most of the hardware I'm familiar with, Pow's performance can be optimized based on the exponent; so a non-dynamic exponent of 2,3,4 and some other values are fast, but, say, 7.172 would be slow, etc. I'm much less familiar with mobile hardware, does it not have this optimization? Also, I know step just turns into a branch on some hardware, though again, not sure about mobile.
     
  19. fireheadd

    fireheadd

    Joined:
    Jan 6, 2013
    Posts:
    3
    Hi, I want to create a dithering pattern paints every second pixel black. I want to use it later for masking other stuff. So this is what I came up with: sf_pixelgrid_6102014.png
    Unfortunatley the shader looks like this:



    Any idea why? The cube is parented to the camera right now, and the camera is moving. If neither the cube or the camera moves it doesn't flicker anymore, but it's still not drawn all over the cube.
     
  20. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,174
    Even reconstructing shaders I've used before that reported info are failing to report info. It works in 4.3, but not 4.5.
     
  21. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Instruction count isn't a measure of performance for mobile anyway really. Those GPU's are just plain odd.
     
  22. GMM

    GMM

    Joined:
    Sep 24, 2012
    Posts:
    301
    Strange, i could have sworn i had already tried that without success. It seems to work now, so thank you for the help!
     
  23. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,174
    Yeah, but uh.

    I'm not targeting mobile. And without a profiler, this is kinda the best I can do to debug shader performance.
     
  24. Play_Edu

    Play_Edu

    Joined:
    Jun 10, 2012
    Posts:
    722
    Hi,
    Great job man can this work with non planar objects.

    best wishes,
    play_edu
     
  25. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Custom lighting is done per-light source. You probably want that plugged into emission instead, which is only done once
     
  26. Project-Mysh

    Project-Mysh

    Joined:
    Nov 3, 2013
    Posts:
    223
    Hi Acegikmo,

    Im having problems to set a PBL shader with Deferred Pre-Pass. This is the error when I try to plug a 2D texture to Specular or Gloss (Unity 4.5):

    Shader error in 'Shader Forge/IBL+TessTest': undeclared identifier 'node_150' at line 575

    And thats the node setup (with energy concerving and Double incoming light enabled):
    sf_ibl+tesstest_6132014.png
     
  27. TenTickles

    TenTickles

    Joined:
    Nov 17, 2012
    Posts:
    10
    Hi, Ive been looking into shader forge, and am using Amplify Texture.
    Is there a Shader Forge/Amplify Texture integration, or a way to create my own custom nodes for the purpose?
     
  28. ok8596

    ok8596

    Joined:
    Feb 21, 2014
    Posts:
    40
    Hi, could anyone tell me if you know.

    Do you know how to use the optional tangent vector as texture coordinates?
    I think it is possible to use "Tangent Direction" node.
    But I do not find a method well...
     
  29. Project-Mysh

    Project-Mysh

    Joined:
    Nov 3, 2013
    Posts:
    223
    Hi ok8596,

    Try to use append node.
     
  30. c0l0rxxx

    c0l0rxxx

    Joined:
    Aug 15, 2013
    Posts:
    5
    Hi.
    noob question
    why this fail compile?
    Lerp / If node both failed.
    I merely thought if put diffuse texture, it override Diffuse color.

    // sorry about my english...
     

    Attached Files:

  31. J_P_

    J_P_

    Joined:
    Jan 9, 2010
    Posts:
    1,027
    I read his post several times and never saw the word 'alt' thanks

    :confused:
     
  32. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    909
    someone have make Curve vertex transformation shader for mobile for info
     
  33. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Try unplugging each input to the main node, and see when/if it starts working again, to find out which branch is causing the issue.

    You have two nodes with the same name
     
  34. rjaimesmith

    rjaimesmith

    Joined:
    Jan 24, 2014
    Posts:
    3
    I'm trying to get a toon shade effect off of this ramp image. But I actually don't even know where to start, can anyone point me in the right direction? I'd greatly appreciate it!

    Many Thanks!
     

    Attached Files:

  35. c0l0rxxx

    c0l0rxxx

    Joined:
    Aug 15, 2013
    Posts:
    5
    :oops: thanks!
     
  36. c0l0rxxx

    c0l0rxxx

    Joined:
    Aug 15, 2013
    Posts:
    5
  37. bmccall1

    bmccall1

    Joined:
    Jul 28, 2013
    Posts:
    120
    I have been going through all the threads and playing with the editor but I have yet to make anything that looks like this:



    Can someone tell me where to go to learn how to do that or just screenshot their node layout?
     
  38. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
  39. Play_Edu

    Play_Edu

    Joined:
    Jun 10, 2012
    Posts:
    722
    How to make wire frame shader ???
    like this
    Shader "Custom/Wireframe"
    {
    Properties
    {
    _WireColor("WireColor", Color) = (1,0,0,1)
    _Color("Color", Color) = (1,1,1,1)
    }
    SubShader
    {

    Pass
    {
    CGPROGRAM
    #include "UnityCG.cginc"
    #pragma target 5.0
    #pragma vertex vert
    #pragma geometry geom
    #pragma fragment frag

    half4 _WireColor, _Color;

    struct v2g
    {
    float4 pos : SV_POSITION;
    float2 uv : TEXCOORD0;
    };

    struct g2f
    {
    float4 pos : SV_POSITION;
    float2 uv : TEXCOORD0;
    float3 dist : TEXCOORD1;
    };

    v2g vert(appdata_base v)
    {
    v2g OUT;
    OUT.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    OUT.uv = v.texcoord; //the uv's arent used in this shader but are included in case you want to use them
    return OUT;
    }

    [maxvertexcount(3)]
    void geom(triangle v2g IN[3], inout TriangleStream<g2f> triStream)
    {

    float2 WIN_SCALE = float2(_ScreenParams.x/2.0, _ScreenParams.y/2.0);

    //frag position
    float2 p0 = WIN_SCALE * IN[0].pos.xy / IN[0].pos.w;
    float2 p1 = WIN_SCALE * IN[1].pos.xy / IN[1].pos.w;
    float2 p2 = WIN_SCALE * IN[2].pos.xy / IN[2].pos.w;

    //barycentric position
    float2 v0 = p2-p1;
    float2 v1 = p2-p0;
    float2 v2 = p1-p0;
    //triangles area
    float area = abs(v1.x*v2.y - v1.y * v2.x);

    g2f OUT;
    OUT.pos = IN[0].pos;
    OUT.uv = IN[0].uv;
    OUT.dist = float3(area/length(v0),0,0);
    triStream.Append(OUT);

    OUT.pos = IN[1].pos;
    OUT.uv = IN[1].uv;
    OUT.dist = float3(0,area/length(v1),0);
    triStream.Append(OUT);

    OUT.pos = IN[2].pos;
    OUT.uv = IN[2].uv;
    OUT.dist = float3(0,0,area/length(v2));
    triStream.Append(OUT);

    }

    half4 frag(g2f IN) : COLOR
    {
    //distance of frag from triangles center
    float d = min(IN.dist.x, min(IN.dist.y, IN.dist.z));
    //fade based on dist from center
    float I = exp2(-4.0*d*d);

    return lerp(_Color, _WireColor, I);
    }

    ENDCG

    }
    }
    }
     
  40. CaseJnr

    CaseJnr

    Joined:
    May 14, 2014
    Posts:
    43
    Did you fix the wrapping effect?
     
  41. Project-Mysh

    Project-Mysh

    Joined:
    Nov 3, 2013
    Posts:
    223
  42. Becoming

    Becoming

    Joined:
    May 19, 2013
    Posts:
    781
    Hey, i am not sure if this is a bug or just my lack of experience, so thought i ask here before posting on the feedback page...

    i try to offset a vertex perpendicular to the view direction(billboard shader) but when ever i use the viewdir node in the vertex offset, the shader turns pink. Any tips on this?
     
  43. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,174
    I think this might be a bug. I tossed it into my testbed shader and as soon as I connect the view direction node to the vertex offset node in any way, I get this:

     
  44. Becoming

    Becoming

    Joined:
    May 19, 2013
    Posts:
    781
    Thx for confirming! I'll report it on the feedback page.
     
  45. XilenceX

    XilenceX

    Joined:
    Jun 16, 2013
    Posts:
    122
    I'm trying to create a splatmap and vertex color blending shader that blends 4 textures. One texture for Black e.g. no color painted and one each for red green and blue.

    This setup doesn't work since the texture assigned to black in the colormap or vertex color shows up in ALL transition areas. Even those that do not blend into the black areas of the colormap.
    If I remember correctly this material setup works like a charm in UDK!

    So this seems like a flaw in ShaderForge or Unity. Is there any way to fix this?

    The best "fix" I could find was to add 2 more Lerps with the green channel as a mask to the Diffuse Black texture and blend it with the Diffuse Red and Green texture respectively...
     
  46. AndreasAustPMX

    AndreasAustPMX

    Joined:
    Mar 2, 2014
    Posts:
    9
    Hey guys,
    I would like to control a panner speed via vertex color, is that possible?

    something like this:
     
  47. TenTickles

    TenTickles

    Joined:
    Nov 17, 2012
    Posts:
    10
    Hey Acegikmo,

    I guess this one got missed. Is there any way around this?

    We would like to use Shader Forge, as it allows our artists to create great complex shaders. Unfortunately, its just not viable for our production if we cant find a workaround for roadblocks like the lack of Amplify Texture support.

    I can foresee many other problems such as this in such a dynamic ecosystem of plugins.
    We are more than happy to code this add-on ourselves if it is possible?
     
  48. XilenceX

    XilenceX

    Joined:
    Jun 16, 2013
    Posts:
    122
    I've done some more experimentation with the 3 texture blending via vertex colors. I recreated this material in Shaderforge: https://docs.unrealengine.com/lates...ode/VertexColor/MaterialSetup/3Way/index.html

    Unfortunately the issue with SF persists as the Red default texture shows up in the transitions between pure blue and green vertex colors:

    Here is my shader setup in SF and the vertex colors of the box that show that blending with vertexcolors between more than 2 textures in Shaderforge is broken.

    Needless to say I'm very annoyed about this right now. -.-
     
  49. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    @XilenceX:
    That is not an issue of SF. It is an issue of the math you are using. If you look closely at the sample given by Unreal Tech. you'll see that they have the same problem - the red base texture shows up as a thin red line where green and blue areas meet.
    To overcome this issue you have to find another way of blending your textures based on your vertex colors.
     
  50. XilenceX

    XilenceX

    Joined:
    Jun 16, 2013
    Posts:
    122
    I've just recreated the material from the unreal docs in UE4 and you are right:

    The transition is broken there as well. Sorry about the false accusations to ShaderForge. Beats me why Epic would post an example that doesn't work correctly.

    So could you please show me a shader setup that doesn't have this problem? I looked all over tutorial sites/videos to find a solution, but sadly couldn't find one.