浏览代码
Added attenuation procedural texture generation code and attenuation texture in shader.
/RenderPassXR_Sandbox
Added attenuation procedural texture generation code and attenuation texture in shader.
/RenderPassXR_Sandbox
Felipe Lira
7 年前
当前提交
c28f1752
共有 13 个文件被更改,包括 232 次插入 和 6 次删除
-
5Assets/ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightAssetInspector.cs
-
6Assets/ScriptableRenderPipeline/LightweightPipeline/LightweightPipeline.cs
-
2Assets/ScriptableRenderPipeline/LightweightPipeline/LightweightPipelineAsset.asset
-
7Assets/ScriptableRenderPipeline/LightweightPipeline/LightweightPipelineAsset.cs
-
1Assets/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipeline.shader
-
2Assets/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelineInput.cginc
-
14Assets/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelineLighting.cginc
-
58Assets/ScriptableRenderPipeline/LightweightPipeline/Editor/GenerateTextures.cs
-
13Assets/ScriptableRenderPipeline/LightweightPipeline/Editor/GenerateTextures.cs.meta
-
10Assets/ScriptableRenderPipeline/LightweightPipeline/Textures.meta
-
3Assets/ScriptableRenderPipeline/LightweightPipeline/Textures/LightweightLightAttenuation.png
-
117Assets/ScriptableRenderPipeline/LightweightPipeline/Textures/LightweightLightAttenuation.png.meta
|
|||
using System.IO; |
|||
using UnityEngine; |
|||
using UnityEditor; |
|||
|
|||
public class GenerateTextures : MonoBehaviour |
|||
{ |
|||
private static readonly int kTextureSize = 1024; |
|||
private static readonly float kQuadraticFac = 25.0f; |
|||
private static readonly float kToZeroFadeStart = 0.8f * 0.8f; |
|||
private static readonly string kSavePath = "Assets/ScriptableRenderPipeline/LightweightPipeline/Textures/LightweightLightAttenuation.png"; |
|||
|
|||
[MenuItem("RenderPipeline/LightweightPipeline/GenerateLightFalloffTexture")] |
|||
public static void GenerateLightFalloffTexture() |
|||
{ |
|||
Texture2D tex = new Texture2D(kTextureSize, 4, TextureFormat.Alpha8, false, true); |
|||
tex.wrapMode = TextureWrapMode.Clamp; |
|||
|
|||
byte[] bytes = new byte[kTextureSize * 4]; |
|||
for (int x = 0; x < kTextureSize; ++x) |
|||
{ |
|||
float sqrRange = (float) x/(float) kTextureSize; |
|||
byte atten = LightAttenuationNormalized(sqrRange); |
|||
bytes[x] = atten; |
|||
bytes[x + kTextureSize] = atten; |
|||
bytes[x + kTextureSize * 2] = atten; |
|||
bytes[x + kTextureSize * 3] = atten; |
|||
} |
|||
|
|||
tex.LoadRawTextureData(bytes); |
|||
tex.Apply(false); |
|||
SaveTexture(tex); |
|||
} |
|||
|
|||
public static void SaveTexture(Texture2D tex) |
|||
{ |
|||
byte[] bytes = tex.EncodeToPNG(); |
|||
File.WriteAllBytes(kSavePath, bytes); |
|||
} |
|||
|
|||
public static byte LightAttenuationNormalized(float distSqr) |
|||
{ |
|||
// 1 / 1.0 + quadAtten * distSqr attenuation function
|
|||
float atten = 1.0f / (1.0f + CalculateLightQuadFac(1.0f) * distSqr); |
|||
|
|||
// however the above does not falloff to zero at light range.
|
|||
// Start fading from ktoZeroFadeStart to light range
|
|||
float fadeMultiplier = Mathf.Clamp01((distSqr - 1.0f) / (kToZeroFadeStart - 1.0f)); |
|||
atten *= fadeMultiplier; |
|||
|
|||
//return atten;
|
|||
return (byte)Mathf.RoundToInt(atten * (float)byte.MaxValue); |
|||
} |
|||
|
|||
public static float CalculateLightQuadFac(float range) |
|||
{ |
|||
return kQuadraticFac / (range * range); |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: dd9e613bcee552646a17f8b54e3519de |
|||
timeCreated: 1503914974 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 3c94d46d9288ec04c8b97aa427dd2a3d |
|||
folderAsset: yes |
|||
timeCreated: 1503916220 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: ee420ad43ff580149a07f10ad66c49ff |
|||
timeCreated: 1503935793 |
|||
licenseType: Pro |
|||
TextureImporter: |
|||
fileIDToRecycleName: {} |
|||
externalObjects: {} |
|||
serializedVersion: 4 |
|||
mipmaps: |
|||
mipMapMode: 0 |
|||
enableMipMap: 0 |
|||
sRGBTexture: 0 |
|||
linearTexture: 0 |
|||
fadeOut: 0 |
|||
borderMipMap: 0 |
|||
mipMapsPreserveCoverage: 0 |
|||
alphaTestReferenceValue: 0.5 |
|||
mipMapFadeDistanceStart: 1 |
|||
mipMapFadeDistanceEnd: 3 |
|||
bumpmap: |
|||
convertToNormalMap: 0 |
|||
externalNormalMap: 0 |
|||
heightScale: 0.25 |
|||
normalMapFilter: 0 |
|||
isReadable: 0 |
|||
grayScaleToAlpha: 0 |
|||
generateCubemap: 6 |
|||
cubemapConvolution: 0 |
|||
seamlessCubemap: 0 |
|||
textureFormat: 1 |
|||
maxTextureSize: 2048 |
|||
textureSettings: |
|||
serializedVersion: 2 |
|||
filterMode: -1 |
|||
aniso: -1 |
|||
mipBias: -1 |
|||
wrapU: 1 |
|||
wrapV: 1 |
|||
wrapW: 1 |
|||
nPOTScale: 1 |
|||
lightmap: 0 |
|||
compressionQuality: 50 |
|||
spriteMode: 0 |
|||
spriteExtrude: 1 |
|||
spriteMeshType: 1 |
|||
alignment: 0 |
|||
spritePivot: {x: 0.5, y: 0.5} |
|||
spriteBorder: {x: 0, y: 0, z: 0, w: 0} |
|||
spritePixelsToUnits: 100 |
|||
alphaUsage: 1 |
|||
alphaIsTransparency: 0 |
|||
spriteTessellationDetail: -1 |
|||
textureType: 10 |
|||
textureShape: 1 |
|||
maxTextureSizeSet: 0 |
|||
compressionQualitySet: 0 |
|||
textureFormatSet: 0 |
|||
platformSettings: |
|||
- buildTarget: DefaultTexturePlatform |
|||
maxTextureSize: 2048 |
|||
resizeAlgorithm: 0 |
|||
textureFormat: -1 |
|||
textureCompression: 1 |
|||
compressionQuality: 50 |
|||
crunchedCompression: 0 |
|||
allowsAlphaSplitting: 0 |
|||
overridden: 0 |
|||
androidETC2FallbackOverride: 0 |
|||
- buildTarget: Standalone |
|||
maxTextureSize: 2048 |
|||
resizeAlgorithm: 0 |
|||
textureFormat: 1 |
|||
textureCompression: 1 |
|||
compressionQuality: 50 |
|||
crunchedCompression: 0 |
|||
allowsAlphaSplitting: 0 |
|||
overridden: 1 |
|||
androidETC2FallbackOverride: 0 |
|||
- buildTarget: iPhone |
|||
maxTextureSize: 2048 |
|||
resizeAlgorithm: 0 |
|||
textureFormat: -1 |
|||
textureCompression: 1 |
|||
compressionQuality: 50 |
|||
crunchedCompression: 0 |
|||
allowsAlphaSplitting: 0 |
|||
overridden: 0 |
|||
androidETC2FallbackOverride: 0 |
|||
- buildTarget: tvOS |
|||
maxTextureSize: 2048 |
|||
resizeAlgorithm: 0 |
|||
textureFormat: -1 |
|||
textureCompression: 1 |
|||
compressionQuality: 50 |
|||
crunchedCompression: 0 |
|||
allowsAlphaSplitting: 0 |
|||
overridden: 0 |
|||
androidETC2FallbackOverride: 0 |
|||
- buildTarget: WiiU |
|||
maxTextureSize: 2048 |
|||
resizeAlgorithm: 0 |
|||
textureFormat: -1 |
|||
textureCompression: 1 |
|||
compressionQuality: 50 |
|||
crunchedCompression: 0 |
|||
allowsAlphaSplitting: 0 |
|||
overridden: 0 |
|||
androidETC2FallbackOverride: 0 |
|||
spriteSheet: |
|||
serializedVersion: 2 |
|||
sprites: [] |
|||
outline: [] |
|||
physicsShape: [] |
|||
spritePackingTag: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue