Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 blitzen · Oct 01, 2020 at 05:37 PM · shadersgraphics

World Space Diffuse Shader with Normal Map

Trying to create one.


Using the following working world coordinate diffuse shader:

     Shader "Custom/WorldCoord Diffuse" {
         Properties {
             _Color ("Main Color", Color) = (1,1,1,1)
             _MainTex ("Base (RGB)", 2D) = "white" {}
             _BaseScale ("Base Tiling", Vector) = (1,1,1,0)
         }
         SubShader {
             Tags { "RenderType"="Opaque" }
             LOD 150
         CGPROGRAM
         #pragma surface surf Lambert 
         sampler2D _MainTex;
         fixed4 _Color;
         fixed3 _BaseScale;
         struct Input{
             float2 uv_MainTex;
             float3 worldPos;
             float3 worldNormal;
         };
         void surf(Input IN,inout SurfaceOutput o) {
             fixed4 texXY=tex2D(_MainTex,IN.worldPos.xy*_BaseScale.z);//IN.uv_MainTex);
             fixed4 texXZ=tex2D(_MainTex,IN.worldPos.xz*_BaseScale.y);//IN.uv_MainTex);
             fixed4 texYZ=tex2D(_MainTex,IN.worldPos.yz*_BaseScale.x);//IN.uv_MainTex);
             fixed3 mask=fixed3(
                 dot(IN.worldNormal,fixed3(0,0,1)),
                 dot(IN.worldNormal,fixed3(0,1,0)),
                 dot(IN.worldNormal,fixed3(1,0,0)));
             fixed4 tex=
                 texXY*abs(mask.x)+
                 texXZ*abs(mask.y)+
                 texYZ*abs(mask.z);
             fixed4 c=tex*_Color;
             o.Albedo=c.rgb;
         }
         ENDCG
         }
         FallBack "Diffuse"
         }

Trying to add a normal texture channel. My attempt thus far, combining the above with simple normal textures:

 Shader "Legacy Shaders/Diffuse - Worldspace"{
     Properties{
         _Color("Main Color",Color)=(1,1,1,1)
         _MainTex("Base (RGB)",2D)="white"{}
         _NormTex("Normal (RGB)",2D)="bump"{}
         _Scale("Texture Scale",Vector)=(1.0,1.0,0,0)
         _BumpInfluence("Bump Influence",Float)=1.0
     }
     SubShader{
         Tags{"RenderType"="Opaque"}
         LOD 200
         CGPROGRAM
             #pragma surface surf Lambert
             sampler2D _MainTex;
             sampler2D _NormTex;
             fixed4 _Color;
             float4 _Scale;
             float _BumpInfluence/*,_Dimension*/;
             struct Input{
                 float3 worldNormal;
                 float3 worldPos;
                 float2 uv_MainTex;
                 float2 uv_NormTex;
                 INTERNAL_DATA
             };
             void surf(Input IN,inout SurfaceOutput o){
                 fixed4 texXY = tex2D(_MainTex, IN.worldPos.xy * _Scale.z);//IN.uv_MainTex);
                 fixed4 texXZ = tex2D(_MainTex, IN.worldPos.xz * _Scale.y);//IN.uv_MainTex);
                 fixed4 texYZ = tex2D(_MainTex, IN.worldPos.yz * _Scale.x);//IN.uv_MainTex);
                 fixed3 mask = fixed3(
                     dot(IN.worldNormal, fixed3(0, 0, 1)),
                     dot(IN.worldNormal, fixed3(0, 1, 0)),
                     dot(IN.worldNormal, fixed3(1, 0, 0)));
                 fixed4 tex =
                     texXY * abs(mask.x) +
                     texXZ * abs(mask.y) +
                     texYZ * abs(mask.z);
                 fixed4 c = tex * _Color;
                 o.Albedo = c.rgb;
 
                 texXY = tex2D(_NormTex, IN.worldPos.xy * _Scale.z);//IN.uv_MainTex);
                 texXZ = tex2D(_NormTex, IN.worldPos.xz * _Scale.y);//IN.uv_MainTex);
                 texYZ = tex2D(_NormTex, IN.worldPos.yz * _Scale.x);//IN.uv_MainTex);
                 mask = fixed3(
                     dot(IN.worldNormal, fixed3(0, 0, 1)),
                     dot(IN.worldNormal, fixed3(0, 1, 0)),
                     dot(IN.worldNormal, fixed3(1, 0, 0)));
                 tex =
                     texXY * abs(mask.x) +
                     texXZ * abs(mask.y) +
                     texYZ * abs(mask.z);
             }
         ENDCG
     }
     Fallback "Legacy Shaders/VertexLit"
 }

Turns the whole thing black, no matter the value of "_BumpInfluence".

Know where it's gone awry?

Thanks.

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

163 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 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 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 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 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 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 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 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 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 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 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

Wierd shading in UV seams 0 Answers

Send vertice shader changes to surface shader 0 Answers

Rendering Particle Systems to Command Buffer 1 Answer

Custom shader remove shine 2 Answers

Get target RenderTexture dimensions in fragment shader used for Graphics.Blit 0 Answers


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