Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Shader "318/TexPixelLightingAlpha" // shader name
- {
- Properties
- {
- _MainTex("Bild", 2D) = "white" {}
- _Cutoff("CutoffValue",Float) = 0.5
- _farbeF("Farbe", Color) = (0.1,0.7,1,0.8)
- _SpecfarbeF("Specular", Color) = (1,1,1,1)
- _Shiny("Shiny", Float) = 10
- }
- SubShader // Pro Platform
- {
- Pass //Shader durchlauf
- {
- Tags {"LightMode" = "ForwardBase"}
- Cull Off
- CGPROGRAM //---------------CG CODE
- #pragma vertex VS //ändert den VShader EntryPoint
- #pragma fragment PS //ändert den PShader EntryPoint
- #include "UnityCG.cginc" //hat mehr Globale constant values aus Unity
- struct VertexInput
- {
- float4 pos : POSITION;
- float3 normal : NORMAL;
- float4 tex : TEXCOORD0;
- };
- struct VertexOutput
- {
- float4 pos : SV_POSITION;
- float4 tex : TEXCOORD0;
- float4 posWorld : TEXCOORD1;
- float3 normalDir : TEXCOORD2;
- };
- uniform sampler2D _MainTex;
- uniform float4 _MainTex_ST; //tillling and offset parameters
- uniform float _Cutoff;
- uniform float4 _farbeF;
- uniform float4 _SpecfarbeF;
- uniform float _Shiny;
- uniform float4 _LightColor0;
- //VERTEX shader
- VertexOutput VS(VertexInput vi)
- {
- VertexOutput vo;
- float4x4 modelMatrix = unity_ObjectToWorld;
- float4x4 modelMatrixInvers = unity_WorldToObject;
- vo.posWorld = mul(modelMatrix, vi.pos);
- vo.normalDir = normalize(
- mul(float4(vi.normal, 0), modelMatrixInvers).xyz);
- vo.pos = UnityObjectToClipPos(vi.pos);
- vo.tex = vi.tex;
- return vo;
- }
- float4 PS(VertexOutput input) : COLOR
- {
- float3 normalDir = normalize(input.normalDir);
- float3 viewDir = normalize(_WorldSpaceCameraPos -
- input.posWorld.xyz);
- float3 lightDir;
- float attenuation;
- //wenn in der .w eine 0 steht -> dannn directional light
- if (0.0 == _WorldSpaceLightPos0.w)
- {
- attenuation = 1;
- lightDir = normalize(_WorldSpaceLightPos0.xyz);
- }
- else
- { //spot or point light
- float3 vertexToLight = _WorldSpaceLightPos0.xyz
- - input.posWorld.xyz;
- float distance = length(vertexToLight);
- attenuation = 1.0 / distance;
- lightDir = normalize(vertexToLight);
- }
- float3 ambient = UNITY_LIGHTMODEL_AMBIENT.rgb * _farbeF;
- float3 diffRefl = attenuation * _LightColor0.rgb * _farbeF.rgb
- *max(0.0, dot(normalDir, lightDir));
- float3 specRefl;
- if (dot(normalDir, lightDir) < 0)
- {
- //licht auf falscher seite?
- specRefl.rgb = 0;
- }
- else
- {
- specRefl = attenuation * _LightColor0.rgb * _SpecfarbeF.rgb *
- pow(max(0.0, dot(reflect(-lightDir, normalDir), viewDir)), _Shiny);
- }
- float4 diff = tex2D(_MainTex, _MainTex_ST.xy * input.tex.xy + _MainTex_ST.zw);
- float4 FinalColor = float4(diff + ambient + diffRefl + specRefl, 1.0);
- if (diff.a < _Cutoff)
- {
- discard;
- }
- return FinalColor;
- }
- ENDCG // -------------END CG
- }
- Pass //Shader durchlauf
- {
- Tags {"LightMode" = "ForwardAdd"}
- Blend One One
- CGPROGRAM //---------------CG CODE
- #pragma vertex VS //ändert den VShader EntryPoint
- #pragma fragment PS //ändert den PShader EntryPoint
- #include "UnityCG.cginc" //hat mehr Globale constant values aus Unity
- struct VertexInput
- {
- float4 pos : POSITION;
- float3 normal : NORMAL;
- };
- struct VertexOutput
- {
- float4 pos : SV_POSITION;
- float4 posWorld : TEXCOORD0;
- float3 normalDir : TEXCOORD1;
- };
- uniform float4 _farbeF;
- uniform float4 _SpecfarbeF;
- uniform float _Shiny;
- uniform float4 _LightColor0;
- //VERTEX shader
- VertexOutput VS(VertexInput vi)
- {
- VertexOutput vo;
- float4x4 modelMatrix = unity_ObjectToWorld;
- float4x4 modelMatrixInvers = unity_WorldToObject;
- vo.posWorld = mul(modelMatrix, vi.pos);
- vo.normalDir = normalize(
- mul(float4(vi.normal, 0), modelMatrixInvers).xyz);
- vo.pos = UnityObjectToClipPos(vi.pos);
- return vo;
- }
- float4 PS(VertexOutput input) : COLOR
- {
- float3 normalDir = normalize(input.normalDir);
- float3 viewDir = normalize(_WorldSpaceCameraPos -
- input.posWorld.xyz);
- float3 lightDir;
- float attenuation;
- //wenn in der .w eine 0 steht -> dannn directional light
- if (0.0 == _WorldSpaceLightPos0.w)
- {
- attenuation = 1;
- lightDir = normalize(_WorldSpaceLightPos0.xyz);
- }
- else
- { //spot or point light
- float3 vertexToLight = _WorldSpaceLightPos0.xyz
- - input.posWorld.xyz;
- float distance = length(vertexToLight);
- attenuation = 1.0 / distance;
- lightDir = normalize(vertexToLight);
- }
- float3 diffRefl = attenuation * _LightColor0.rgb * _farbeF.rgb
- *max(0.0, dot(normalDir, lightDir));
- float3 specRefl;
- if (dot(normalDir, lightDir) < 0)
- {
- //licht auf falscher seite?
- specRefl.rgb = 0;
- }
- else
- {
- specRefl = attenuation * _LightColor0.rgb * _SpecfarbeF.rgb *
- pow(max(0.0, dot(reflect(-lightDir, normalDir), viewDir)), _Shiny);
- }
- return float4(diffRefl + specRefl, 1.0);
- }
- ENDCG // -------------END CG
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement