浏览代码

add a new shader using 8 textures layers

/batch_rendering
Arnaud Carre 8 年前
当前提交
0e9c9040
共有 12 个文件被更改,包括 628 次插入459 次删除
  1. 35
      Assets/BasicRenderBatching/BasicMat_Colors.mat
  2. 35
      Assets/BasicRenderBatching/BasicMat_ColorsFlat.mat
  3. 10
      Assets/BasicRenderBatching/Scripts/PopulateScene.cs
  4. 121
      Assets/BasicRenderBatching/Textures/numbers/1.png
  5. 150
      Assets/BasicRenderBatching/Textures/numbers/2.png
  6. 96
      Assets/BasicRenderBatching/Textures/numbers/3.png
  7. 122
      Assets/BasicRenderBatching/Textures/numbers/5.png
  8. 108
      Assets/BasicRenderBatching/Textures/numbers/6.png
  9. 68
      Assets/BasicRenderBatching/Textures/numbers/7.png
  10. 150
      Assets/BasicRenderBatching/Textures/numbers/8.png
  11. 175
      Assets/BasicRenderBatching/BasicRenderBatchingShader8.shader
  12. 17
      Assets/BasicRenderBatching/BasicRenderBatchingShader8.shader.meta

35
Assets/BasicRenderBatching/BasicMat_Colors.mat


m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: BasicMat_Colors
m_Shader: {fileID: 4800000, guid: 88dc421b065e08e4caeb32d940c57312, type: 3}
m_Shader: {fileID: 4800000, guid: 915ec92038355ed418b43639259468cc, type: 3}
m_ShaderKeywords: _EMISSION _METALLICGLOSSMAP
m_LightmapFlags: 1
m_CustomRenderQueue: -1

m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- myTexture1:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- myTexture2:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- myTexture3:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- myTexture4:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- myTexture5:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- myTexture6:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- myTexture7:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- myTexture8:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5

m_Colors:
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- myColor: {r: 1, g: 1, b: 1, a: 1}

35
Assets/BasicRenderBatching/BasicMat_ColorsFlat.mat


m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: BasicMat_ColorsFlat
m_Shader: {fileID: 4800000, guid: 88dc421b065e08e4caeb32d940c57312, type: 3}
m_Shader: {fileID: 4800000, guid: 915ec92038355ed418b43639259468cc, type: 3}
m_ShaderKeywords: _EMISSION
m_LightmapFlags: 1
m_CustomRenderQueue: -1

m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- myTexture1:
m_Texture: {fileID: 2800000, guid: 4425fca2a65e78c49b2415476d1cc5ec, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- myTexture2:
m_Texture: {fileID: 2800000, guid: 04b429f47f1e0d54ca799a2a31986801, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- myTexture3:
m_Texture: {fileID: 2800000, guid: 70233265683595f468e46f6300a0c7f5, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- myTexture4:
m_Texture: {fileID: 2800000, guid: b94537f3a7934f84a9e66c662bc06800, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- myTexture5:
m_Texture: {fileID: 2800000, guid: ff3ba92a36048274ab6eb2ec4567fa44, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- myTexture6:
m_Texture: {fileID: 2800000, guid: 2d69bdda1399802499987e9f68ae88ed, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- myTexture7:
m_Texture: {fileID: 2800000, guid: 14d974c88ade21747938eb13f6cfc152, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- myTexture8:
m_Texture: {fileID: 2800000, guid: 8e18cf146b7c0d0449454cdeb8653d94, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5

m_Colors:
- _Color: {r: 0.97794116, g: 0, b: 0, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- myColor: {r: 1, g: 1, b: 1, a: 1}

10
Assets/BasicRenderBatching/Scripts/PopulateScene.cs


Color oColor = new Color(Random.value, Random.value, Random.value, 1.0f);
mat.SetColor("myColor", oColor);
int t = Random.Range(0, 7 + 1);
mat.SetTexture("_MainTex", m_Textures[t]);
mat.SetTexture("myTexture1", m_Textures[Random.Range(0, 7 + 1)]);
mat.SetTexture("myTexture2", m_Textures[Random.Range(0, 7 + 1)]);
mat.SetTexture("myTexture3", m_Textures[Random.Range(0, 7 + 1)]);
mat.SetTexture("myTexture4", m_Textures[Random.Range(0, 7 + 1)]);
mat.SetTexture("myTexture5", m_Textures[Random.Range(0, 7 + 1)]);
mat.SetTexture("myTexture6", m_Textures[Random.Range(0, 7 + 1)]);
mat.SetTexture("myTexture7", m_Textures[Random.Range(0, 7 + 1)]);
mat.SetTexture("myTexture8", m_Textures[Random.Range(0, 7 + 1)]);
mat.InitUniformBuffers();

121
Assets/BasicRenderBatching/Textures/numbers/1.png

之前 之后
宽度: 256  |  高度: 256  |  大小: 12 KiB

150
Assets/BasicRenderBatching/Textures/numbers/2.png

之前 之后
宽度: 256  |  高度: 256  |  大小: 18 KiB

96
Assets/BasicRenderBatching/Textures/numbers/3.png

之前 之后
宽度: 256  |  高度: 256  |  大小: 16 KiB

122
Assets/BasicRenderBatching/Textures/numbers/5.png

之前 之后
宽度: 256  |  高度: 256  |  大小: 15 KiB

108
Assets/BasicRenderBatching/Textures/numbers/6.png

之前 之后
宽度: 256  |  高度: 256  |  大小: 17 KiB

68
Assets/BasicRenderBatching/Textures/numbers/7.png

之前 之后
宽度: 256  |  高度: 256  |  大小: 13 KiB

150
Assets/BasicRenderBatching/Textures/numbers/8.png

之前 之后
宽度: 256  |  高度: 256  |  大小: 19 KiB

175
Assets/BasicRenderBatching/BasicRenderBatchingShader8.shader


// Upgrade NOTE: replaced 'glstate_matrix_invtrans_modelview0' with 'UNITY_MATRIX_IT_MV'
// Upgrade NOTE: replaced 'glstate_matrix_modelview0' with 'UNITY_MATRIX_MV'
// Upgrade NOTE: replaced 'glstate_matrix_mvp' with 'UNITY_MATRIX_MVP'
// Example shader for a scriptable render loop that calculates multiple lights
// in a single forward-rendered shading pass. Uses same PBR shading model as the
// Standard shader.
//
// The parameters and inspector of the shader are the same as Standard shader,
// for easier experimentation.
Shader "RenderLoop/Batching/Standard8"
{
// Properties is just a copy of Standard.shader. Our example shader does not use all of them,
// but the inspector UI expects all these to exist.
Properties
{
// _Color("Color", Color) = (1,1,1,1)
myColor("Color", Color) = (1,1,1,1)
myTexture1("Albedo1", 2D) = "white" {}
myTexture2("Albedo2", 2D) = "white" {}
myTexture3("Albedo3", 2D) = "white" {}
myTexture4("Albedo4", 2D) = "white" {}
myTexture5("Albedo5", 2D) = "white" {}
myTexture6("Albedo6", 2D) = "white" {}
myTexture7("Albedo7", 2D) = "white" {}
myTexture8("Albedo8", 2D) = "white" {}
// [HideInInspector] _Mode("__mode", Float) = 0.0
// [HideInInspector] _SrcBlend("__src", Float) = 1.0
// [HideInInspector] _DstBlend("__dst", Float) = 0.0
// [HideInInspector] _ZWrite("__zw", Float) = 1.0
}
SubShader
{
Tags { "RenderType" = "Opaque" "PerformanceChecks" = "False" }
LOD 300
// Multiple lights at once pass, for our example Basic render loop.
Pass
{
Tags { "LightMode" = "BasicPass" }
// Use same blending / depth states as Standard shader
Blend One Zero
ZWrite On
CGPROGRAM
#pragma target 3.0
#pragma vertex vert
#pragma fragment frag
//#pragma shader_feature _METALLICGLOSSMAP
//#include "UnityCG.cginc"
#include "HLSLSupport.cginc"
//float4 _Color;
// Global lighting data (setup from C# code once per frame).
CBUFFER_START(GlobalLightData)
// The variables are very similar to built-in unity_LightColor, unity_LightPosition,
// unity_LightAtten, unity_SpotDirection as used by the VertexLit shaders, except here
// we use world space positions instead of view space.
half4 globalLightColor[8];
float4 globalLightPos[8];
float4 globalLightSpotDir[8];
float4 globalLightAtten[8];
int4 globalLightCount;
// Global ambient/SH probe, similar to unity_SH* built-in variables.
float4 globalSH[7];
CBUFFER_END
CBUFFER_START(UniformBuffer_FastBatch : register(b1) )
float4 myColor;
CBUFFER_END
/*
CBUFFER_START(UnityPerDraw) // 352 bytes, uploaded per object (even if just position change position )
float4x4 UNITY_MATRIX_MVP;
float4x4 UNITY_MATRIX_MV;
float4x4 UNITY_MATRIX_IT_MV;
float4x4 unity_ObjectToWorld;
float4x4 unity_WorldToObject;
float4 unity_LODFade; // x is the fade value ranging within [0,1]. y is x quantized into 16 levels
float4 unity_WorldTransformParams; // w is usually 1.0, or -1.0 for odd-negative scale transforms
CBUFFER_END
*/
// Compute attenuation & illumination from one light
half3 EvaluateOneLight(int idx, float3 positionWS, half3 normalWS, float3 vAlbedo)
{
// direction to light
float3 dirToLight = globalLightPos[idx].xyz;
dirToLight -= positionWS * globalLightPos[idx].w;
// distance attenuation
float att = 1.0;
float distSqr = dot(dirToLight, dirToLight);
att /= (1.0 + globalLightAtten[idx].z * distSqr);
if (globalLightPos[idx].w != 0 && distSqr > globalLightAtten[idx].w) att = 0.0; // set to 0 if outside of range
distSqr = max(distSqr, 0.000001); // don't produce NaNs if some vertex position overlaps with the light
dirToLight *= rsqrt(distSqr);
// spotlight angular attenuation
// Fill in light & indirect structures, and evaluate Standard BRDF
half3 light = globalLightColor[idx].rgb * att;
half3 c = dot(dirToLight, normalWS) * light * vAlbedo;
return c;
}
sampler2D myTexture1;
sampler2D myTexture2;
sampler2D myTexture3;
sampler2D myTexture4;
sampler2D myTexture5;
sampler2D myTexture6;
sampler2D myTexture7;
sampler2D myTexture8;
// Vertex shader
struct v2f // vertex to fragment
{
float2 uv : TEXCOORD0;
float3 positionWS : TEXCOORD1;
float3 normalWS : TEXCOORD2;
float4 hpos : SV_POSITION;
};
struct s2v // stream to vertex
{
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 texcoord : TEXCOORD0;
};
v2f vert(s2v v)
{
v2f o;
o.uv = v.texcoord.xy;
o.hpos = mul(UNITY_MATRIX_MVP, v.vertex);
o.positionWS = mul(unity_ObjectToWorld, v.vertex).xyz;
o.normalWS = normalize(mul((float3x3)unity_WorldToObject, v.normal));
return o;
}
// Fragment shader
half4 frag(v2f i) : SV_Target
{
i.normalWS = normalize(i.normalWS);
float4 color;
float4 diffuseAlbedo = float4(0, 0, 0, 0);
diffuseAlbedo += tex2D(myTexture1, i.uv);
diffuseAlbedo += tex2D(myTexture2, i.uv);
diffuseAlbedo += tex2D(myTexture3, i.uv);
diffuseAlbedo += tex2D(myTexture4, i.uv);
diffuseAlbedo += tex2D(myTexture5, i.uv);
diffuseAlbedo += tex2D(myTexture6, i.uv);
diffuseAlbedo += tex2D(myTexture7, i.uv);
diffuseAlbedo += tex2D(myTexture8, i.uv);
color = half4(EvaluateOneLight(0, i.positionWS, i.normalWS, diffuseAlbedo.rgb * myColor.rgb),1);
return color;
}
ENDCG
}
}
CustomEditor "StandardShaderGUI"
}

17
Assets/BasicRenderBatching/BasicRenderBatchingShader8.shader.meta


fileFormatVersion: 2
guid: 915ec92038355ed418b43639259468cc
timeCreated: 1483608332
licenseType: Pro
ShaderImporter:
defaultTextures:
- myTexture1: {fileID: 2800000, guid: 4425fca2a65e78c49b2415476d1cc5ec, type: 3}
- myTexture2: {fileID: 2800000, guid: 04b429f47f1e0d54ca799a2a31986801, type: 3}
- myTexture3: {fileID: 2800000, guid: 70233265683595f468e46f6300a0c7f5, type: 3}
- myTexture4: {fileID: 2800000, guid: b94537f3a7934f84a9e66c662bc06800, type: 3}
- myTexture5: {fileID: 2800000, guid: ff3ba92a36048274ab6eb2ec4567fa44, type: 3}
- myTexture6: {fileID: 2800000, guid: 2d69bdda1399802499987e9f68ae88ed, type: 3}
- myTexture7: {fileID: 2800000, guid: 14d974c88ade21747938eb13f6cfc152, type: 3}
- myTexture8: {fileID: 2800000, guid: 8e18cf146b7c0d0449454cdeb8653d94, type: 3}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存