mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
更新Demo
更新Demo
This commit is contained in:
58
UnityProject/Assets/AssetArt/Shader/MyUnlitShader.shader
Normal file
58
UnityProject/Assets/AssetArt/Shader/MyUnlitShader.shader
Normal file
@@ -0,0 +1,58 @@
|
||||
Shader "Unlit/MyUnlitShader"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_MainTex ("Texture", 2D) = "white" {}
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
Tags { "RenderType"="Opaque" }
|
||||
LOD 100
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
// make fog work
|
||||
#pragma multi_compile_fog
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct appdata
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float2 uv : TEXCOORD0;
|
||||
UNITY_FOG_COORDS(1)
|
||||
float4 vertex : SV_POSITION;
|
||||
};
|
||||
|
||||
sampler2D _MainTex;
|
||||
float4 _MainTex_ST;
|
||||
|
||||
v2f vert (appdata v)
|
||||
{
|
||||
v2f o;
|
||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
|
||||
UNITY_TRANSFER_FOG(o,o.vertex);
|
||||
return o;
|
||||
}
|
||||
|
||||
fixed4 frag (v2f i) : SV_Target
|
||||
{
|
||||
// sample the texture
|
||||
fixed4 col = tex2D(_MainTex, i.uv);
|
||||
// apply fog
|
||||
UNITY_APPLY_FOG(i.fogCoord, col);
|
||||
return col;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e1f5153da774c754aa283cf23fd64d56
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
preprocessorOverride: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
308
UnityProject/Assets/AssetArt/Shader/StandardMobile.cginc
Normal file
308
UnityProject/Assets/AssetArt/Shader/StandardMobile.cginc
Normal file
@@ -0,0 +1,308 @@
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
// DEFINES, CONSTRUCTORS AND STRUCTS
|
||||
|
||||
sampler2D _MainTex;
|
||||
half4 _MainTex_ST;
|
||||
|
||||
// Color, brightness and contrast
|
||||
#if COLOR_ON
|
||||
half4 _Color;
|
||||
half _Brightness;
|
||||
half _Contrast;
|
||||
#endif
|
||||
|
||||
// Phong point light
|
||||
#if PHONG_ON
|
||||
uniform half4 _PointLightColor;
|
||||
uniform half3 _PointLightPosition;
|
||||
|
||||
half _AmbiencePower;
|
||||
half _SpecularPower;
|
||||
half _DiffusePower;
|
||||
#endif
|
||||
|
||||
// Detail map
|
||||
#if DETAIL_ON
|
||||
sampler2D _DetailMap;
|
||||
half _DetailStrength;
|
||||
#endif
|
||||
|
||||
// Detail mask
|
||||
#if DETAIL_ON && DETAIL_MASK_ON
|
||||
sampler2D _DetailMask;
|
||||
#endif
|
||||
|
||||
// Emission map
|
||||
#if EMISSION_ON
|
||||
sampler2D _EmissionMap;
|
||||
half _EmissionStrength;
|
||||
#endif
|
||||
|
||||
// Normal map
|
||||
#if NORMAL_ON
|
||||
sampler2D _NormalMap;
|
||||
#endif
|
||||
|
||||
struct appdata
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
half2 texcoord : TEXCOORD0;
|
||||
#if PHONG_ON
|
||||
float4 normal : NORMAL;
|
||||
#endif
|
||||
#if NORMAL_ON
|
||||
float4 tangent : TANGENT;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct appdata_lm
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
half2 texcoord : TEXCOORD0;
|
||||
half2 texcoord_lm : TEXCOORD1;
|
||||
#if PHONG_ON
|
||||
float4 normal : NORMAL;
|
||||
#endif
|
||||
#if NORMAL_ON
|
||||
float4 tangent : TANGENT;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float4 vertex : SV_POSITION;
|
||||
half2 uv_main : TEXCOORD0;
|
||||
UNITY_FOG_COORDS(1)
|
||||
#if PHONG_ON
|
||||
float4 worldVertex : TEXCOORD2; // worldPos
|
||||
#endif
|
||||
#if PHONG_ON || NORMAL_ON
|
||||
half3 worldNormal : TEXCOORD3;
|
||||
#endif
|
||||
#if NORMAL_ON
|
||||
// these three vectors will hold a 3x3 rotation matrix
|
||||
// that transforms from tangent to world space
|
||||
half3 tspace0 : TEXCOORD4; // tangent.x, bitangent.x, normal.x
|
||||
half3 tspace1 : TEXCOORD5; // tangent.y, bitangent.y, normal.y
|
||||
half3 tspace2 : TEXCOORD6; // tangent.z, bitangent.z, normal.z
|
||||
#endif
|
||||
};
|
||||
|
||||
struct v2f_lm
|
||||
{
|
||||
float4 vertex : SV_POSITION;
|
||||
half2 uv_main : TEXCOORD0;
|
||||
half2 uv_lm : TEXCOORD1;
|
||||
UNITY_FOG_COORDS(2)
|
||||
#if PHONG_ON
|
||||
float4 worldVertex : TEXCOORD3;
|
||||
#endif
|
||||
#if PHONG_ON || NORMAL_ON
|
||||
half3 worldNormal : TEXCOORD4;
|
||||
#endif
|
||||
#if NORMAL_ON
|
||||
// these three vectors will hold a 3x3 rotation matrix
|
||||
// that transforms from tangent to world space
|
||||
half3 tspace0 : TEXCOORD5; // tangent.x, bitangent.x, normal.x
|
||||
half3 tspace1 : TEXCOORD6; // tangent.y, bitangent.y, normal.y
|
||||
half3 tspace2 : TEXCOORD7; // tangent.z, bitangent.z, normal.z
|
||||
#endif
|
||||
};
|
||||
|
||||
// VERTEX SHADERS
|
||||
|
||||
v2f vert(appdata v)
|
||||
{
|
||||
v2f o;
|
||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||
|
||||
#if PHONG_ON
|
||||
o.worldVertex = mul(unity_ObjectToWorld, v.vertex);
|
||||
o.worldNormal = UnityObjectToWorldNormal(v.normal);
|
||||
#endif
|
||||
|
||||
#if NORMAL_ON
|
||||
half3 wTangent = UnityObjectToWorldDir(v.tangent.xyz);
|
||||
// compute bitangent from cross product of normal and tangent
|
||||
half tangentSign = v.tangent.w * unity_WorldTransformParams.w;
|
||||
half3 wBitangent = cross(o.worldNormal, wTangent) * tangentSign;
|
||||
// output the tangent space matrix
|
||||
o.tspace0 = half3(wTangent.x, wBitangent.x, o.worldNormal.x);
|
||||
o.tspace1 = half3(wTangent.y, wBitangent.y, o.worldNormal.y);
|
||||
o.tspace2 = half3(wTangent.z, wBitangent.z, o.worldNormal.z);
|
||||
#endif
|
||||
|
||||
o.uv_main = TRANSFORM_TEX(v.texcoord, _MainTex);
|
||||
UNITY_TRANSFER_FOG(o, o.vertex);
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
v2f_lm vert_lm(appdata_lm v)
|
||||
{
|
||||
v2f_lm o;
|
||||
o.vertex = UnityObjectToClipPos(v.vertex); // XXX: Is this efficient?
|
||||
|
||||
#if PHONG_ON
|
||||
o.worldVertex = mul(unity_ObjectToWorld, v.vertex);
|
||||
o.worldNormal = UnityObjectToWorldNormal(v.normal);
|
||||
#endif
|
||||
|
||||
#if NORMAL_ON && PHONG_ON
|
||||
half3 wTangent = UnityObjectToWorldDir(v.tangent.xyz);
|
||||
// compute bitangent from cross product of normal and tangent
|
||||
half tangentSign = v.tangent.w * unity_WorldTransformParams.w;
|
||||
half3 wBitangent = cross(o.worldNormal, wTangent) * tangentSign;
|
||||
// output the tangent space matrix
|
||||
o.tspace0 = half3(wTangent.x, wBitangent.x, o.worldNormal.x);
|
||||
o.tspace1 = half3(wTangent.y, wBitangent.y, o.worldNormal.y);
|
||||
o.tspace2 = half3(wTangent.z, wBitangent.z, o.worldNormal.z);
|
||||
#endif
|
||||
|
||||
o.uv_main = TRANSFORM_TEX(v.texcoord, _MainTex);
|
||||
// lightmapped uv
|
||||
o.uv_lm = v.texcoord_lm.xy * unity_LightmapST.xy + unity_LightmapST.zw;
|
||||
UNITY_TRANSFER_FOG(o, o.vertex);
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
// FRAGMENT SHADERS
|
||||
|
||||
#if COLOR_ON
|
||||
// Fix the brightness, contrast and color
|
||||
half4 bcc(half4 main_color)
|
||||
{
|
||||
main_color.rgb /= main_color.a;
|
||||
main_color.rgb = ((main_color.rgb - 0.5f) * max(_Contrast, 0)) + 0.5f;
|
||||
main_color.rgb += _Brightness * 0.05;
|
||||
main_color.rgb *= main_color.a;
|
||||
|
||||
//main_color.rgb = lerp(main_color.rgb, _Color.rgb, _Color.a);
|
||||
main_color *= _Color;
|
||||
|
||||
return main_color;
|
||||
}
|
||||
#endif
|
||||
|
||||
fixed4 frag(v2f i) : SV_Target
|
||||
{
|
||||
half4 returnColor = tex2D(_MainTex, i.uv_main);
|
||||
|
||||
#if DETAIL_ON
|
||||
half4 mask = half4(1, 1, 1, 1);
|
||||
#endif
|
||||
#if DETAIL_ON && DETAIL_MASK_ON
|
||||
mask = tex2D(_DetailMask, i.uv_main);
|
||||
#endif
|
||||
#if DETAIL_ON
|
||||
half4 detailMap = tex2D(_DetailMap, i.uv_main) * mask;
|
||||
const fixed3 constantList = fixed3(1.0, 0.5, 0.0);
|
||||
returnColor = (returnColor + _DetailStrength*detailMap) * constantList.xxxz + (returnColor + _DetailStrength*detailMap) * constantList.zzzy;
|
||||
#endif
|
||||
|
||||
#if EMISSION_ON
|
||||
returnColor += tex2D(_EmissionMap, i.uv_main)*_EmissionStrength*0.2;
|
||||
#endif
|
||||
|
||||
#if NORMAL_ON
|
||||
// sample the normal map, and decode from the Unity encoding
|
||||
half3 tnormal = UnpackNormal(tex2D(_NormalMap, i.uv_main));
|
||||
// transform normal from tangent to world space
|
||||
half3 worldNormal;
|
||||
worldNormal.x = dot(i.tspace0, tnormal);
|
||||
worldNormal.y = dot(i.tspace1, tnormal);
|
||||
worldNormal.z = dot(i.tspace2, tnormal);
|
||||
float3 normal = normalize(worldNormal);
|
||||
#endif
|
||||
#if !NORMAL_ON && PHONG_ON
|
||||
float3 normal = normalize(i.worldNormal.xyz);
|
||||
#endif
|
||||
|
||||
#if PHONG_ON
|
||||
float3 localCoords = i.worldVertex.xyz;
|
||||
// ambient intensities
|
||||
half3 amb = returnColor.rgb * unity_AmbientSky * _AmbiencePower;
|
||||
// diffuse intensities
|
||||
half3 L = normalize(_PointLightPosition - localCoords);
|
||||
half LdotN = dot(L, normal);
|
||||
half3 dif = _PointLightColor.rgb * returnColor.rgb * saturate(LdotN) * _DiffusePower;
|
||||
// specular intensities
|
||||
half3 V = normalize(_WorldSpaceCameraPos - localCoords);
|
||||
half3 H = normalize(V+L);
|
||||
half3 spe = _PointLightColor.rgb * pow(saturate(dot(normal, H)), 25) * _SpecularPower;
|
||||
|
||||
returnColor.rgb = lerp(returnColor.rgb, amb.rgb+dif.rgb+spe.rgb, _PointLightColor.a);
|
||||
#endif
|
||||
|
||||
UNITY_APPLY_FOG(i.fogCoord, returnColor);
|
||||
|
||||
#if COLOR_ON
|
||||
returnColor = bcc(returnColor);
|
||||
#endif
|
||||
|
||||
return returnColor;
|
||||
}
|
||||
|
||||
fixed4 frag_lm(v2f_lm i) : SV_Target
|
||||
{
|
||||
half4 returnColor = tex2D(_MainTex, i.uv_main);
|
||||
|
||||
#if DETAIL_ON
|
||||
half4 mask = half4(1, 1, 1, 1);
|
||||
#endif
|
||||
#if DETAIL_ON && DETAIL_MASK_ON
|
||||
mask = tex2D(_DetailMask, i.uv_main);
|
||||
#endif
|
||||
#if DETAIL_ON
|
||||
half4 detailMap = tex2D(_DetailMap, i.uv_main) * mask;
|
||||
const fixed3 constantList = fixed3(1.0, 0.5, 0.0);
|
||||
returnColor = (returnColor + _DetailStrength*detailMap) * constantList.xxxz + (returnColor + _DetailStrength*detailMap) * constantList.zzzy;
|
||||
#endif
|
||||
|
||||
#if EMISSION_ON
|
||||
returnColor += tex2D(_EmissionMap, i.uv_main)*_EmissionStrength/5;
|
||||
#endif
|
||||
returnColor.rgb *= DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap, i.uv_lm));
|
||||
|
||||
#if NORMAL_ON
|
||||
// sample the normal map, and decode from the Unity encoding
|
||||
half3 tnormal = UnpackNormal(tex2D(_NormalMap, i.uv_main));
|
||||
// transform normal from tangent to world space
|
||||
half3 worldNormal;
|
||||
worldNormal.x = dot(i.tspace0, tnormal);
|
||||
worldNormal.y = dot(i.tspace1, tnormal);
|
||||
worldNormal.z = dot(i.tspace2, tnormal);
|
||||
float3 normal = normalize(worldNormal);
|
||||
#endif
|
||||
#if !NORMAL_ON && PHONG_ON
|
||||
float3 normal = normalize(i.worldNormal.xyz);
|
||||
#endif
|
||||
|
||||
#if PHONG_ON
|
||||
float3 localCoords = i.worldVertex.xyz;
|
||||
// ambient intensities
|
||||
half3 amb = returnColor.rgb * unity_AmbientSky * _AmbiencePower;
|
||||
// diffuse intensities
|
||||
half3 L = normalize(_PointLightPosition - localCoords);
|
||||
half LdotN = dot(L, normal);
|
||||
half3 dif = _PointLightColor.rgb * returnColor.rgb * saturate(LdotN) * _DiffusePower;
|
||||
// specular intensities
|
||||
half3 V = normalize(_WorldSpaceCameraPos - localCoords);
|
||||
half3 H = normalize(V+L);
|
||||
half3 spe = _PointLightColor.rgb * pow(saturate(dot(normal, H)), 25) * _SpecularPower;
|
||||
|
||||
returnColor.rgb = lerp(returnColor.rgb, amb.rgb+dif.rgb+spe.rgb, _PointLightColor.a);
|
||||
#endif
|
||||
|
||||
UNITY_APPLY_FOG(i.fogCoord, returnColor);
|
||||
|
||||
#if COLOR_ON
|
||||
returnColor = bcc(returnColor);
|
||||
#endif
|
||||
|
||||
return returnColor;
|
||||
}
|
||||
|
||||
// SURFACE SHADERS
|
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3da53e94e926e0140a44a19326e2b2b3
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
preprocessorOverride: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
110
UnityProject/Assets/AssetArt/Shader/StandardMobile.shader
Normal file
110
UnityProject/Assets/AssetArt/Shader/StandardMobile.shader
Normal file
@@ -0,0 +1,110 @@
|
||||
// Standard shader for mobile
|
||||
// Written by Nihal Mirpuri @nylonee
|
||||
|
||||
Shader "Mobile/Standard"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_MainTex("Albedo", 2D) = "white" {}
|
||||
|
||||
[Toggle(COLOR_ON)] _ColorToggle("Color, Brightness, Contrast Toggle", Int) = 0
|
||||
_Color("Color", Color) = (1,1,1)
|
||||
_Brightness ("Brightness", Range(-10.0, 10.0)) = 0.0
|
||||
_Contrast ("Contrast", Range(0.0, 3.0)) = 1
|
||||
|
||||
[Toggle(PHONG_ON)] _Phong("Point Light Toggle", Int) = 0
|
||||
_PointLightColor("Point Light Color", Color) = (1,1,1,1)
|
||||
_PointLightPosition("Point Light Position", Vector) = (0.0,0.0,0.0)
|
||||
_AmbiencePower("Ambience intensity", Range(0.0,2.0)) = 1.0
|
||||
_SpecularPower("Specular intensity", Range(0.0,2.0)) = 1.0
|
||||
_DiffusePower("Diffuse intensity", Range(0.0,2.0)) = 1.0
|
||||
|
||||
[Toggle(DETAIL_ON)] _Detail("Detail Map Toggle", Int) = 0
|
||||
_DetailMap("Detail Map", 2D) = "white" {}
|
||||
_DetailStrength("Detail Map Strength", Range(0.0, 2.0)) = 1
|
||||
[Toggle(DETAIL_MASK_ON)] _Mask("Detail Mask Toggle", Int) = 0
|
||||
_DetailMask("Detail Mask", 2D) = "white" {}
|
||||
|
||||
[Toggle(EMISSION_ON)] _Emission("Emission Map Toggle", Int) = 0
|
||||
_EmissionMap("Emission", 2D) = "white" {}
|
||||
_EmissionStrength("Emission Strength", Range(0.0,10.0)) = 1
|
||||
|
||||
[Toggle(NORMAL_ON)] _Normal("Normal Map Toggle", Int) = 0
|
||||
_NormalMap("Normal Map", 2D) = "bump" {}
|
||||
}
|
||||
|
||||
SubShader {
|
||||
Tags { "RenderType" = "Opaque" }
|
||||
LOD 150
|
||||
|
||||
// Render the relevant pass based on whether lightmap data is being passed in
|
||||
Pass {
|
||||
Tags { "LightMode" = "VertexLM" }
|
||||
Lighting Off
|
||||
Cull Back
|
||||
CGPROGRAM
|
||||
#pragma vertex vert_lm
|
||||
#pragma fragment frag_lm
|
||||
|
||||
#pragma multi_compile_fog
|
||||
#pragma skip_variants FOG_LINEAR FOG_EXP
|
||||
|
||||
#pragma shader_feature COLOR_ON
|
||||
#pragma shader_feature PHONG_ON
|
||||
#pragma shader_feature DETAIL_ON
|
||||
#pragma shader_feature DETAIL_MASK_ON
|
||||
#pragma shader_feature EMISSION_ON
|
||||
#pragma shader_feature NORMAL_ON
|
||||
|
||||
#include "StandardMobile.cginc"
|
||||
ENDCG
|
||||
}
|
||||
|
||||
Pass {
|
||||
Tags { "LightMode" = "VertexLMRGBM" }
|
||||
Lighting Off
|
||||
Cull Back
|
||||
CGPROGRAM
|
||||
#pragma vertex vert_lm
|
||||
#pragma fragment frag_lm
|
||||
|
||||
#pragma multi_compile_fog
|
||||
#pragma skip_variants FOG_LINEAR FOG_EXP
|
||||
|
||||
#pragma shader_feature COLOR_ON
|
||||
#pragma shader_feature PHONG_ON
|
||||
#pragma shader_feature DETAIL_ON
|
||||
#pragma shader_feature DETAIL_MASK_ON
|
||||
#pragma shader_feature EMISSION_ON
|
||||
#pragma shader_feature NORMAL_ON
|
||||
|
||||
#include "StandardMobile.cginc"
|
||||
ENDCG
|
||||
}
|
||||
|
||||
Pass {
|
||||
Tags { "LightMode" = "Vertex" }
|
||||
Lighting Off
|
||||
Cull Back
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#pragma multi_compile_fog
|
||||
#pragma skip_variants FOG_LINEAR FOG_EXP
|
||||
|
||||
#pragma shader_feature COLOR_ON
|
||||
#pragma shader_feature PHONG_ON
|
||||
#pragma shader_feature DETAIL_ON
|
||||
#pragma shader_feature DETAIL_MASK_ON
|
||||
#pragma shader_feature EMISSION_ON
|
||||
#pragma shader_feature NORMAL_ON
|
||||
|
||||
#include "StandardMobile.cginc"
|
||||
ENDCG
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
FallBack "Mobile/VertexLit"
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ba67c8b1d5e59dc428ad9fc9270f8353
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
preprocessorOverride: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user