diff --git a/Assets/Materials/ComputeShaderResultMaterial.mat b/Assets/Materials/ComputeShaderResultMaterial.mat index 93809ba..e459ba6 100644 --- a/Assets/Materials/ComputeShaderResultMaterial.mat +++ b/Assets/Materials/ComputeShaderResultMaterial.mat @@ -21,7 +21,7 @@ Material: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_Name: ComputeShaderResultMaterial - m_Shader: {fileID: 4800000, guid: 650dd9526735d5b46b79224bc6e94025, type: 3} + m_Shader: {fileID: 10752, guid: 0000000000000000f000000000000000, type: 0} m_Parent: {fileID: 0} m_ModifiedSerializedProperties: 0 m_ValidKeywords: [] @@ -30,8 +30,7 @@ Material: m_EnableInstancingVariants: 0 m_DoubleSidedGI: 0 m_CustomRenderQueue: -1 - stringTagMap: - RenderType: Opaque + stringTagMap: {} disabledShaderPasses: [] m_LockedProperties: m_SavedProperties: diff --git a/Assets/Materials/openttd.mat b/Assets/Materials/openttd.mat new file mode 100644 index 0000000..a98f292 --- /dev/null +++ b/Assets/Materials/openttd.mat @@ -0,0 +1,33 @@ +%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: openttd + m_Shader: {fileID: 10752, guid: 0000000000000000f000000000000000, type: 0} + 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: + - _MainTex: + m_Texture: {fileID: 2800000, guid: ac4ea20a37b3d4943b8889efe1821948, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Ints: [] + m_Floats: [] + m_Colors: [] + m_BuildTextureStacks: [] diff --git a/Assets/Materials/openttd.mat.meta b/Assets/Materials/openttd.mat.meta new file mode 100644 index 0000000..1d78781 --- /dev/null +++ b/Assets/Materials/openttd.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c55c9209d94c99c48b3814e8b9dfac0c +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Materials/sabeltann.mat b/Assets/Materials/sabeltann.mat new file mode 100644 index 0000000..ca6f8e9 --- /dev/null +++ b/Assets/Materials/sabeltann.mat @@ -0,0 +1,33 @@ +%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: sabeltann + m_Shader: {fileID: 10752, guid: 0000000000000000f000000000000000, type: 0} + 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: + - _MainTex: + m_Texture: {fileID: 2800000, guid: 0766dead55e68a44d98a3984d5862da9, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Ints: [] + m_Floats: [] + m_Colors: [] + m_BuildTextureStacks: [] diff --git a/Assets/Materials/sabeltann.mat.meta b/Assets/Materials/sabeltann.mat.meta new file mode 100644 index 0000000..de3de1b --- /dev/null +++ b/Assets/Materials/sabeltann.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: abe8e653868665f4cac7d7121c272dba +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 6982bf7..9b336f6 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -135,7 +135,7 @@ GameObject: - component: {fileID: 702131711} - component: {fileID: 702131710} m_Layer: 0 - m_Name: Quad + m_Name: Result m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -200,7 +200,7 @@ Transform: m_GameObject: {fileID: 702131709} serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalPosition: {x: 0.505, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] @@ -368,7 +368,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: a453b492952575646aa79f717aa4c52a, type: 3} m_Name: m_EditorClassIdentifier: - _computeShader: {fileID: 7200000, guid: 3df3413c2fff3cc41a2eb5505b4c260c, type: 3} + _computeShader: {fileID: 7200000, guid: c35861df311fdba4e850d9c8a49c65df, type: 3} _inputTexture: {fileID: 2800000, guid: ac4ea20a37b3d4943b8889efe1821948, type: 3} _resultTexture: {fileID: 0} _resultMaterial: {fileID: 2100000, guid: d7655914d2a5f2b458b0fecf0f73713e, type: 2} @@ -462,7 +462,7 @@ Transform: m_GameObject: {fileID: 963194225} serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: -0, z: -0.87} + m_LocalPosition: {x: 0, y: 0.93, z: -1.355} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] @@ -512,6 +512,89 @@ MonoBehaviour: mipBias: 0 varianceClampScale: 0.9 contrastAdaptiveSharpening: 0 +--- !u!1 &1222278644 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1222278647} + - component: {fileID: 1222278646} + - component: {fileID: 1222278645} + m_Layer: 0 + m_Name: Input + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!23 &1222278645 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1222278644} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 2 + m_RayTraceProcedural: 0 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 2100000, guid: c55c9209d94c99c48b3814e8b9dfac0c, type: 2} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + m_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 + m_AdditionalVertexStreams: {fileID: 0} +--- !u!33 &1222278646 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1222278644} + m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0} +--- !u!4 &1222278647 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1222278644} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: -0.505, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1660057539 &9223372036854775807 SceneRoots: m_ObjectHideFlags: 0 @@ -520,3 +603,4 @@ SceneRoots: - {fileID: 705507995} - {fileID: 768508630} - {fileID: 702131712} + - {fileID: 1222278647} diff --git a/Assets/Scripts/ComputeController.cs b/Assets/Scripts/ComputeController.cs index d798dc2..adb4256 100644 --- a/Assets/Scripts/ComputeController.cs +++ b/Assets/Scripts/ComputeController.cs @@ -54,18 +54,19 @@ public class ComputeController : MonoBehaviour _kernelHandle = _computeShader.FindKernel("cs_main"); _computeShader.SetTexture(_kernelHandle, SourceTexture, _inputTexture); _computeShader.SetTexture(_kernelHandle, Result, _resultTexture); + RunComputeShader(); } #endregion #region Update - private void Update() - { - ShaderUpdate(); - - _resultMaterial.mainTexture = _resultTexture; - } + // private void Update() + // { + // ShaderUpdate(); + // + // _resultMaterial.mainTexture = _resultTexture; + // } private void ShaderUpdate() { diff --git a/Assets/Shaders/GaussianBlur.compute b/Assets/Shaders/GaussianBlur.compute new file mode 100644 index 0000000..4316b18 --- /dev/null +++ b/Assets/Shaders/GaussianBlur.compute @@ -0,0 +1,38 @@ +#pragma kernel cs_main + +Texture2D source_texture; +RWTexture2D result; + +[numthreads(8, 8, 1)] +void cs_main(uint3 id : SV_DispatchThreadID) +{ + //Define a basic 3x3 Gaussian kernel (just for illustration) + // float3x3 kernel = { + // {7, 1, 1}, + // {1, 20, 1}, + // {1, 1, 7} + // }; + + float3x3 kernel = { + { 1, 2, 1 }, + { 2, 4, 2 }, + { 1, 2, 1 } + }; + + // Normalize kernel + //kernel /= 7+1+1+1+20+1+1+1+7; + kernel /= 16; + + float4 sum = float4(0, 0, 0, 0); + + // Convolution: Multiply the surrounding pixels with the kernel and sum them + for (int y = -1; y <= 1; y++) + { + for (int x = -1; x <= 1; x++) + { + sum += source_texture[id.xy + uint2(x, y)] * kernel[x + 1][y + 1]; + } + } + + result[id.xy] = sum; +} diff --git a/Assets/Shaders/GaussianBlur.compute.meta b/Assets/Shaders/GaussianBlur.compute.meta new file mode 100644 index 0000000..200ab88 --- /dev/null +++ b/Assets/Shaders/GaussianBlur.compute.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: c35861df311fdba4e850d9c8a49c65df +ComputeShaderImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Textures/sabeltann.png b/Assets/Textures/sabeltann.png new file mode 100644 index 0000000..ca25ecf Binary files /dev/null and b/Assets/Textures/sabeltann.png differ diff --git a/Assets/Textures/sabeltann.png.meta b/Assets/Textures/sabeltann.png.meta new file mode 100644 index 0000000..a5f58d9 --- /dev/null +++ b/Assets/Textures/sabeltann.png.meta @@ -0,0 +1,127 @@ +fileFormatVersion: 2 +guid: 0766dead55e68a44d98a3984d5862da9 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + 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 + flipGreenChannel: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMipmapLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + swizzle: 50462976 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Server + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + mipmapLimitGroupName: + pSDRemoveMatte: 0 + userData: + assetBundleName: + assetBundleVariant: