Added window imposter shader and material

This commit is contained in:
raccoon
2024-11-28 04:33:51 +05:00
parent 5b9da97aed
commit a5fbcbef08
5 changed files with 179 additions and 0 deletions

View File

@@ -0,0 +1,87 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 8
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: dev_windowimposter
m_Shader: {fileID: 4800000, guid: 6e36733ecafa0ce46b70364ace1c77f0, type: 3}
m_Parent: {fileID: 0}
m_ModifiedSerializedProperties: 0
m_ValidKeywords: []
m_InvalidKeywords: []
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_LockedProperties:
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}
- _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}
m_Ints: []
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Opacity: 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}
- _ReflectionProbeBoxMax: {r: 0, g: 0, b: 0, a: 0}
- _ReflectionProbeBoxMin: {r: 0, g: 0, b: 0, a: 0}
- _ReflectionProbePosition: {r: 0, g: 0, b: 0, a: 0}
m_BuildTextureStacks: []

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 80f407b5d22a47a45bcdd86e7fd9215c
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b5168b5cf00925f4799caea2da17e9fd
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,67 @@
// Original code from https://gist.github.com/josephbk117/a43f5335cea9b3e12a44f196dc81f30f
Shader "Custom/InteriorImposterShader"
{
Properties
{
}
SubShader
{
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float3 normal : NORMAL;
};
struct v2f
{
float3 worldPos : TEXCOORD0;
float3 worldNormal : TEXCOORD1;
float4 pos : SV_POSITION;
};
v2f vert (appdata v)
{
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
o.worldNormal = UnityObjectToWorldNormal(v.normal);
return o;
}
// ChatGPT snippet
float3 BoxProjectReflectionDir(float3 worldPos, float3 worldRefl)
{
// Calculate relative position within the box
float3 boxMin = unity_SpecCube0_BoxMin.xyz;
float3 boxMax = unity_SpecCube0_BoxMax.xyz;
float3 boxCenter = 0.5 * (boxMin + boxMax);
float3 boxSize = boxMax - boxMin;
float3 localPos = worldPos - boxCenter;
float3 absLocalRefl = abs(worldRefl);
// Scale the reflection vector based on which side of the box it hits
float3 scale = boxSize / absLocalRefl;
float scaleMin = min(min(scale.x, scale.y), scale.z);
return localPos + worldRefl * scaleMin;
}
fixed4 frag (v2f i) : SV_Target
{
half3 worldViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); // Direction of ray from the camera towards the object surface
half4 skyData = UNITY_SAMPLE_TEXCUBE(unity_SpecCube0, BoxProjectReflectionDir(i.worldPos, -worldViewDir));
half3 skyColor = DecodeHDR(skyData, unity_SpecCube0_HDR); // This is done becasue the cubemap is stored HDR
return half4(skyColor, 1.0);
}
ENDCG
}
}
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 6e36733ecafa0ce46b70364ace1c77f0
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant: