Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Shader "Bora/updated_carpaint" {
- Properties {
- _Color ("Diffuse Color", Color) = (1, 1, 1,1)
- _SpecColor ("Specular Color", Color) = (1,1,1,1)
- _AmbientColor ("Metalic Color", Color) = (1,1,1, 1)
- _ReflectionColor("Reflection Color", Color) = (1,1,1, 1)
- _Shininess ("Glossiness", Range(0.1,2)) = 0.5
- _MainTex ("Diffuse", 2D) = "white" {}
- _FlakeTex ("Flakes", 2D) = "white" {}
- _FlakeDens ("Flakes Tile", Range(1,40) ) = 2
- _Cube ("Reflection Cubemap", Cube) = "" { TexGen CubeReflect }
- _Cube2 ("Reflection Cubemap2", Cube) = "" { TexGen CubeReflect }
- _FresnelScale ("Fresnel Intensity", Range(0,2)) = 0
- _FresnelPower ("Fresnel Power", Range(0.1,3) ) = 0
- _MetalicScale ("Metalic Intens", Range(0.0,4.0)) = 0
- _MetalicPower ("Metalic Power", Range(0.0,20.0)) = 0
- _Blend ("Blend Rate", Range(0,1)) = 0
- }
- SubShader {
- Tags { "RenderType"="Opaque" }
- LOD 400
- Cull Back
- ZWrite On
- ZTest Lequal
- ColorMask RGBA
- CGPROGRAM
- #pragma surface surf BlinnPhong vertex:vert
- #pragma target 3.0
- struct Input
- {
- float2 uv_MainTex;
- float2 uv_FlakeTex;
- float3 worldRefl;
- float3 viewDir;
- float3 lightDir;
- float3 normal;
- float3 worldNormal;
- INTERNAL_DATA
- };
- uniform float _Rotate;
- samplerCUBE _Cube;
- samplerCUBE _Cube2;
- sampler2D _MainTex;
- sampler2D _FlakeTex;
- float4 _Color;
- float4 _AmbientColor;
- float4 _ReflectionColor;
- float _Shininess;
- float _FlakeDens;
- float _FresnelScale;
- float _FresnelPower;
- float _MetalicScale;
- float _MetalicPower;
- float _Blend;
- float3 RotateAroundXInDegrees (float3 vertex, float degrees)
- {
- float alpha = degrees * UNITY_PI / 180.0;
- float sina, cosa;
- sincos(alpha / 2, sina, cosa);
- float3x3 m = float3x3(1, 0, 0, 0, cosa, -sina, 0, sina, cosa);
- float3 r = float3(mul(m, vertex.xyz) ).rgb;
- return r;
- }
- float3 RotateAroundYInDegrees (float3 vertex, float degrees)
- {
- float alpha = degrees * UNITY_PI / 180.0;
- float sina, cosa;
- sincos(alpha / 2, sina, cosa);
- float3x3 m = float3x3(cosa, 0, sina, 0, 1, 0, -sina, 0, cosa);
- float3 r = float3(mul(m, vertex.xyz) ).rgb;
- return r;
- }
- float3 RotateAroundZInDegrees (float3 vertex, float degrees)
- {
- float alpha = degrees * UNITY_PI / 180.0;
- float sina, cosa;
- sincos(alpha / 2, sina, cosa);
- float3x3 m = float3x3(cosa, -sina, sina, sina, cosa, 0, 0, 0, 1);
- float3 r = float3(mul(m, vertex.xyz) ).rgb;
- return r;
- }
- void vert (inout appdata_full v, out Input o) {
- UNITY_INITIALIZE_OUTPUT(Input,o);
- v.normal.x = RotateAroundXInDegrees(float3(v.normal.x, 0, 1), _Rotate * 10);
- v.normal.z = RotateAroundZInDegrees(float3(1, 0, v.normal.z), _Rotate * 10);
- }
- void surf (Input IN, inout SurfaceOutput o){
- //Reflection ve isik icin hesaplamalar
- o.Normal = normalize(float3(0.0,0.0,1.0));
- float3 normEyeVec = normalize (IN.viewDir);
- float dotEyeVecNormal = abs(dot(normEyeVec, o.Normal));
- //GET WORLD REFLECTION FROM o.Normal.x and o.Normal.y
- float3 worldRefl = WorldReflectionVector (IN, o.Normal);
- float3 worldRefl2 = WorldReflectionVector (IN, o.Normal);
- float3 worldLight = normalize (IN.lightDir);
- //Gerekli ise flake texture
- float4 Tex1 = tex2D( _MainTex,IN.uv_MainTex );
- float specularmask = Tex1.a ;
- float4 Diffuse = ((_Color* (specularmask) )* Tex1) + (Tex1*(1-specularmask));
- float4 Tex2 = tex2D( _FlakeTex, IN.uv_FlakeTex*_FlakeDens );
- float4 Specular = (_Shininess * Tex2) + Tex2;
- //Cubemap' lerin alimi
- float4 TexCUBE = texCUBE( _Cube, worldRefl) * _ReflectionColor;
- float4 TexCUBE2 = texCUBE( _Cube2, worldRefl2) * _ReflectionColor;
- //Cubemap degisimi
- float4 env = lerp(TexCUBE, TexCUBE2, IN.normal.x);
- //Paint efekti
- float4 fresnel = (1.0 - dot( normEyeVec,o.Normal ));
- float4 emmission = _FresnelScale * env * pow(fresnel,_FresnelPower);
- float metalic = (specularmask*_MetalicScale) * pow(dotEyeVecNormal,_MetalicPower);
- o.Albedo = Diffuse * ((metalic+(1-specularmask)+((1-Tex2)*(specularmask))) + (_AmbientColor.rgb*specularmask) ) + ( specularmask*(1-Tex2));
- o.Specular = Specular;
- o.Gloss = _SpecColor * specularmask;
- o.Emission = emmission * emmission * specularmask;
- }
- ENDCG
- }
- FallBack "Reflective/Diffuse"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement