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 trumanita · Nov 10, 2012 at 06:51 PM · shadercarreflectionpaintdx11

Car shader problem

Hi, I've written my first custom shader (Unity 4.0.0f5, DX11)

 Shader "Custom/FerrariShader" {
 Properties {
     _Color ("Main Color", Color) = (1,1,1,1)
     _SpecColor ("Specular Color", Color) = (0.5,0.5,0.5,1)
     _Shininess ("Shininess", Range (0.01, 1)) = 0.078125
     //_ReflectColor ("Reflection Color", Color) = (1,1,1,0.5)
     _MainTex ("Base (RGB) RefStrGloss (A)", 2D) = "white" {}
     _Cube ("Reflection Cubemap", Cube) = "" { TexGen CubeReflect }
     _BumpMap ("Normalmap", 2D) = "bump" {}
     _SpecularMap ("Spec(R) Gloss(G) Reflec(B)", 2D) = "specular" {}
     _RimPower ("Rim Power", Range(0.005,8.0)) = 1.0
 }
 
 SubShader {
     Tags
         {
 "Queue"="Geometry"
 "IgnoreProjector"="False"
 "RenderType"="Opaque"
 
         }
     LOD 400
     Cull Back
 ZWrite On
 ZTest LEqual
 ColorMask RGBA
 Fog{
 }
 CGPROGRAM
 #pragma surface surf BlinnPhong
 #pragma target 5.0
 
 sampler2D _MainTex;
 sampler2D _BumpMap;
 sampler2D _SpecularMap;
 samplerCUBE _Cube;
 float _RimPower;
 fixed4 _Color;
 fixed4 _ReflectColor;
 
 
 half _Shininess;
 
 struct Input {
     float2 uv_MainTex;
     float2 uv_BumpMap;
     float3 worldRefl;
     float3 viewDir;
     INTERNAL_DATA
 };
 
 void surf (Input IN, inout SurfaceOutput o) {
     fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
     fixed4 texSpec = tex2D(_SpecularMap, IN.uv_MainTex);
     fixed4 c = tex * _Color;
     float diffusePower=.3;
     float reflectPower=.7;
     o.Albedo = c.rgb*diffusePower;
     //o.Gloss = texSpec.rgb;
     o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
     //o.Specular = texSpec.r*_Shininess;
     float3 worldRefl = WorldReflectionVector (IN, o.Normal);
     fixed4 reflcol = texCUBE (_Cube, worldRefl);
     
     half rim = 1.0-saturate (dot (normalize(IN.viewDir), o.Normal));
     o.Emission = reflcol.rgb* pow(rim,_RimPower/3)*texSpec.b*reflectPower;//* pow(_ReflectColor.rgb,_RimPower);
     //o.Emission = Lerp0.rgb;
 
                 o.Normal = normalize(o.Normal);
             }
 ENDCG
 }
 
 FallBack "Diffuse"
 }

I'm quite satisfied, but when car parts aren't thrown by direction light, car seems to me too dark.

Dark scene good one Please give me feedbacks and suggestions !!! Thanks

tipasso1.jpg (273.3 kB)
tipasso2.jpg (257.4 kB)
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

3 Replies

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

Answer by hvilela · Nov 10, 2012 at 06:56 PM

You can icrease your ambient ligth (and reduce your directional light to compensate) or you can write your own light model.

Comment
Add comment · 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
0

Answer by trumanita · Nov 10, 2012 at 07:23 PM

thanks, you pointed me in the right direction: you mean that I should make something like this:

 half4 LightingFerrariPhong (SurfaceOutput s, half3 lightDir, half3 viewDir, half atten) {
           half3 h = normalize (lightDir + viewDir);
 
           half diff = max (0, dot (s.Normal, lightDir));
 
           float nh = max (0, dot (s.Normal, h));
           float spec = pow (nh, 48.0);
 
           half4 c;
           c.rgb = .9*s.Albedo+(.1 * _LightColor0.rgb * diff + _LightColor0.rgb * spec) * (atten * 2);
           c.a = s.Alpha;
           return c;
       }
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 hvilela · Nov 10, 2012 at 07:30 PM 0
Share

Yes, now it's up to you how to tune the light to active what you expect.

PS: Do not forget to make the shader use your light model.

 #pragma surface surf LightingFerrariPhong
avatar image
0

Answer by trumanita · Nov 10, 2012 at 07:45 PM

yes, I already added

 #pragma surface surf LightingFerrariPhong


alt text

darkness problem is solved, I have to tune light thanks!!!!!!!!!!!


tipasso3.jpg (209.0 kB)
Comment
Add comment · Show 2 · 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 hvilela · Nov 10, 2012 at 10:16 PM 0
Share

Nice. You just forgot to check the answer as correct.

avatar image trumanita · Nov 10, 2012 at 10:45 PM 0
Share

sorry, I checked the wrong one thanks again

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

10 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

Related Questions

Change color of WaterPro (Standard Assets) when a Particle touch it,Particle Collision with Water and change Refraction Color 0 Answers

Blending Reflection 0 Answers

How does the districts painting work in cities skyline? 1 Answer

Why does specular highlight ignore vertex position? 1 Answer

can i have reflections on a self illuminated bumped diffuse object ? 3 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