private static void PrepareTextureForRuntime() { if (Object.op_Equality((Object)CoreEnvBrdfLut.runtimeEnvBrdfLut, (Object)null)) { CoreEnvBrdfLut.runtimeEnvBrdfLut = CoreEnvBrdfLut.Generate(false); } Shader.SetGlobalTexture("_EnvBrdfLut", (Texture)CoreEnvBrdfLut.runtimeEnvBrdfLut); }
private static void PrepareTextureForRuntime() { if (CoreEnvBrdfLut.runtimeEnvBrdfLut == null) { CoreEnvBrdfLut.runtimeEnvBrdfLut = CoreEnvBrdfLut.Generate(false); } Shader.SetGlobalTexture("_EnvBrdfLut", CoreEnvBrdfLut.runtimeEnvBrdfLut); }
public static Texture2D Generate(bool asset = false) { TextureFormat textureFormat1 = asset ? (TextureFormat)17 : (TextureFormat)16; TextureFormat textureFormat2 = SystemInfo.SupportsTextureFormat(textureFormat1) ? textureFormat1 : (TextureFormat)5; int num1 = 128; int num2 = 32; float num3 = 1f / (float)num1; float num4 = 1f / (float)num2; Texture2D texture2D = new Texture2D(num1, num2, textureFormat2, false, true); ((Object)texture2D).set_name("_EnvBrdfLut"); ((Texture)texture2D).set_wrapMode((TextureWrapMode)1); ((Texture)texture2D).set_filterMode((FilterMode)1); Color[] colorArray = new Color[num1 * num2]; float num5 = 1f / 128f; for (int index = 0; index < num2; ++index) { double num6 = (double)((float)index + 0.5f) * (double)num4; float num7 = (float)(num6 * num6); float num8 = num7 * num7; int num9 = 0; int num10 = index * num1; for (; num9 < num1; ++num9) { float num11 = ((float)num9 + 0.5f) * num3; Vector3 vector3_1; ((Vector3) ref vector3_1).\u002Ector(Mathf.Sqrt((float)(1.0 - (double)num11 * (double)num11)), 0.0f, num11); float num12 = 0.0f; float num13 = 0.0f; for (uint Bits = 0; Bits < 128U; ++Bits) { float num14 = (float)Bits * num5; float num15 = (float)CoreEnvBrdfLut.ReverseBits(Bits) / (float)uint.MaxValue; float num16 = 6.283185f * num14; float num17 = Mathf.Sqrt((float)((1.0 - (double)num15) / (1.0 + ((double)num8 - 1.0) * (double)num15))); float num18 = Mathf.Sqrt((float)(1.0 - (double)num17 * (double)num17)); Vector3 vector3_2; ((Vector3) ref vector3_2).\u002Ector(num18 * Mathf.Cos(num16), num18 * Mathf.Sin(num16), num17); float num19 = Mathf.Max((float)Vector3.op_Subtraction(Vector3.op_Multiply(2f * Vector3.Dot(vector3_1, vector3_2), vector3_2), vector3_1).z, 0.0f); float num20 = Mathf.Max((float)vector3_2.z, 0.0f); float num21 = Mathf.Max(Vector3.Dot(vector3_1, vector3_2), 0.0f); if ((double)num19 > 0.0) { float num22 = (float)(0.5 / ((double)(num19 * (num11 * (1f - num7) + num7)) + (double)(num11 * (num19 * (1f - num7) + num7)))); float num23 = (float)((double)num19 * (double)num22 * (4.0 * (double)num21 / (double)num20)); float num24 = 1f - num21; float num25 = num24 * (float)((double)num24 * (double)num24 * ((double)num24 * (double)num24)); num12 += num23 * (1f - num25); num13 += num23 * num25; } } float num26 = Mathf.Clamp(num12 * num5, 0.0f, 1f); float num27 = Mathf.Clamp(num13 * num5, 0.0f, 1f); colorArray[num10++] = new Color(num26, num27, 0.0f, 0.0f); } } texture2D.SetPixels(colorArray); texture2D.Apply(false, !asset); return(texture2D); }
private static void OnRuntimeLoad() { CoreEnvBrdfLut.PrepareTextureForRuntime(); CoreEnvBrdfLut.UpdateReflProbe(); }
public static Texture2D Generate(bool asset = false) { TextureFormat textureFormat = (asset ? TextureFormat.RGBAHalf : TextureFormat.RGHalf); textureFormat = (SystemInfo.SupportsTextureFormat(textureFormat) ? textureFormat : TextureFormat.ARGB32); int num = 128; int num1 = 32; float single = 1f / (float)num; float single1 = 1f / (float)num1; Texture2D texture2D = new Texture2D(num, num1, textureFormat, false, true) { name = "_EnvBrdfLut", wrapMode = TextureWrapMode.Clamp, filterMode = FilterMode.Bilinear }; Color[] color = new Color[num * num1]; float single2 = 0.0078125f; for (int i = 0; i < num1; i++) { float single3 = (float)((float)i + 0.5f) * single1; float single4 = single3 * single3; float single5 = single4 * single4; int num2 = 0; int num3 = i * num; while (num2 < num) { float single6 = (float)((float)num2 + 0.5f) * single; Vector3 vector3 = new Vector3(Mathf.Sqrt(1f - single6 * single6), 0f, single6); float single7 = 0f; float single8 = 0f; for (uint j = 0; j < 128; j++) { float single9 = (float)((float)j) * single2; float single10 = (float)((double)((float)CoreEnvBrdfLut.ReverseBits(j)) / 4294967296); float single11 = 6.28318548f * single9; float single12 = Mathf.Sqrt((1f - single10) / (1f + (single5 - 1f) * single10)); float single13 = Mathf.Sqrt(1f - single12 * single12); Vector3 vector31 = new Vector3(single13 * Mathf.Cos(single11), single13 * Mathf.Sin(single11), single12); float single14 = Mathf.Max(((2f * Vector3.Dot(vector3, vector31) * vector31) - vector3).z, 0f); float single15 = Mathf.Max(vector31.z, 0f); float single16 = Mathf.Max(Vector3.Dot(vector3, vector31), 0f); if (single14 > 0f) { float single17 = single14 * (single6 * (1f - single4) + single4); float single18 = single6 * (single14 * (1f - single4) + single4); float single19 = 0.5f / (single17 + single18); float single20 = single14 * single19 * (4f * single16 / single15); float single21 = 1f - single16; single21 = single21 * (single21 * single21 * (single21 * single21)); single7 = single7 + single20 * (1f - single21); single8 = single8 + single20 * single21; } } single7 = Mathf.Clamp(single7 * single2, 0f, 1f); single8 = Mathf.Clamp(single8 * single2, 0f, 1f); int num4 = num3; num3 = num4 + 1; color[num4] = new Color(single7, single8, 0f, 0f); num2++; } } texture2D.SetPixels(color); texture2D.Apply(false, !asset); return(texture2D); }