private float4 readliner(float3 uvw, MipLevel level) { float2 uv = uvw.xy * new float2(level.width, level.height); float2 uv1 = warp(uv - 0.5, level); float2 uv2 = warp(uv + 0.5, level); int i0 = (int)Mathf.floor(uv1.x) % level.width; int j0 = (int)Mathf.floor(uv1.y) % level.height; int i1 = (int)Mathf.floor(uv2.x) % level.width; int j1 = (int)Mathf.floor(uv2.y) % level.height; float alpha = Shader.frac(uv.x - 0.5f); float beta = Shader.frac(uv.y - 0.5f); float4 Ti0j0 = level.texuteData[i0][j0]; float4 Ti1j0 = level.texuteData[i1][j0]; float4 Ti0j1 = level.texuteData[i0][j1]; float4 Ti1j1 = level.texuteData[i1][j1]; return((1 - alpha) * (1 - beta) * Ti0j0 + alpha * (1 - beta) * Ti1j0 + (1 - alpha) * beta * Ti0j1 + alpha * beta * Ti1j1); }
void Alloc(CommandBuffer cmd, int id, MipLevel size, RenderTextureFormat format, bool uav, bool dynamicScale) { int sizeId = (int)size; cmd.GetTemporaryRT(id, new RenderTextureDescriptor { #if UNITY_2019_4_OR_NEWER width = m_Widths[sizeId], height = m_Heights[sizeId], #else width = m_ScaledWidths[sizeId], height = m_ScaledHeights[sizeId], #endif colorFormat = format, depthBufferBits = 0, volumeDepth = 1, autoGenerateMips = false, msaaSamples = 1, #if UNITY_2019_2_OR_NEWER mipCount = 1, #endif #if UNITY_2019_4_OR_NEWER useDynamicScale = dynamicScale, #endif enableRandomWrite = uav, dimension = TextureDimension.Tex2D, sRGB = false }, FilterMode.Point); }
private float4 readpixel(float3 uvw, MipLevel level) { float2 uv1 = warp(uvw.xy * new float2(level.width, level.height) + 0.5, level); int i0 = (int)Mathf.floor(uv1.x) % level.width; int j0 = (int)Mathf.floor(uv1.y) % level.height; return(level.texuteData[i0][j0]); }
/// <inheritdoc/> public override int GetHashCode() { unchecked { int hashCode = Texture?.GetHashCode() ?? 0; hashCode = (hashCode * 397) ^ ClearDepth.GetHashCode(); hashCode = (hashCode * 397) ^ ClearStencil.GetHashCode(); hashCode = (hashCode * 397) ^ LoadAction.GetHashCode(); hashCode = (hashCode * 397) ^ StoreAction.GetHashCode(); hashCode = (hashCode * 397) ^ MipLevel.GetHashCode(); hashCode = (hashCode * 397) ^ Slice.GetHashCode(); return(hashCode); } }
public override void Init() { shader = Shader.Find("Hidden/SC Post Effects/Fog"); m_Pyramid = new MipLevel[k_MaxPyramidSize]; for (int i = 0; i < k_MaxPyramidSize; i++) { m_Pyramid[i] = new MipLevel { down = Shader.PropertyToID("_BloomMipDown" + i), up = Shader.PropertyToID("_BloomMipUp" + i) }; } }
public override void Init() { shader = Shader.Find(ShaderNames.Fog); m_Pyramid = new MipLevel[k_MaxPyramidSize]; for (int i = 0; i < k_MaxPyramidSize; i++) { m_Pyramid[i] = new MipLevel { down = Shader.PropertyToID("_BloomMipDown" + i), up = Shader.PropertyToID("_BloomMipUp" + i) }; } }
void Alloc(out RTHandle rt, MipLevel size, GraphicsFormat format, bool uav, string name) { rt = RTHandles.Alloc( scaleFunc: m_ScaleFunctors[(int)size], dimension: TextureDimension.Tex2D, colorFormat: format, depthBufferBits: DepthBits.None, autoGenerateMips: false, enableMSAA: false, useDynamicScale: true, enableRandomWrite: uav, filterMode: FilterMode.Point, xrInstancing: true, name: name ); }
private void AllocArray(CommandBuffer cmd, int id, MipLevel size, RenderTextureFormat format, bool uav) { cmd.GetTemporaryRT(id, new RenderTextureDescriptor { width = m_Widths[(int)size], height = m_Heights[(int)size], colorFormat = format, depthBufferBits = 0, volumeDepth = 16, autoGenerateMips = false, msaaSamples = 1, enableRandomWrite = uav, dimension = TextureDimension.Tex2DArray, sRGB = false }, FilterMode.Point); }
private float2 warp(float2 uv, MipLevel level) { switch (wrap) { case Context3DWrapMode.CLAMP: { return(Shader.clamp(uv, new float2(0, 0), new float2(level.width - 1, level.height - 1))); } case Context3DWrapMode.CLAMP_U_REPEAT_V: { float v = uv.y % level.height; if (v < 0) { v += level.height; } float u = Shader.clamp(uv.x, 0, level.width - 1); return(new float2(u, v)); } case Context3DWrapMode.REPEAT: { float u = uv.x % level.width; if (u < 0) { u += level.width; } float v = uv.y % level.height; if (v < 0) { v += level.height; } return(new float2(u, v)); } case Context3DWrapMode.REPEAT_U_CLAMP_V: { float u = uv.x % level.width; if (u < 0) { u += level.width; } float v = Shader.clamp(uv.y, 0, level.width - 1); return(new float2(u, v)); } default: throw new NotImplementedException(); } }
void AllocArray(out RTHandle rt, MipLevel size, GraphicsFormat format, bool uav, string name) { rt = RTHandles.Alloc( scaleFunc: m_ScaleFunctors[(int)size], dimension: TextureDimension.Tex2DArray, colorFormat: format, depthBufferBits: DepthBits.None, slices: 16, // XRTODO: multiply by eyeCount and handle indexing in shader autoGenerateMips: false, enableMSAA: false, useDynamicScale: true, enableRandomWrite: uav, filterMode: FilterMode.Point, xrInstancing: true, name: name ); }
private static void ExtractMipmapLevel(int yOffset, MipLevel mipLevel, int xOffset, Bitmap bmp, int index) { var width = xOffset + mipLevel.Width; var height = yOffset + mipLevel.Height; for (int y = yOffset; y < height; y++) { for (int x = xOffset; x < width; x++) { var pixel = bmp.GetPixel(x, y); mipLevel.Data[index++] = pixel.R / 255f; mipLevel.Data[index++] = pixel.G / 255f; mipLevel.Data[index++] = pixel.B / 255f; mipLevel.Data[index++] = pixel.A / 255f; } } }
void Alloc(CommandBuffer cmd, int id, MipLevel size, RenderTextureFormat format, bool uav) { int sizeId = (int)size; cmd.GetTemporaryRT(id, new RenderTextureDescriptor { width = m_ScaledWidths[sizeId], height = m_ScaledHeights[sizeId], colorFormat = format, depthBufferBits = 0, volumeDepth = 1, autoGenerateMips = false, msaaSamples = 1, mipCount = 1, enableRandomWrite = uav, dimension = TextureDimension.Tex2D, sRGB = false }, FilterMode.Point); }
Vector3 GetSizeArray(MipLevel mip) { return(new Vector3(m_Widths[(int)mip], m_Heights[(int)mip], 16)); }
Vector2 GetSize(MipLevel mip) { return(new Vector2(m_Widths[(int)mip], m_Heights[(int)mip])); }
// Constructor public RTHandle(string name, TextureType type, MipLevel level) { _id = Shader.PropertyToID(name); _type = type; _level = level; }
public RTHandle(string name, TextureType type, MipLevel level) { nameID = Shader.PropertyToID(name); m_Type = type; m_Level = level; }
private float4 sampleTex(MipLevel level, float3 uvw, FragementUnit unit) { switch (filter) { case Context3DTextureFilter.NEAREST: //break; { return(readpixel(uvw, level)); } case Context3DTextureFilter.LINEAR: { return(readliner(uvw, level)); } case Context3DTextureFilter.ANISOTROPIC: { var quadunit = unit.quadunit; var center = (quadunit.unit0.input.uv + quadunit.unit1.input.uv + quadunit.unit2.input.uv + quadunit.unit3.input.uv) * 0.25f; var t_center = (quadunit.unit0.input.uv + quadunit.unit1.input.uv) * 0.5f; var b_center = (quadunit.unit2.input.uv + quadunit.unit3.input.uv) * 0.5f; var l_center = (quadunit.unit0.input.uv + quadunit.unit2.input.uv) * 0.5f; var r_center = (quadunit.unit1.input.uv + quadunit.unit3.input.uv) * 0.5f; float3 p0, p1, p2, p3; if (unit.index == 0) { p0 = unit.input.uv - (center - unit.input.uv); p1 = t_center - (center - t_center); p2 = l_center - (center - l_center); p3 = center; } else if (unit.index == 1) { p0 = t_center - (center - t_center); p1 = unit.input.uv - (center - unit.input.uv); p2 = center; p3 = r_center - (center - r_center); } else if (unit.index == 2) { p0 = l_center - (center - l_center); p1 = center; p2 = unit.input.uv - (center - unit.input.uv); p3 = b_center - (center - b_center); } else { p0 = center; p1 = r_center - (center - r_center); p2 = b_center - (center - b_center); p3 = unit.input.uv - (center - unit.input.uv); } //float3 lp0, lp1, lp2, lp3; //lp0 = (p0 + p1) * 0.5f; //lp1 = (p1 + p2) * 0.5f; //lp2 = (p2 + p3) * 0.5f; //lp3 = (p3 + p0) * 0.5f; return((readliner(p0, level) + readliner(p1, level) + readliner(p2, level) + readliner(p3, level) + readliner(unit.input.uv, level) //+ readliner(lp0, level) //+ readliner(lp1, level) //+ readliner(lp2, level) //+ readliner(lp3, level) ) * 0.2f); //float3 dxuv = (unit.dpdx_v2.input.uv - unit.dpdx_v1.input.uv); //float3 dyuv = (unit.dpdy_v2.input.uv - unit.dpdy_v1.input.uv); //float l1 = dxuv.x * dxuv.x + dxuv.y * dxuv.y; //float l2 = dyuv.x * dyuv.x + dyuv.y * dyuv.y; //float3 duv = (dxuv * l1 + dyuv * l2) / (l1 + l2); //float4 c = new float4(); //float3 st = uvw - new float3(-duv.x, -duv.y, uvw.z) * 0.5; //float3 ed = uvw + new float3(duv.x, duv.y, uvw.z) * 0.5; //float stepx = (ed.x - st.x); //float stepy = (ed.y - st.y); //for (int i = 0; i < 2; i++) //{ // for (int j = 0; j < 2; j++) // { // float3 uvpos = uvw + new float3(i * stepx, j * stepy, 0); // c += readliner(uvpos, level); // } //} //return c * 1f / 4; } throw new NotImplementedException(); default: throw new NotImplementedException(); } }