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 Idual · Jul 16, 2020 at 11:48 AM · shader programmingsurface shaderspecular

Simple Blinn Phong Surface Shader

Hi All, I'm trying to write a very simple surface shader using BlinnPhong that doesn't use any textures. It's supposed to represent gloss paint. I'm new to surface shaders and can't find any reference texts or examples that use the BlinnPhong surf keyword apart from those that also use a normal map..

Here's what I have so far:

 Shader "Custom/BP" {
  
         Properties {
             _Color ("Color", color) = (1,1,1,1)
             _SpecColor ("Spec color", color) = (0.5,0.5,0.5,0.5)
             _Glossiness("Shininess", Range(0, 255)) = 10
         }
         SubShader {
             Tags { "RenderType"="Opaque" }
             LOD 200
          
             CGPROGRAM
             #pragma surface surf BlinnPhong
             #pragma target 3.0
  
             struct appdata {
                 float4 vertex : POSITION;
                 float3 normal : NORMAL;
             };
  
             struct Input {
                 float3 normal : NORMAL;
             };
  
         float _Glossiness;
         fixed4 _Color;
 
             void surf (Input IN, inout SurfaceOutput o) {
                 o.Albedo = _Color.rgb;
                 o.Specular = _Glossiness;
                 o.Gloss = 1;
                 o.Normal = IN.normal;
             }
             ENDCG
         }
         FallBack "Diffuse"
     }


The results are not as I expected. I'm not sure what the values in the output represent or if I need to do any calculations to generate the output.

Any help appreciated. If anyone has a link to a tutorial that covers this I'd be extremely grateful.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Namey5 · Jul 17, 2020 at 12:19 AM

Don't assign anything to o.Normal. This output is specifically for normal maps, and if you assign into it the normals will be taken in tangent space rather than world space, which would mess with the lighting here.

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 Idual · Jul 25, 2020 at 03:49 PM 0
Share

Thanks for that. It now works perfectly.

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

136 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

Related Questions

Change custom shader color where vertex is displaced 0 Answers

Surface Shader vertex displacement, shadows not moving 1 Answer

How to convert surface shader to Vertex/Fragment code? 0 Answers

Shading is visible through object using surface shader 0 Answers

Referencing the current pixel's world coordinates in the SURF block of a shader 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