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 lagidigu3ll · Apr 24, 2015 at 06:30 PM · shadervertexdiffuse

How can I add the diffuse property to a vertex Shader?

Hi there!

I've been messing around with a shader that distorts the world by modifiying the vertices in the scene. Thing is, every object that I apply this shader to remains unlit. Is there a way to give it a diffuse in the script? Is that even possible with vertex shaders? How would I do it?

Here's my current shader:

 Shader "Custom/Curved" {
     Properties {
         _MainTex ("Base (RGB)", 2D) = "white" {}
         _QOffset ("Offset", Vector) = (0,0,0,0)
         _Dist ("Distance", Float) = 100.0
         _Sin ("Sin", Float) = 1
     }
     SubShader {
         Tags { "RenderType"="Opaque" }
         Pass
         {
             CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
             #include "UnityCG.cginc"
 
                         sampler2D _MainTex;
             float4 _QOffset;
             float _Dist;
             float _Sin;
             
             struct v2f {
                 float4 pos : SV_POSITION;
                 float4 uv : TEXCOORD0;
             };
 
             v2f vert (appdata_base v)
             {
                 v2f o;
                 float4 vPos = mul (UNITY_MATRIX_MV, v.vertex);
                 float zOff = vPos.z/_Dist;
                 _Sin = sin(zOff*1 - 3.1) * 6 + sin(zOff) * 2;
                 //_Sin = 0;
                 vPos += _QOffset*_Sin;
                 o.pos = mul (UNITY_MATRIX_P, vPos);
                 o.uv = v.texcoord;
                 return o;
             }
 
             half4 frag (v2f i) : COLOR
             {
                 half4 col = tex2D(_MainTex, i.uv.xy);
                 return col;
             }
             ENDCG
         }
     }
     FallBack "Diffuse"
 }
 

I haven't written everything by myself, found it some time ago and modified it.

Thanks in advance!

Comment
Add comment · Show 2
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
avatar image tanoshimi · Apr 24, 2015 at 06:31 PM 0
Share

Yes, of course. But seeing as you've not posted your shader code it's impossible to tell you what you're doing wrong. Perhaps start with reading http://docs.unity3d.com/$$anonymous$$anual/SL-VertexFragmentShaderExamples.html

avatar image lagidigu3ll · Apr 24, 2015 at 08:36 PM 0
Share

I've posted the shader code now, do you know where I could do a slight change to get diffuse ins$$anonymous$$d of unlit? Shaders are really really confusing to me...

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by tanoshimi · Apr 24, 2015 at 08:44 PM

Well, you haven't really included any lighting calculations in your shader at all - you're just directly applying the _MainTex texture in the fragment shader which is why it's unaffected by lighting. If you're not familiar with shaders you'll probably find it a lot easier to use a surface shader rather than a vert/frag - it greatly simplifies the lighting calculations required.

You appear to be trying to adjust vertex position to falloff with distance from camera? If so, I'dn recommend you start off with a surface shader template that achieves the same effect and adjust it to your needs, e.g.: https://alastaira.wordpress.com/2013/10/25/animal-crossing-curved-world-shader/

Comment
Add comment · Show 1 · Share
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
avatar image lagidigu3ll · Apr 24, 2015 at 09:06 PM 0
Share

Thanks a lot man! So basically, I can recreate the same effect with a surface shader, and still give it a good-looking shader that is as good as the standard shader in unity 5?

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

2 People are following this question.

avatar image avatar image

Related Questions

Curved + Diffuse Shader??? 0 Answers

Cubemap Diffuse / Heightmap Shader Issues. 1 Answer

Problem of color in custom vertex shader 0 Answers

Silhouette Toon Shader 0 Answers

Add new vertex attributes for a shader,Create vertex attributes 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