镜面反射

来源:互联网 发布:数据库的三种模型 编辑:程序博客网 时间:2024/04/30 14:25
Shader "Custom/CustomSpecular" {Properties {_Color ("Color", Color) = (1,1,1,1)_SpeColor("Specular Color", Color) = (1,1,1,1)_Shininess("Shininess", Float) = 10}SubShader {Pass{Tags { "LightMode" = "ForwardBase" }CGPROGRAM#pragma vertex vert#pragma fragment frag#include "UnityCG.cginc"#include "Lighting.cginc"fixed4 _Color;fixed4 _SpeColor;float _Shininess;struct v2f{float4 pos : SV_POSITION;float4 col : COLOR;};v2f vert(appdata_base v){v2f o;float3 normalDirection = normalize(mul(float4(v.normal, 0.0), _World2Object).xyz);float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz);float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - mul(_Object2World, v.vertex));float3 specularReflection = _LightColor0.rgb*_SpeColor.rgb*pow(max(0.0,dot(reflect(-lightDirection, normalDirection),viewDirection)),_Shininess);float3 diffuseReflection = _LightColor0.rgb * _Color.rgb* max(0.0, dot(normalDirection, lightDirection));float3 ambientLighting = UNITY_LIGHTMODEL_AMBIENT.rgb * _Color.rgb;o.col = float4(ambientLighting + diffuseReflection + specularReflection, 1.0);o.pos = mul(UNITY_MATRIX_MVP, v.vertex);return o;}fixed4 frag(v2f i) : COLOR{return i.col;}ENDCG}} FallBack "Diffuse"}
<pre name="code" class="plain">Shader "Custom/SpecularTex" {Properties {_MainTex ("Albedo (RGB)", 2D) = "white" {}_Color ("Color", Color) = (1,1,1,1)_SpeColor("Specular Color", Color) = (1,1,1,1)_Shininess("Shininess", Float) = 10}SubShader {Pass{Tags { "LightMode" = "ForwardBase" }CGPROGRAM#pragma vertex vert#pragma fragment frag#include "UnityCG.cginc"#include "Lighting.cginc"sampler2D _MainTex;fixed4 _Color;fixed4 _SpeColor;float _Shininess;struct v2f{float4 pos : SV_POSITION;float4 tex : TEXCOORD0;float4 posWorld : TEXCOORD1;float4 normalDir : TEXCOORD2;};v2f vert(appdata_base v){v2f o;o.posWorld = mul(_Object2World,  v.vertex);o.pos = mul(UNITY_MATRIX_MVP, v.vertex);o.tex = v.texcoord;o.normalDir = normalize(mul(float4(v.normal, 0.0), _World2Object));return o;}fixed4 frag(v2f i) : COLOR{float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld);float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz);float3 specularReflection = _LightColor0.rgb*_SpeColor.rgb*pow(max(0.0,dot(reflect(-lightDirection, i.normalDir.xyz),viewDirection)),_Shininess);float3 diffuseReflection = _LightColor0.rgb * _Color.rgb* max(0.0, dot(i.normalDir.xyz, lightDirection));float3 ambientLighting = UNITY_LIGHTMODEL_AMBIENT.rgb * _Color.rgb;return float4(ambientLighting + diffuseReflection * tex2D(_MainTex, i.tex.xy) + specularReflection, 1.0);}ENDCG}} FallBack "Diffuse"}



0 0