DanMillerDev
5 年前
当前提交
767432ee
共有 10 个文件被更改,包括 433 次插入 和 233 次删除
-
394Assets/Shaders/Scenes/Fog.unity
-
14Assets/Shaders/Scripts/ApplyFog.cs
-
1ProjectSettings/GraphicsSettings.asset
-
4ProjectSettings/ProjectSettings.asset
-
89Assets/Shaders/Materials/ARCoreFogMat.mat
-
8Assets/Shaders/Materials/ARCoreFogMat.mat.meta
-
131Assets/Shaders/Shaders/ARCoreFogBackground.shader
-
9Assets/Shaders/Shaders/ARCoreFogBackground.shader.meta
-
8Assets/StreamingAssets.meta
-
8Assets/ARFoundationDemos.meta
|
|||
using System; |
|||
using System.Text; |
|||
using Unity.Collections.LowLevel.Unsafe; |
|||
using UnityEngine.XR.ARFoundation; |
|||
using UnityEngine.XR.ARSubsystems; |
|||
namespace UnityEngine.XR.ARFoundation.Samples |
|||
public class ApplyFog : MonoBehaviour |
|||
public class ApplyFog : MonoBehaviour |
|||
public void OnSliderValueChanged(Slider slider) |
|||
public void OnSliderValueChanged(Slider slider) |
|||
{ |
|||
RenderSettings.fogEndDistance = slider.value; |
|||
} |
|||
RenderSettings.fogEndDistance = slider.value; |
|||
|
|
|||
%YAML 1.1 |
|||
%TAG !u! tag:unity3d.com,2011: |
|||
--- !u!21 &2100000 |
|||
Material: |
|||
serializedVersion: 6 |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_Name: ARCoreFogMat |
|||
m_Shader: {fileID: 4800000, guid: 07e2ffb48a3a30f43a41cd1fe7e54dab, type: 3} |
|||
m_ShaderKeywords: |
|||
m_LightmapFlags: 4 |
|||
m_EnableInstancingVariants: 0 |
|||
m_DoubleSidedGI: 0 |
|||
m_CustomRenderQueue: -1 |
|||
stringTagMap: {} |
|||
disabledShaderPasses: [] |
|||
m_SavedProperties: |
|||
serializedVersion: 3 |
|||
m_TexEnvs: |
|||
- _BumpMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _DetailAlbedoMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _DetailMask: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _DetailNormalMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _EmissionMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _EnvironmentDepth: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _MainTex: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _MetallicGlossMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _OcclusionMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _ParallaxMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _textureCbCr: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _textureY: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
m_Floats: |
|||
- _BumpScale: 1 |
|||
- _Cutoff: 0.5 |
|||
- _DetailNormalMapScale: 1 |
|||
- _DstBlend: 0 |
|||
- _GlossMapScale: 1 |
|||
- _Glossiness: 0.5 |
|||
- _GlossyReflections: 1 |
|||
- _Metallic: 0 |
|||
- _Mode: 0 |
|||
- _OcclusionStrength: 1 |
|||
- _Parallax: 0.02 |
|||
- _SmoothnessTextureChannel: 0 |
|||
- _SpecularHighlights: 1 |
|||
- _SrcBlend: 1 |
|||
- _UVSec: 0 |
|||
- _ZWrite: 1 |
|||
m_Colors: |
|||
- _Color: {r: 1, g: 1, b: 1, a: 1} |
|||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1} |
|
|||
fileFormatVersion: 2 |
|||
guid: 2d3391376819f824a93a55c30a301abc |
|||
NativeFormatImporter: |
|||
externalObjects: {} |
|||
mainObjectFileID: 0 |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
Shader "Custom/ARCoreFogBackground" |
|||
{ |
|||
Properties |
|||
{ |
|||
_MainTex("Texture", 2D) = "white" {} |
|||
_EnvironmentDepth("Texture", 2D) = "black" {} |
|||
} |
|||
|
|||
SubShader |
|||
{ |
|||
Tags |
|||
{ |
|||
"Queue" = "Background" |
|||
"RenderType" = "Background" |
|||
"ForceNoShadowCasting" = "True" |
|||
} |
|||
|
|||
Pass |
|||
{ |
|||
Cull Off |
|||
ZTest Always |
|||
ZWrite On |
|||
Lighting Off |
|||
LOD 100 |
|||
Tags |
|||
{ |
|||
"LightMode" = "Always" |
|||
} |
|||
|
|||
GLSLPROGRAM |
|||
|
|||
#pragma multi_compile_local __ ARCORE_ENVIRONMENT_DEPTH_ENABLED |
|||
|
|||
#pragma only_renderers gles3 |
|||
|
|||
#include "UnityCG.glslinc" |
|||
|
|||
#ifdef SHADER_API_GLES3 |
|||
#extension GL_OES_EGL_image_external_essl3 : require |
|||
#endif // SHADER_API_GLES3 |
|||
|
|||
// Device display transform is provided by the AR Foundation camera background renderer. |
|||
uniform mat4 _UnityDisplayTransform; |
|||
|
|||
#ifdef VERTEX |
|||
varying vec2 textureCoord; |
|||
|
|||
void main() |
|||
{ |
|||
#ifdef SHADER_API_GLES3 |
|||
// Transform the position from object space to clip space. |
|||
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; |
|||
|
|||
// Remap the texture coordinates based on the device rotation. |
|||
textureCoord = (_UnityDisplayTransform * vec4(gl_MultiTexCoord0.x, 1.0f - gl_MultiTexCoord0.y, 1.0f, 0.0f)).xy; |
|||
#endif // SHADER_API_GLES3 |
|||
} |
|||
#endif // VERTEX |
|||
|
|||
#ifdef FRAGMENT |
|||
varying vec2 textureCoord; |
|||
uniform samplerExternalOES _MainTex; |
|||
|
|||
#ifdef ARCORE_ENVIRONMENT_DEPTH_ENABLED |
|||
uniform sampler2D _EnvironmentDepth; |
|||
#endif // ARCORE_ENVIRONMENT_DEPTH_ENABLED |
|||
|
|||
#if defined(SHADER_API_GLES3) && !defined(UNITY_COLORSPACE_GAMMA) |
|||
float GammaToLinearSpaceExact (float value) |
|||
{ |
|||
if (value <= 0.04045F) |
|||
return value / 12.92F; |
|||
else if (value < 1.0F) |
|||
return pow((value + 0.055F)/1.055F, 2.4F); |
|||
else |
|||
return pow(value, 2.2F); |
|||
} |
|||
|
|||
vec3 GammaToLinearSpace (vec3 sRGB) |
|||
{ |
|||
// Approximate version from http://chilliant.blogspot.com.au/2012/08/srgb-approximations-for-hlsl.html?m=1 |
|||
return sRGB * (sRGB * (sRGB * 0.305306011F + 0.682171111F) + 0.012522878F); |
|||
|
|||
// Precise version, useful for debugging, but the pow() function is too slow. |
|||
// return vec3(GammaToLinearSpaceExact(sRGB.r), GammaToLinearSpaceExact(sRGB.g), GammaToLinearSpaceExact(sRGB.b)); |
|||
} |
|||
|
|||
#endif // SHADER_API_GLES3 && !UNITY_COLORSPACE_GAMMA |
|||
|
|||
float ConvertDistanceToDepth(float d) |
|||
{ |
|||
float zBufferParamsW = 1.0 / _ProjectionParams.y; |
|||
float zBufferParamsY = _ProjectionParams.z * zBufferParamsW; |
|||
float zBufferParamsX = 1.0 - zBufferParamsY; |
|||
float zBufferParamsZ = zBufferParamsX * _ProjectionParams.w; |
|||
|
|||
// Clip any distances smaller than the near clip plane, and compute the depth value from the distance. |
|||
return (d < _ProjectionParams.y) ? 1.0f : ((1.0 / zBufferParamsZ) * ((1.0 / d) - zBufferParamsW)); |
|||
} |
|||
|
|||
void main() |
|||
{ |
|||
#ifdef SHADER_API_GLES3 |
|||
vec3 result = texture(_MainTex, textureCoord).xyz; |
|||
float depth = 1.0; |
|||
#ifndef UNITY_COLORSPACE_GAMMA |
|||
result = GammaToLinearSpace(result); |
|||
#endif // !UNITY_COLORSPACE_GAMMA |
|||
|
|||
#ifdef ARCORE_ENVIRONMENT_DEPTH_ENABLED |
|||
float distance = texture(_EnvironmentDepth, textureCoord).x; |
|||
depth = ConvertDistanceToDepth(distance); |
|||
#if defined(FOG_LINEAR) || defined(FOG_EXP) || defined(FOG_EXP2) |
|||
UNITY_CALC_FOG_FACTOR(depth); |
|||
UNITY_FOG_LERP_COLOR(result, unity_FogColor, unityFogFactor); |
|||
#endif // defined(FOG_LINEAR) || defined(FOG_EXP) || defined(FOG_EXP2) |
|||
|
|||
#endif // ARCORE_ENVIRONMENT_DEPTH_ENABLED |
|||
|
|||
gl_FragColor = vec4(result, 1.0); |
|||
gl_FragDepth = depth; |
|||
#endif // SHADER_API_GLES3 |
|||
} |
|||
|
|||
#endif // FRAGMENT |
|||
ENDGLSL |
|||
} |
|||
} |
|||
|
|||
FallBack Off |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 07e2ffb48a3a30f43a41cd1fe7e54dab |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: c3431710a7637a04089ba8f7b922b339 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: faeaceca7df854ff49277ef3f74f530f |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue