Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Pixeldamage · Jul 31, 2013 at 09:29 AM · shaderlightmappinguvdecal

BumpedSpecProbed + decal UV2

Is there a BumpedSpecProbed that combines the diffuse (UV1) with a decal (UV2)? Can anyone help with this please?

I gave it a go using (http://forum.unity3d.com/threads/116497-Light-Probes-Questions-Feedback/page5) but couldn't get the UV2 channel data into/out of the vertex shader properly withouth taking out the #pragma vertex:vert - which then destroys the specular info.

Please note i'm a 3D artist not a shader writer (though i'm trying) so appologies for glaring errors.

 Shader "BumpSpecProbedDecalUV2"
 {
     Properties 
     {
     // shaderlab nodes
 
 _diffuse("_diffuse", 2D) = "black" {}
 _decal("_decal", 2D) = "black" {}
 _BumpMap("Normalmap", 2D) = "bump" {}
 _Shininess("Shininess", Range(0.03,1) ) = 0.1
 _SpecularColor("Specular Color", Color) = (0.4552239,0.4552239,0.4552239,1)
 _ProbeShininess("Probe Spec Pow", Range(1,20) ) = 2
 _ProbeSpecStr("Probe Spec Multiply", Range(0,2) ) = 0.5
 _ProbeSpecSub("Probe Spec Subtrator", Range(0,4) ) = 2
     }
     
     SubShader 
     {
         Tags
         {
 "Queue"="Geometry"
 "IgnoreProjector"="False"
 "RenderType"="Opaque"
 "LightMode"="ForwardBase"
         }
 
         
 Cull Back
 ZWrite On
 ZTest LEqual
 ColorMask RGBA
 Fog{
 }
 
 
 
         
 CGPROGRAM
 #include "UnityCG.cginc"
 #include "HLSLSupport.cginc"
 //removed #pragma vertex:vert novertexlights
 #pragma surface surf BlinnPhongEditor  
 #pragma debug
 #pragma target 3.0
  
 // Definitions
 
 sampler2D _diffuse;
 sampler2D _decal;
 sampler2D _BumpMap;
 float4 _SpecularColor;
 float _Shininess;
 float _ProbeShininess;
 float _ProbeSpecStr;
 float _ProbeSpecSub;
 
             struct EditorSurfaceOutput 
             {
                 half3 Albedo;
                 half3 Normal;
                 half3 Emission;
                 half3 Gloss;
                 half Specular;
                 half Alpha;
                 half4 Custom;
             };
             
             inline half4 LightingBlinnPhongEditor_PrePass (EditorSurfaceOutput s, half4 light)
             {
                 half3 spec = light.a * s.Gloss;
                 half4 c;
                 c.rgb = (s.Albedo * light.rgb + light.rgb * spec);
                 c.a = s.Alpha;
                 return c;
             }
 
             inline half4 LightingBlinnPhongEditor (EditorSurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
             {
                 half3 h = normalize (lightDir + viewDir);
                 
                 half diff = max (0, dot ( lightDir, s.Normal ));
                 
                 float nh = max (0, dot (s.Normal, h));
                 float spec = pow (nh, s.Specular*128.0);
                 
                 half4 res;
                 res.rgb = _LightColor0.rgb * diff;
                 res.w = spec * Luminance (_LightColor0.rgb);
                 res *= atten * 2.0;
 
                 return LightingBlinnPhongEditor_PrePass( s, res );
             }
             
             struct Input {
                 float3 viewDir;
                 float2 uv_diffuse;
                 float4 meshUV;
                 float2 uv_BumpMap;
                 float3 worldNormal;
                 float3 worldRefl;
                 INTERNAL_DATA
 
             };
 
 
             void vert (inout appdata_full v, out Input o) 
             {
             
                 //UNITY_INITIALIZE_OUTPUT(Input, o);
                 
                 //o.meshUV.xy = v.texcoord.xy;
                 //o.meshUV.zw = v.texcoord1.xy;
                 
 
             }
             
 
                 void surf (Input IN, inout EditorSurfaceOutput o) {
                             
                             
                             o.Normal = float3(0.0,0.0,1.0);
                             o.Alpha = 1.0;
                             o.Albedo = 0.0;
                             o.Emission = 0.0;
                             o.Gloss = 0.0;
                             o.Specular = 0.0;
                             o.Custom = 0.0;
             
             
                             //IN.meshUV.xy = tex1XY;
                             //IN.meshUV.zw = tex2XY;
             
                             // this is the diffuse UV passed into the vertex shader in register 0
                             //float4 Tex2D0=tex2D(_diffuse,(IN.uv_diffuse.xyxy).xy);
                             
                             float4 Tex2D1=tex2D(_diffuse,(IN.uv_diffuse.xyxy).xy);
                             float4 Tex2D2=tex2D(_decal,(IN.meshUV.zwzw).xy);
                             float4 Add0=Tex2D1 + Tex2D2.aaaa;
                             float4 Multiply1=Add0 * Tex2D2;                
                                 
                             //float4 Invert0= float4(1.0, 1.0, 1.0, 1.0) - Tex2D2.aaaa;
                             //float4 Multiply0=_numberC * Tex2D2.aaaa;
                             //float4 Add0=Multiply2 + Multiply0;
                             
                             
                             float4 Tex2DNormal0=float4(UnpackNormal( tex2D(_BumpMap,(IN.uv_BumpMap.xyxy).xy)).xyz, 1.0 );
                             float4 Multiply2=Tex2D1.aaaa * _SpecularColor;
                             
                                                         
                             o.Albedo = Multiply1;
                             o.Normal = Tex2DNormal0;
                             o.Specular = _Shininess.xxxx;
                             o.Gloss = Multiply2;
                             o.Alpha = Tex2D1.aaaa;
                             o.Normal = normalize(o.Normal);
             
                             float4 Fresnel0=(1.0 - dot( normalize( float4( IN.viewDir.x, IN.viewDir.y,IN.viewDir.z,1.0 ).xyz), normalize( Tex2DNormal0.xyz ) )).xxxx;
                             fixed3 worldN = WorldNormalVector(IN, o.Normal);
                             fixed3 worldR = normalize(WorldReflectionVector(IN, o.Normal));
                             float3 fProbeSpecCol = ShadeSH9(float4(worldR,1.0));
                             float fProbeSpecMask = pow(max(_ProbeSpecStr*(length(fProbeSpecCol)-_ProbeSpecSub-Fresnel0*2),0),_ProbeShininess+Fresnel0);
                             o.Emission = o.Albedo*ShadeSH9(float4(worldN,1.0)) + o.Gloss*fProbeSpecCol*fProbeSpecMask;
                             
             }
         ENDCG
     }
     Fallback "Diffuse"
 }


Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

15 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

U3: Beast Lightmapping + Nature / Soft Occlusion Shader 1 Answer

UI shader; get simple UV 0 Answers

TexGen'ed UVs - how to access in surface shader? 1 Answer

Apply an affine transformation 2 Answers

How to scale and offset UV coordinates from the center of the texture? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges