├── Assets ├── Img.meta ├── Img │ ├── Chapter4.png │ ├── Chapter4.png.meta │ ├── Chapter5_1.png │ ├── Chapter5_1.png.meta │ ├── Chapter5_2.png │ ├── Chapter5_2.png.meta │ ├── chapter1.png │ ├── chapter1.png.meta │ ├── chapter10_1.png │ ├── chapter10_1.png.meta │ ├── chapter10_2.png │ ├── chapter10_2.png.meta │ ├── chapter10_3.png │ ├── chapter10_3.png.meta │ ├── chapter11.png │ ├── chapter11.png.meta │ ├── chapter11_1.png │ ├── chapter11_1.png.meta │ ├── chapter12.png │ ├── chapter12.png.meta │ ├── chapter3.png │ ├── chapter3.png.meta │ ├── chapter6.png │ ├── chapter6.png.meta │ ├── chapter7_1.png │ ├── chapter7_1.png.meta │ ├── chapter7_2.png │ ├── chapter7_2.png.meta │ ├── chapter8_1.png │ ├── chapter8_1.png.meta │ ├── chapter8fuzz2.png │ ├── chapter8fuzz2.png.meta │ ├── chapter9_1.png │ ├── chapter9_1.png.meta │ ├── chapter9_2.png │ └── chapter9_2.png.meta ├── Script.meta ├── Script │ ├── ImageHelper.cs │ ├── ImageHelper.cs.meta │ ├── camera.cs │ ├── camera.cs.meta │ ├── chapter1.cs │ ├── chapter1.cs.meta │ ├── chapter10.cs │ ├── chapter10.cs.meta │ ├── chapter11.cs │ ├── chapter11.cs.meta │ ├── chapter12.cs │ ├── chapter12.cs.meta │ ├── chapter3.cs │ ├── chapter3.cs.meta │ ├── chapter4.cs │ ├── chapter4.cs.meta │ ├── chapter5_1.cs │ ├── chapter5_1.cs.meta │ ├── chapter5_2.cs │ ├── chapter5_2.cs.meta │ ├── chapter6.cs │ ├── chapter6.cs.meta │ ├── chapter7.cs │ ├── chapter7.cs.meta │ ├── chapter8.cs │ ├── chapter8.cs.meta │ ├── chapter9.cs │ └── chapter9.cs.meta ├── figure.meta └── figure │ ├── chapter3-1.png │ ├── chapter3-1.png.meta │ ├── chapter3-2.png │ ├── chapter3-2.png.meta │ ├── chapter3-3.png │ ├── chapter3-3.png.meta │ ├── chapter4-1.png │ ├── chapter4-1.png.meta │ ├── figure10-1.png │ ├── figure10-1.png.meta │ ├── figure10-2.png │ ├── figure10-2.png.meta │ ├── figure10-3.png │ ├── figure10-3.png.meta │ ├── figure11-1.png │ ├── figure11-1.png.meta │ ├── figure11-2.png │ ├── figure11-2.png.meta │ ├── figure5-1.png │ ├── figure5-1.png.meta │ ├── figure7-1.png │ ├── figure7-1.png.meta │ ├── figure7-2.png │ ├── figure7-2.png.meta │ ├── figure8-1.png │ ├── figure8-1.png.meta │ ├── figure9-1.png │ └── figure9-1.png.meta ├── README.html ├── README.md └── README.pdf /Assets/Img.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f055d882eeaae9d43a2a2f449be7678d 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Img/Chapter4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyonggit/RayTracingInOneWeekend_CSharp/31372c481f9e4d45e8ba30ebcb78548bd00ed8b8/Assets/Img/Chapter4.png -------------------------------------------------------------------------------- /Assets/Img/Chapter4.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ecea241804a97f24a9455ae90039ce27 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | externalObjects: {} 6 | serializedVersion: 9 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 1 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | isReadable: 0 24 | streamingMipmaps: 0 25 | streamingMipmapsPriority: 0 26 | grayScaleToAlpha: 0 27 | generateCubemap: 6 28 | cubemapConvolution: 0 29 | seamlessCubemap: 0 30 | textureFormat: 1 31 | maxTextureSize: 2048 32 | textureSettings: 33 | serializedVersion: 2 34 | filterMode: -1 35 | aniso: -1 36 | mipBias: -100 37 | wrapU: -1 38 | wrapV: -1 39 | wrapW: -1 40 | nPOTScale: 1 41 | lightmap: 0 42 | compressionQuality: 50 43 | spriteMode: 0 44 | spriteExtrude: 1 45 | spriteMeshType: 1 46 | alignment: 0 47 | spritePivot: {x: 0.5, y: 0.5} 48 | spritePixelsToUnits: 100 49 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 50 | spriteGenerateFallbackPhysicsShape: 1 51 | alphaUsage: 1 52 | alphaIsTransparency: 0 53 | spriteTessellationDetail: -1 54 | textureType: 0 55 | textureShape: 1 56 | singleChannelComponent: 0 57 | maxTextureSizeSet: 0 58 | compressionQualitySet: 0 59 | textureFormatSet: 0 60 | platformSettings: 61 | - serializedVersion: 2 62 | buildTarget: DefaultTexturePlatform 63 | maxTextureSize: 2048 64 | resizeAlgorithm: 0 65 | textureFormat: -1 66 | textureCompression: 1 67 | compressionQuality: 50 68 | crunchedCompression: 0 69 | allowsAlphaSplitting: 0 70 | overridden: 0 71 | androidETC2FallbackOverride: 0 72 | spriteSheet: 73 | serializedVersion: 2 74 | sprites: [] 75 | outline: [] 76 | physicsShape: [] 77 | bones: [] 78 | spriteID: 79 | vertices: [] 80 | indices: 81 | edges: [] 82 | weights: [] 83 | spritePackingTag: 84 | pSDRemoveMatte: 0 85 | pSDShowRemoveMatteOption: 0 86 | userData: 87 | assetBundleName: 88 | assetBundleVariant: 89 | -------------------------------------------------------------------------------- /Assets/Img/Chapter5_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyonggit/RayTracingInOneWeekend_CSharp/31372c481f9e4d45e8ba30ebcb78548bd00ed8b8/Assets/Img/Chapter5_1.png -------------------------------------------------------------------------------- /Assets/Img/Chapter5_1.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 00cc55fa90042e949808ec9f4aae7fac 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | externalObjects: {} 6 | serializedVersion: 9 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 1 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | isReadable: 0 24 | streamingMipmaps: 0 25 | streamingMipmapsPriority: 0 26 | grayScaleToAlpha: 0 27 | generateCubemap: 6 28 | cubemapConvolution: 0 29 | seamlessCubemap: 0 30 | textureFormat: 1 31 | maxTextureSize: 2048 32 | textureSettings: 33 | serializedVersion: 2 34 | filterMode: -1 35 | aniso: -1 36 | mipBias: -100 37 | wrapU: -1 38 | wrapV: -1 39 | wrapW: -1 40 | nPOTScale: 1 41 | lightmap: 0 42 | compressionQuality: 50 43 | spriteMode: 0 44 | spriteExtrude: 1 45 | spriteMeshType: 1 46 | alignment: 0 47 | spritePivot: {x: 0.5, y: 0.5} 48 | spritePixelsToUnits: 100 49 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 50 | spriteGenerateFallbackPhysicsShape: 1 51 | alphaUsage: 1 52 | alphaIsTransparency: 0 53 | spriteTessellationDetail: -1 54 | textureType: 0 55 | textureShape: 1 56 | singleChannelComponent: 0 57 | maxTextureSizeSet: 0 58 | compressionQualitySet: 0 59 | textureFormatSet: 0 60 | platformSettings: 61 | - serializedVersion: 2 62 | buildTarget: DefaultTexturePlatform 63 | maxTextureSize: 2048 64 | resizeAlgorithm: 0 65 | textureFormat: -1 66 | textureCompression: 1 67 | compressionQuality: 50 68 | crunchedCompression: 0 69 | allowsAlphaSplitting: 0 70 | overridden: 0 71 | androidETC2FallbackOverride: 0 72 | spriteSheet: 73 | serializedVersion: 2 74 | sprites: [] 75 | outline: [] 76 | physicsShape: [] 77 | bones: [] 78 | spriteID: 79 | vertices: [] 80 | indices: 81 | edges: [] 82 | weights: [] 83 | spritePackingTag: 84 | pSDRemoveMatte: 0 85 | pSDShowRemoveMatteOption: 0 86 | userData: 87 | assetBundleName: 88 | assetBundleVariant: 89 | -------------------------------------------------------------------------------- /Assets/Img/Chapter5_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyonggit/RayTracingInOneWeekend_CSharp/31372c481f9e4d45e8ba30ebcb78548bd00ed8b8/Assets/Img/Chapter5_2.png -------------------------------------------------------------------------------- /Assets/Img/Chapter5_2.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5de48b1755d13f7489399ca3e4db2059 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | externalObjects: {} 6 | serializedVersion: 9 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 1 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | isReadable: 0 24 | streamingMipmaps: 0 25 | streamingMipmapsPriority: 0 26 | grayScaleToAlpha: 0 27 | generateCubemap: 6 28 | cubemapConvolution: 0 29 | seamlessCubemap: 0 30 | textureFormat: 1 31 | maxTextureSize: 2048 32 | textureSettings: 33 | serializedVersion: 2 34 | filterMode: -1 35 | aniso: -1 36 | mipBias: -100 37 | wrapU: -1 38 | wrapV: -1 39 | wrapW: -1 40 | nPOTScale: 1 41 | lightmap: 0 42 | compressionQuality: 50 43 | spriteMode: 0 44 | spriteExtrude: 1 45 | spriteMeshType: 1 46 | alignment: 0 47 | spritePivot: {x: 0.5, y: 0.5} 48 | spritePixelsToUnits: 100 49 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 50 | spriteGenerateFallbackPhysicsShape: 1 51 | alphaUsage: 1 52 | alphaIsTransparency: 0 53 | spriteTessellationDetail: -1 54 | textureType: 0 55 | textureShape: 1 56 | singleChannelComponent: 0 57 | maxTextureSizeSet: 0 58 | compressionQualitySet: 0 59 | textureFormatSet: 0 60 | platformSettings: 61 | - serializedVersion: 2 62 | buildTarget: DefaultTexturePlatform 63 | maxTextureSize: 2048 64 | resizeAlgorithm: 0 65 | textureFormat: -1 66 | textureCompression: 1 67 | compressionQuality: 50 68 | crunchedCompression: 0 69 | allowsAlphaSplitting: 0 70 | overridden: 0 71 | androidETC2FallbackOverride: 0 72 | spriteSheet: 73 | serializedVersion: 2 74 | sprites: [] 75 | outline: [] 76 | physicsShape: [] 77 | bones: [] 78 | spriteID: 79 | vertices: [] 80 | indices: 81 | edges: [] 82 | weights: [] 83 | spritePackingTag: 84 | pSDRemoveMatte: 0 85 | pSDShowRemoveMatteOption: 0 86 | userData: 87 | assetBundleName: 88 | assetBundleVariant: 89 | -------------------------------------------------------------------------------- /Assets/Img/chapter1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyonggit/RayTracingInOneWeekend_CSharp/31372c481f9e4d45e8ba30ebcb78548bd00ed8b8/Assets/Img/chapter1.png -------------------------------------------------------------------------------- /Assets/Img/chapter1.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0e02aaffb7caa114d85333795878dd37 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | externalObjects: {} 6 | serializedVersion: 9 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 1 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | isReadable: 0 24 | streamingMipmaps: 0 25 | streamingMipmapsPriority: 0 26 | grayScaleToAlpha: 0 27 | generateCubemap: 6 28 | cubemapConvolution: 0 29 | seamlessCubemap: 0 30 | textureFormat: 1 31 | maxTextureSize: 2048 32 | textureSettings: 33 | serializedVersion: 2 34 | filterMode: -1 35 | aniso: -1 36 | mipBias: -100 37 | wrapU: -1 38 | wrapV: -1 39 | wrapW: -1 40 | nPOTScale: 1 41 | lightmap: 0 42 | compressionQuality: 50 43 | spriteMode: 0 44 | spriteExtrude: 1 45 | spriteMeshType: 1 46 | alignment: 0 47 | spritePivot: {x: 0.5, y: 0.5} 48 | spritePixelsToUnits: 100 49 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 50 | spriteGenerateFallbackPhysicsShape: 1 51 | alphaUsage: 1 52 | alphaIsTransparency: 0 53 | spriteTessellationDetail: -1 54 | textureType: 0 55 | textureShape: 1 56 | singleChannelComponent: 0 57 | maxTextureSizeSet: 0 58 | compressionQualitySet: 0 59 | textureFormatSet: 0 60 | platformSettings: 61 | - serializedVersion: 2 62 | buildTarget: DefaultTexturePlatform 63 | maxTextureSize: 2048 64 | resizeAlgorithm: 0 65 | textureFormat: -1 66 | textureCompression: 1 67 | compressionQuality: 50 68 | crunchedCompression: 0 69 | allowsAlphaSplitting: 0 70 | overridden: 0 71 | androidETC2FallbackOverride: 0 72 | spriteSheet: 73 | serializedVersion: 2 74 | sprites: [] 75 | outline: [] 76 | physicsShape: [] 77 | bones: [] 78 | spriteID: 79 | vertices: [] 80 | indices: 81 | edges: [] 82 | weights: [] 83 | spritePackingTag: 84 | pSDRemoveMatte: 0 85 | pSDShowRemoveMatteOption: 0 86 | userData: 87 | assetBundleName: 88 | assetBundleVariant: 89 | -------------------------------------------------------------------------------- /Assets/Img/chapter10_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyonggit/RayTracingInOneWeekend_CSharp/31372c481f9e4d45e8ba30ebcb78548bd00ed8b8/Assets/Img/chapter10_1.png -------------------------------------------------------------------------------- /Assets/Img/chapter10_1.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8a41c62487c0a484489206b093e03ff9 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | externalObjects: {} 6 | serializedVersion: 9 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 1 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | isReadable: 0 24 | streamingMipmaps: 0 25 | streamingMipmapsPriority: 0 26 | grayScaleToAlpha: 0 27 | generateCubemap: 6 28 | cubemapConvolution: 0 29 | seamlessCubemap: 0 30 | textureFormat: 1 31 | maxTextureSize: 2048 32 | textureSettings: 33 | serializedVersion: 2 34 | filterMode: -1 35 | aniso: -1 36 | mipBias: -100 37 | wrapU: -1 38 | wrapV: -1 39 | wrapW: -1 40 | nPOTScale: 1 41 | lightmap: 0 42 | compressionQuality: 50 43 | spriteMode: 0 44 | spriteExtrude: 1 45 | spriteMeshType: 1 46 | alignment: 0 47 | spritePivot: {x: 0.5, y: 0.5} 48 | spritePixelsToUnits: 100 49 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 50 | spriteGenerateFallbackPhysicsShape: 1 51 | alphaUsage: 1 52 | alphaIsTransparency: 0 53 | spriteTessellationDetail: -1 54 | textureType: 0 55 | textureShape: 1 56 | singleChannelComponent: 0 57 | maxTextureSizeSet: 0 58 | compressionQualitySet: 0 59 | textureFormatSet: 0 60 | platformSettings: 61 | - serializedVersion: 2 62 | buildTarget: DefaultTexturePlatform 63 | maxTextureSize: 2048 64 | resizeAlgorithm: 0 65 | textureFormat: -1 66 | textureCompression: 1 67 | compressionQuality: 50 68 | crunchedCompression: 0 69 | allowsAlphaSplitting: 0 70 | overridden: 0 71 | androidETC2FallbackOverride: 0 72 | spriteSheet: 73 | serializedVersion: 2 74 | sprites: [] 75 | outline: [] 76 | physicsShape: [] 77 | bones: [] 78 | spriteID: 79 | vertices: [] 80 | indices: 81 | edges: [] 82 | weights: [] 83 | spritePackingTag: 84 | pSDRemoveMatte: 0 85 | pSDShowRemoveMatteOption: 0 86 | userData: 87 | assetBundleName: 88 | assetBundleVariant: 89 | -------------------------------------------------------------------------------- /Assets/Img/chapter10_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyonggit/RayTracingInOneWeekend_CSharp/31372c481f9e4d45e8ba30ebcb78548bd00ed8b8/Assets/Img/chapter10_2.png -------------------------------------------------------------------------------- /Assets/Img/chapter10_2.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 53bfdf52af214a3419bf3cc957c2644c 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | externalObjects: {} 6 | serializedVersion: 9 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 1 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | isReadable: 0 24 | streamingMipmaps: 0 25 | streamingMipmapsPriority: 0 26 | grayScaleToAlpha: 0 27 | generateCubemap: 6 28 | cubemapConvolution: 0 29 | seamlessCubemap: 0 30 | textureFormat: 1 31 | maxTextureSize: 2048 32 | textureSettings: 33 | serializedVersion: 2 34 | filterMode: -1 35 | aniso: -1 36 | mipBias: -100 37 | wrapU: -1 38 | wrapV: -1 39 | wrapW: -1 40 | nPOTScale: 1 41 | lightmap: 0 42 | compressionQuality: 50 43 | spriteMode: 0 44 | spriteExtrude: 1 45 | spriteMeshType: 1 46 | alignment: 0 47 | spritePivot: {x: 0.5, y: 0.5} 48 | spritePixelsToUnits: 100 49 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 50 | spriteGenerateFallbackPhysicsShape: 1 51 | alphaUsage: 1 52 | alphaIsTransparency: 0 53 | spriteTessellationDetail: -1 54 | textureType: 0 55 | textureShape: 1 56 | singleChannelComponent: 0 57 | maxTextureSizeSet: 0 58 | compressionQualitySet: 0 59 | textureFormatSet: 0 60 | platformSettings: 61 | - serializedVersion: 2 62 | buildTarget: DefaultTexturePlatform 63 | maxTextureSize: 2048 64 | resizeAlgorithm: 0 65 | textureFormat: -1 66 | textureCompression: 1 67 | compressionQuality: 50 68 | crunchedCompression: 0 69 | allowsAlphaSplitting: 0 70 | overridden: 0 71 | androidETC2FallbackOverride: 0 72 | spriteSheet: 73 | serializedVersion: 2 74 | sprites: [] 75 | outline: [] 76 | physicsShape: [] 77 | bones: [] 78 | spriteID: 79 | vertices: [] 80 | indices: 81 | edges: [] 82 | weights: [] 83 | spritePackingTag: 84 | pSDRemoveMatte: 0 85 | pSDShowRemoveMatteOption: 0 86 | userData: 87 | assetBundleName: 88 | assetBundleVariant: 89 | -------------------------------------------------------------------------------- /Assets/Img/chapter10_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyonggit/RayTracingInOneWeekend_CSharp/31372c481f9e4d45e8ba30ebcb78548bd00ed8b8/Assets/Img/chapter10_3.png -------------------------------------------------------------------------------- /Assets/Img/chapter10_3.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a10aff9c8b41bec4698c8aec34f0c083 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | externalObjects: {} 6 | serializedVersion: 9 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 1 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | isReadable: 0 24 | streamingMipmaps: 0 25 | streamingMipmapsPriority: 0 26 | grayScaleToAlpha: 0 27 | generateCubemap: 6 28 | cubemapConvolution: 0 29 | seamlessCubemap: 0 30 | textureFormat: 1 31 | maxTextureSize: 2048 32 | textureSettings: 33 | serializedVersion: 2 34 | filterMode: -1 35 | aniso: -1 36 | mipBias: -100 37 | wrapU: -1 38 | wrapV: -1 39 | wrapW: -1 40 | nPOTScale: 1 41 | lightmap: 0 42 | compressionQuality: 50 43 | spriteMode: 0 44 | spriteExtrude: 1 45 | spriteMeshType: 1 46 | alignment: 0 47 | spritePivot: {x: 0.5, y: 0.5} 48 | spritePixelsToUnits: 100 49 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 50 | spriteGenerateFallbackPhysicsShape: 1 51 | alphaUsage: 1 52 | alphaIsTransparency: 0 53 | spriteTessellationDetail: -1 54 | textureType: 0 55 | textureShape: 1 56 | singleChannelComponent: 0 57 | maxTextureSizeSet: 0 58 | compressionQualitySet: 0 59 | textureFormatSet: 0 60 | platformSettings: 61 | - serializedVersion: 2 62 | buildTarget: DefaultTexturePlatform 63 | maxTextureSize: 2048 64 | resizeAlgorithm: 0 65 | textureFormat: -1 66 | textureCompression: 1 67 | compressionQuality: 50 68 | crunchedCompression: 0 69 | allowsAlphaSplitting: 0 70 | overridden: 0 71 | androidETC2FallbackOverride: 0 72 | spriteSheet: 73 | serializedVersion: 2 74 | sprites: [] 75 | outline: [] 76 | physicsShape: [] 77 | bones: [] 78 | spriteID: 79 | vertices: [] 80 | indices: 81 | edges: [] 82 | weights: [] 83 | spritePackingTag: 84 | pSDRemoveMatte: 0 85 | pSDShowRemoveMatteOption: 0 86 | userData: 87 | assetBundleName: 88 | assetBundleVariant: 89 | -------------------------------------------------------------------------------- /Assets/Img/chapter11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyonggit/RayTracingInOneWeekend_CSharp/31372c481f9e4d45e8ba30ebcb78548bd00ed8b8/Assets/Img/chapter11.png -------------------------------------------------------------------------------- /Assets/Img/chapter11.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 532a7e7d6e5f6aa4d9f95bd2aae7a288 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | externalObjects: {} 6 | serializedVersion: 9 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 1 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | isReadable: 0 24 | streamingMipmaps: 0 25 | streamingMipmapsPriority: 0 26 | grayScaleToAlpha: 0 27 | generateCubemap: 6 28 | cubemapConvolution: 0 29 | seamlessCubemap: 0 30 | textureFormat: 1 31 | maxTextureSize: 2048 32 | textureSettings: 33 | serializedVersion: 2 34 | filterMode: -1 35 | aniso: -1 36 | mipBias: -100 37 | wrapU: -1 38 | wrapV: -1 39 | wrapW: -1 40 | nPOTScale: 1 41 | lightmap: 0 42 | compressionQuality: 50 43 | spriteMode: 0 44 | spriteExtrude: 1 45 | spriteMeshType: 1 46 | alignment: 0 47 | spritePivot: {x: 0.5, y: 0.5} 48 | spritePixelsToUnits: 100 49 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 50 | spriteGenerateFallbackPhysicsShape: 1 51 | alphaUsage: 1 52 | alphaIsTransparency: 0 53 | spriteTessellationDetail: -1 54 | textureType: 0 55 | textureShape: 1 56 | singleChannelComponent: 0 57 | maxTextureSizeSet: 0 58 | compressionQualitySet: 0 59 | textureFormatSet: 0 60 | platformSettings: 61 | - serializedVersion: 2 62 | buildTarget: DefaultTexturePlatform 63 | maxTextureSize: 2048 64 | resizeAlgorithm: 0 65 | textureFormat: -1 66 | textureCompression: 1 67 | compressionQuality: 50 68 | crunchedCompression: 0 69 | allowsAlphaSplitting: 0 70 | overridden: 0 71 | androidETC2FallbackOverride: 0 72 | spriteSheet: 73 | serializedVersion: 2 74 | sprites: [] 75 | outline: [] 76 | physicsShape: [] 77 | bones: [] 78 | spriteID: 79 | vertices: [] 80 | indices: 81 | edges: [] 82 | weights: [] 83 | spritePackingTag: 84 | pSDRemoveMatte: 0 85 | pSDShowRemoveMatteOption: 0 86 | userData: 87 | assetBundleName: 88 | assetBundleVariant: 89 | -------------------------------------------------------------------------------- /Assets/Img/chapter11_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyonggit/RayTracingInOneWeekend_CSharp/31372c481f9e4d45e8ba30ebcb78548bd00ed8b8/Assets/Img/chapter11_1.png -------------------------------------------------------------------------------- /Assets/Img/chapter11_1.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fe01f4b03f681a541a43d90e0a47db49 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | externalObjects: {} 6 | serializedVersion: 9 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 1 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | isReadable: 0 24 | streamingMipmaps: 0 25 | streamingMipmapsPriority: 0 26 | grayScaleToAlpha: 0 27 | generateCubemap: 6 28 | cubemapConvolution: 0 29 | seamlessCubemap: 0 30 | textureFormat: 1 31 | maxTextureSize: 2048 32 | textureSettings: 33 | serializedVersion: 2 34 | filterMode: -1 35 | aniso: -1 36 | mipBias: -100 37 | wrapU: -1 38 | wrapV: -1 39 | wrapW: -1 40 | nPOTScale: 1 41 | lightmap: 0 42 | compressionQuality: 50 43 | spriteMode: 0 44 | spriteExtrude: 1 45 | spriteMeshType: 1 46 | alignment: 0 47 | spritePivot: {x: 0.5, y: 0.5} 48 | spritePixelsToUnits: 100 49 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 50 | spriteGenerateFallbackPhysicsShape: 1 51 | alphaUsage: 1 52 | alphaIsTransparency: 0 53 | spriteTessellationDetail: -1 54 | textureType: 0 55 | textureShape: 1 56 | singleChannelComponent: 0 57 | maxTextureSizeSet: 0 58 | compressionQualitySet: 0 59 | textureFormatSet: 0 60 | platformSettings: 61 | - serializedVersion: 2 62 | buildTarget: DefaultTexturePlatform 63 | maxTextureSize: 2048 64 | resizeAlgorithm: 0 65 | textureFormat: -1 66 | textureCompression: 1 67 | compressionQuality: 50 68 | crunchedCompression: 0 69 | allowsAlphaSplitting: 0 70 | overridden: 0 71 | androidETC2FallbackOverride: 0 72 | spriteSheet: 73 | serializedVersion: 2 74 | sprites: [] 75 | outline: [] 76 | physicsShape: [] 77 | bones: [] 78 | spriteID: 79 | vertices: [] 80 | indices: 81 | edges: [] 82 | weights: [] 83 | spritePackingTag: 84 | pSDRemoveMatte: 0 85 | pSDShowRemoveMatteOption: 0 86 | userData: 87 | assetBundleName: 88 | assetBundleVariant: 89 | -------------------------------------------------------------------------------- /Assets/Img/chapter12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyonggit/RayTracingInOneWeekend_CSharp/31372c481f9e4d45e8ba30ebcb78548bd00ed8b8/Assets/Img/chapter12.png -------------------------------------------------------------------------------- /Assets/Img/chapter12.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cccea973f1def794bb0a28d34e0f1661 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | externalObjects: {} 6 | serializedVersion: 9 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 1 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | isReadable: 0 24 | streamingMipmaps: 0 25 | streamingMipmapsPriority: 0 26 | grayScaleToAlpha: 0 27 | generateCubemap: 6 28 | cubemapConvolution: 0 29 | seamlessCubemap: 0 30 | textureFormat: 1 31 | maxTextureSize: 2048 32 | textureSettings: 33 | serializedVersion: 2 34 | filterMode: -1 35 | aniso: -1 36 | mipBias: -100 37 | wrapU: -1 38 | wrapV: -1 39 | wrapW: -1 40 | nPOTScale: 0 41 | lightmap: 0 42 | compressionQuality: 50 43 | spriteMode: 0 44 | spriteExtrude: 1 45 | spriteMeshType: 1 46 | alignment: 0 47 | spritePivot: {x: 0.5, y: 0.5} 48 | spritePixelsToUnits: 100 49 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 50 | spriteGenerateFallbackPhysicsShape: 1 51 | alphaUsage: 1 52 | alphaIsTransparency: 0 53 | spriteTessellationDetail: -1 54 | textureType: 0 55 | textureShape: 1 56 | singleChannelComponent: 0 57 | maxTextureSizeSet: 0 58 | compressionQualitySet: 0 59 | textureFormatSet: 0 60 | platformSettings: 61 | - serializedVersion: 2 62 | buildTarget: DefaultTexturePlatform 63 | maxTextureSize: 2048 64 | resizeAlgorithm: 0 65 | textureFormat: -1 66 | textureCompression: 1 67 | compressionQuality: 50 68 | crunchedCompression: 0 69 | allowsAlphaSplitting: 0 70 | overridden: 0 71 | androidETC2FallbackOverride: 0 72 | - serializedVersion: 2 73 | buildTarget: Standalone 74 | maxTextureSize: 2048 75 | resizeAlgorithm: 0 76 | textureFormat: -1 77 | textureCompression: 1 78 | compressionQuality: 50 79 | crunchedCompression: 0 80 | allowsAlphaSplitting: 0 81 | overridden: 0 82 | androidETC2FallbackOverride: 0 83 | spriteSheet: 84 | serializedVersion: 2 85 | sprites: [] 86 | outline: [] 87 | physicsShape: [] 88 | bones: [] 89 | spriteID: 90 | vertices: [] 91 | indices: 92 | edges: [] 93 | weights: [] 94 | spritePackingTag: 95 | pSDRemoveMatte: 0 96 | pSDShowRemoveMatteOption: 0 97 | userData: 98 | assetBundleName: 99 | assetBundleVariant: 100 | -------------------------------------------------------------------------------- /Assets/Img/chapter3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyonggit/RayTracingInOneWeekend_CSharp/31372c481f9e4d45e8ba30ebcb78548bd00ed8b8/Assets/Img/chapter3.png -------------------------------------------------------------------------------- /Assets/Img/chapter3.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c273032f7e922a34da6f16e1802ae553 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | externalObjects: {} 6 | serializedVersion: 9 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 1 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | isReadable: 0 24 | streamingMipmaps: 0 25 | streamingMipmapsPriority: 0 26 | grayScaleToAlpha: 0 27 | generateCubemap: 6 28 | cubemapConvolution: 0 29 | seamlessCubemap: 0 30 | textureFormat: 1 31 | maxTextureSize: 2048 32 | textureSettings: 33 | serializedVersion: 2 34 | filterMode: -1 35 | aniso: -1 36 | mipBias: -100 37 | wrapU: -1 38 | wrapV: -1 39 | wrapW: -1 40 | nPOTScale: 1 41 | lightmap: 0 42 | compressionQuality: 50 43 | spriteMode: 0 44 | spriteExtrude: 1 45 | spriteMeshType: 1 46 | alignment: 0 47 | spritePivot: {x: 0.5, y: 0.5} 48 | spritePixelsToUnits: 100 49 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 50 | spriteGenerateFallbackPhysicsShape: 1 51 | alphaUsage: 1 52 | alphaIsTransparency: 0 53 | spriteTessellationDetail: -1 54 | textureType: 0 55 | textureShape: 1 56 | singleChannelComponent: 0 57 | maxTextureSizeSet: 0 58 | compressionQualitySet: 0 59 | textureFormatSet: 0 60 | platformSettings: 61 | - serializedVersion: 2 62 | buildTarget: DefaultTexturePlatform 63 | maxTextureSize: 2048 64 | resizeAlgorithm: 0 65 | textureFormat: -1 66 | textureCompression: 1 67 | compressionQuality: 50 68 | crunchedCompression: 0 69 | allowsAlphaSplitting: 0 70 | overridden: 0 71 | androidETC2FallbackOverride: 0 72 | spriteSheet: 73 | serializedVersion: 2 74 | sprites: [] 75 | outline: [] 76 | physicsShape: [] 77 | bones: [] 78 | spriteID: 79 | vertices: [] 80 | indices: 81 | edges: [] 82 | weights: [] 83 | spritePackingTag: 84 | pSDRemoveMatte: 0 85 | pSDShowRemoveMatteOption: 0 86 | userData: 87 | assetBundleName: 88 | assetBundleVariant: 89 | -------------------------------------------------------------------------------- /Assets/Img/chapter6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyonggit/RayTracingInOneWeekend_CSharp/31372c481f9e4d45e8ba30ebcb78548bd00ed8b8/Assets/Img/chapter6.png -------------------------------------------------------------------------------- /Assets/Img/chapter6.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1d0d3ce55c8a3a2419b7c7c7cd011803 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | externalObjects: {} 6 | serializedVersion: 9 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 1 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | isReadable: 0 24 | streamingMipmaps: 0 25 | streamingMipmapsPriority: 0 26 | grayScaleToAlpha: 0 27 | generateCubemap: 6 28 | cubemapConvolution: 0 29 | seamlessCubemap: 0 30 | textureFormat: 1 31 | maxTextureSize: 2048 32 | textureSettings: 33 | serializedVersion: 2 34 | filterMode: -1 35 | aniso: -1 36 | mipBias: -100 37 | wrapU: -1 38 | wrapV: -1 39 | wrapW: -1 40 | nPOTScale: 1 41 | lightmap: 0 42 | compressionQuality: 50 43 | spriteMode: 0 44 | spriteExtrude: 1 45 | spriteMeshType: 1 46 | alignment: 0 47 | spritePivot: {x: 0.5, y: 0.5} 48 | spritePixelsToUnits: 100 49 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 50 | spriteGenerateFallbackPhysicsShape: 1 51 | alphaUsage: 1 52 | alphaIsTransparency: 0 53 | spriteTessellationDetail: -1 54 | textureType: 0 55 | textureShape: 1 56 | singleChannelComponent: 0 57 | maxTextureSizeSet: 0 58 | compressionQualitySet: 0 59 | textureFormatSet: 0 60 | platformSettings: 61 | - serializedVersion: 2 62 | buildTarget: DefaultTexturePlatform 63 | maxTextureSize: 2048 64 | resizeAlgorithm: 0 65 | textureFormat: -1 66 | textureCompression: 1 67 | compressionQuality: 50 68 | crunchedCompression: 0 69 | allowsAlphaSplitting: 0 70 | overridden: 0 71 | androidETC2FallbackOverride: 0 72 | spriteSheet: 73 | serializedVersion: 2 74 | sprites: [] 75 | outline: [] 76 | physicsShape: [] 77 | bones: [] 78 | spriteID: 79 | vertices: [] 80 | indices: 81 | edges: [] 82 | weights: [] 83 | spritePackingTag: 84 | pSDRemoveMatte: 0 85 | pSDShowRemoveMatteOption: 0 86 | userData: 87 | assetBundleName: 88 | assetBundleVariant: 89 | -------------------------------------------------------------------------------- /Assets/Img/chapter7_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyonggit/RayTracingInOneWeekend_CSharp/31372c481f9e4d45e8ba30ebcb78548bd00ed8b8/Assets/Img/chapter7_1.png -------------------------------------------------------------------------------- /Assets/Img/chapter7_1.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2be60248be406f24282f907bc53aa211 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | externalObjects: {} 6 | serializedVersion: 9 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 1 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | isReadable: 0 24 | streamingMipmaps: 0 25 | streamingMipmapsPriority: 0 26 | grayScaleToAlpha: 0 27 | generateCubemap: 6 28 | cubemapConvolution: 0 29 | seamlessCubemap: 0 30 | textureFormat: 1 31 | maxTextureSize: 2048 32 | textureSettings: 33 | serializedVersion: 2 34 | filterMode: -1 35 | aniso: -1 36 | mipBias: -100 37 | wrapU: -1 38 | wrapV: -1 39 | wrapW: -1 40 | nPOTScale: 1 41 | lightmap: 0 42 | compressionQuality: 50 43 | spriteMode: 0 44 | spriteExtrude: 1 45 | spriteMeshType: 1 46 | alignment: 0 47 | spritePivot: {x: 0.5, y: 0.5} 48 | spritePixelsToUnits: 100 49 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 50 | spriteGenerateFallbackPhysicsShape: 1 51 | alphaUsage: 1 52 | alphaIsTransparency: 0 53 | spriteTessellationDetail: -1 54 | textureType: 0 55 | textureShape: 1 56 | singleChannelComponent: 0 57 | maxTextureSizeSet: 0 58 | compressionQualitySet: 0 59 | textureFormatSet: 0 60 | platformSettings: 61 | - serializedVersion: 2 62 | buildTarget: DefaultTexturePlatform 63 | maxTextureSize: 2048 64 | resizeAlgorithm: 0 65 | textureFormat: -1 66 | textureCompression: 1 67 | compressionQuality: 50 68 | crunchedCompression: 0 69 | allowsAlphaSplitting: 0 70 | overridden: 0 71 | androidETC2FallbackOverride: 0 72 | spriteSheet: 73 | serializedVersion: 2 74 | sprites: [] 75 | outline: [] 76 | physicsShape: [] 77 | bones: [] 78 | spriteID: 79 | vertices: [] 80 | indices: 81 | edges: [] 82 | weights: [] 83 | spritePackingTag: 84 | pSDRemoveMatte: 0 85 | pSDShowRemoveMatteOption: 0 86 | userData: 87 | assetBundleName: 88 | assetBundleVariant: 89 | -------------------------------------------------------------------------------- /Assets/Img/chapter7_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyonggit/RayTracingInOneWeekend_CSharp/31372c481f9e4d45e8ba30ebcb78548bd00ed8b8/Assets/Img/chapter7_2.png -------------------------------------------------------------------------------- /Assets/Img/chapter7_2.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 211f849635cab2c409ac32d8094266d2 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | externalObjects: {} 6 | serializedVersion: 9 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 1 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | isReadable: 0 24 | streamingMipmaps: 0 25 | streamingMipmapsPriority: 0 26 | grayScaleToAlpha: 0 27 | generateCubemap: 6 28 | cubemapConvolution: 0 29 | seamlessCubemap: 0 30 | textureFormat: 1 31 | maxTextureSize: 2048 32 | textureSettings: 33 | serializedVersion: 2 34 | filterMode: -1 35 | aniso: -1 36 | mipBias: -100 37 | wrapU: -1 38 | wrapV: -1 39 | wrapW: -1 40 | nPOTScale: 1 41 | lightmap: 0 42 | compressionQuality: 50 43 | spriteMode: 0 44 | spriteExtrude: 1 45 | spriteMeshType: 1 46 | alignment: 0 47 | spritePivot: {x: 0.5, y: 0.5} 48 | spritePixelsToUnits: 100 49 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 50 | spriteGenerateFallbackPhysicsShape: 1 51 | alphaUsage: 1 52 | alphaIsTransparency: 0 53 | spriteTessellationDetail: -1 54 | textureType: 0 55 | textureShape: 1 56 | singleChannelComponent: 0 57 | maxTextureSizeSet: 0 58 | compressionQualitySet: 0 59 | textureFormatSet: 0 60 | platformSettings: 61 | - serializedVersion: 2 62 | buildTarget: DefaultTexturePlatform 63 | maxTextureSize: 2048 64 | resizeAlgorithm: 0 65 | textureFormat: -1 66 | textureCompression: 1 67 | compressionQuality: 50 68 | crunchedCompression: 0 69 | allowsAlphaSplitting: 0 70 | overridden: 0 71 | androidETC2FallbackOverride: 0 72 | spriteSheet: 73 | serializedVersion: 2 74 | sprites: [] 75 | outline: [] 76 | physicsShape: [] 77 | bones: [] 78 | spriteID: 79 | vertices: [] 80 | indices: 81 | edges: [] 82 | weights: [] 83 | spritePackingTag: 84 | pSDRemoveMatte: 0 85 | pSDShowRemoveMatteOption: 0 86 | userData: 87 | assetBundleName: 88 | assetBundleVariant: 89 | -------------------------------------------------------------------------------- /Assets/Img/chapter8_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyonggit/RayTracingInOneWeekend_CSharp/31372c481f9e4d45e8ba30ebcb78548bd00ed8b8/Assets/Img/chapter8_1.png -------------------------------------------------------------------------------- /Assets/Img/chapter8_1.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 81509e4b54b2ef5428a0e55e3bcc90b4 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | externalObjects: {} 6 | serializedVersion: 9 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 1 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | isReadable: 0 24 | streamingMipmaps: 0 25 | streamingMipmapsPriority: 0 26 | grayScaleToAlpha: 0 27 | generateCubemap: 6 28 | cubemapConvolution: 0 29 | seamlessCubemap: 0 30 | textureFormat: 1 31 | maxTextureSize: 2048 32 | textureSettings: 33 | serializedVersion: 2 34 | filterMode: -1 35 | aniso: -1 36 | mipBias: -100 37 | wrapU: -1 38 | wrapV: -1 39 | wrapW: -1 40 | nPOTScale: 1 41 | lightmap: 0 42 | compressionQuality: 50 43 | spriteMode: 0 44 | spriteExtrude: 1 45 | spriteMeshType: 1 46 | alignment: 0 47 | spritePivot: {x: 0.5, y: 0.5} 48 | spritePixelsToUnits: 100 49 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 50 | spriteGenerateFallbackPhysicsShape: 1 51 | alphaUsage: 1 52 | alphaIsTransparency: 0 53 | spriteTessellationDetail: -1 54 | textureType: 0 55 | textureShape: 1 56 | singleChannelComponent: 0 57 | maxTextureSizeSet: 0 58 | compressionQualitySet: 0 59 | textureFormatSet: 0 60 | platformSettings: 61 | - serializedVersion: 2 62 | buildTarget: DefaultTexturePlatform 63 | maxTextureSize: 2048 64 | resizeAlgorithm: 0 65 | textureFormat: -1 66 | textureCompression: 1 67 | compressionQuality: 50 68 | crunchedCompression: 0 69 | allowsAlphaSplitting: 0 70 | overridden: 0 71 | androidETC2FallbackOverride: 0 72 | spriteSheet: 73 | serializedVersion: 2 74 | sprites: [] 75 | outline: [] 76 | physicsShape: [] 77 | bones: [] 78 | spriteID: 79 | vertices: [] 80 | indices: 81 | edges: [] 82 | weights: [] 83 | spritePackingTag: 84 | pSDRemoveMatte: 0 85 | pSDShowRemoveMatteOption: 0 86 | userData: 87 | assetBundleName: 88 | assetBundleVariant: 89 | -------------------------------------------------------------------------------- /Assets/Img/chapter8fuzz2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyonggit/RayTracingInOneWeekend_CSharp/31372c481f9e4d45e8ba30ebcb78548bd00ed8b8/Assets/Img/chapter8fuzz2.png -------------------------------------------------------------------------------- /Assets/Img/chapter8fuzz2.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4692da0b38c43c04a8c811bc11d46cdf 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | externalObjects: {} 6 | serializedVersion: 9 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 1 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | isReadable: 0 24 | streamingMipmaps: 0 25 | streamingMipmapsPriority: 0 26 | grayScaleToAlpha: 0 27 | generateCubemap: 6 28 | cubemapConvolution: 0 29 | seamlessCubemap: 0 30 | textureFormat: 1 31 | maxTextureSize: 2048 32 | textureSettings: 33 | serializedVersion: 2 34 | filterMode: -1 35 | aniso: -1 36 | mipBias: -100 37 | wrapU: -1 38 | wrapV: -1 39 | wrapW: -1 40 | nPOTScale: 1 41 | lightmap: 0 42 | compressionQuality: 50 43 | spriteMode: 0 44 | spriteExtrude: 1 45 | spriteMeshType: 1 46 | alignment: 0 47 | spritePivot: {x: 0.5, y: 0.5} 48 | spritePixelsToUnits: 100 49 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 50 | spriteGenerateFallbackPhysicsShape: 1 51 | alphaUsage: 1 52 | alphaIsTransparency: 0 53 | spriteTessellationDetail: -1 54 | textureType: 0 55 | textureShape: 1 56 | singleChannelComponent: 0 57 | maxTextureSizeSet: 0 58 | compressionQualitySet: 0 59 | textureFormatSet: 0 60 | platformSettings: 61 | - serializedVersion: 2 62 | buildTarget: DefaultTexturePlatform 63 | maxTextureSize: 2048 64 | resizeAlgorithm: 0 65 | textureFormat: -1 66 | textureCompression: 1 67 | compressionQuality: 50 68 | crunchedCompression: 0 69 | allowsAlphaSplitting: 0 70 | overridden: 0 71 | androidETC2FallbackOverride: 0 72 | spriteSheet: 73 | serializedVersion: 2 74 | sprites: [] 75 | outline: [] 76 | physicsShape: [] 77 | bones: [] 78 | spriteID: 79 | vertices: [] 80 | indices: 81 | edges: [] 82 | weights: [] 83 | spritePackingTag: 84 | pSDRemoveMatte: 0 85 | pSDShowRemoveMatteOption: 0 86 | userData: 87 | assetBundleName: 88 | assetBundleVariant: 89 | -------------------------------------------------------------------------------- /Assets/Img/chapter9_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyonggit/RayTracingInOneWeekend_CSharp/31372c481f9e4d45e8ba30ebcb78548bd00ed8b8/Assets/Img/chapter9_1.png -------------------------------------------------------------------------------- /Assets/Img/chapter9_1.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2f8c1d75386427641a25b0dfc6388f56 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | externalObjects: {} 6 | serializedVersion: 9 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 1 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | isReadable: 0 24 | streamingMipmaps: 0 25 | streamingMipmapsPriority: 0 26 | grayScaleToAlpha: 0 27 | generateCubemap: 6 28 | cubemapConvolution: 0 29 | seamlessCubemap: 0 30 | textureFormat: 1 31 | maxTextureSize: 2048 32 | textureSettings: 33 | serializedVersion: 2 34 | filterMode: -1 35 | aniso: -1 36 | mipBias: -100 37 | wrapU: -1 38 | wrapV: -1 39 | wrapW: -1 40 | nPOTScale: 1 41 | lightmap: 0 42 | compressionQuality: 50 43 | spriteMode: 0 44 | spriteExtrude: 1 45 | spriteMeshType: 1 46 | alignment: 0 47 | spritePivot: {x: 0.5, y: 0.5} 48 | spritePixelsToUnits: 100 49 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 50 | spriteGenerateFallbackPhysicsShape: 1 51 | alphaUsage: 1 52 | alphaIsTransparency: 0 53 | spriteTessellationDetail: -1 54 | textureType: 0 55 | textureShape: 1 56 | singleChannelComponent: 0 57 | maxTextureSizeSet: 0 58 | compressionQualitySet: 0 59 | textureFormatSet: 0 60 | platformSettings: 61 | - serializedVersion: 2 62 | buildTarget: DefaultTexturePlatform 63 | maxTextureSize: 2048 64 | resizeAlgorithm: 0 65 | textureFormat: -1 66 | textureCompression: 1 67 | compressionQuality: 50 68 | crunchedCompression: 0 69 | allowsAlphaSplitting: 0 70 | overridden: 0 71 | androidETC2FallbackOverride: 0 72 | spriteSheet: 73 | serializedVersion: 2 74 | sprites: [] 75 | outline: [] 76 | physicsShape: [] 77 | bones: [] 78 | spriteID: 79 | vertices: [] 80 | indices: 81 | edges: [] 82 | weights: [] 83 | spritePackingTag: 84 | pSDRemoveMatte: 0 85 | pSDShowRemoveMatteOption: 0 86 | userData: 87 | assetBundleName: 88 | assetBundleVariant: 89 | -------------------------------------------------------------------------------- /Assets/Img/chapter9_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyonggit/RayTracingInOneWeekend_CSharp/31372c481f9e4d45e8ba30ebcb78548bd00ed8b8/Assets/Img/chapter9_2.png -------------------------------------------------------------------------------- /Assets/Img/chapter9_2.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 486ce5939d5367e4597c35b41ed5e763 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | externalObjects: {} 6 | serializedVersion: 9 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 1 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | isReadable: 0 24 | streamingMipmaps: 0 25 | streamingMipmapsPriority: 0 26 | grayScaleToAlpha: 0 27 | generateCubemap: 6 28 | cubemapConvolution: 0 29 | seamlessCubemap: 0 30 | textureFormat: 1 31 | maxTextureSize: 2048 32 | textureSettings: 33 | serializedVersion: 2 34 | filterMode: -1 35 | aniso: -1 36 | mipBias: -100 37 | wrapU: -1 38 | wrapV: -1 39 | wrapW: -1 40 | nPOTScale: 1 41 | lightmap: 0 42 | compressionQuality: 50 43 | spriteMode: 0 44 | spriteExtrude: 1 45 | spriteMeshType: 1 46 | alignment: 0 47 | spritePivot: {x: 0.5, y: 0.5} 48 | spritePixelsToUnits: 100 49 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 50 | spriteGenerateFallbackPhysicsShape: 1 51 | alphaUsage: 1 52 | alphaIsTransparency: 0 53 | spriteTessellationDetail: -1 54 | textureType: 0 55 | textureShape: 1 56 | singleChannelComponent: 0 57 | maxTextureSizeSet: 0 58 | compressionQualitySet: 0 59 | textureFormatSet: 0 60 | platformSettings: 61 | - serializedVersion: 2 62 | buildTarget: DefaultTexturePlatform 63 | maxTextureSize: 2048 64 | resizeAlgorithm: 0 65 | textureFormat: -1 66 | textureCompression: 1 67 | compressionQuality: 50 68 | crunchedCompression: 0 69 | allowsAlphaSplitting: 0 70 | overridden: 0 71 | androidETC2FallbackOverride: 0 72 | spriteSheet: 73 | serializedVersion: 2 74 | sprites: [] 75 | outline: [] 76 | physicsShape: [] 77 | bones: [] 78 | spriteID: 79 | vertices: [] 80 | indices: 81 | edges: [] 82 | weights: [] 83 | spritePackingTag: 84 | pSDRemoveMatte: 0 85 | pSDShowRemoveMatteOption: 0 86 | userData: 87 | assetBundleName: 88 | assetBundleVariant: 89 | -------------------------------------------------------------------------------- /Assets/Script.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fda4e619aa1145442be5424f6302d1ea 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Script/ImageHelper.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEditor; 5 | using System.IO; 6 | 7 | public static class ImageHelper 8 | { 9 | public static Texture2D CreateImg(int width ,int height) 10 | { 11 | Texture2D tex = new Texture2D(width, height, TextureFormat.RGB24, false); 12 | return tex; 13 | } 14 | 15 | public static void SetPixel(Texture2D tex,int x,int y,float r,float g,float b) 16 | { 17 | tex.SetPixel(x, y, new Color(r, g, b)); 18 | } 19 | 20 | public static void SetPixel(Texture2D tex,int x,int y,Vector3 color) 21 | { 22 | tex.SetPixel(x, y, new Color(color.x, color.y, color.z)); 23 | } 24 | 25 | public static void SaveImg(Texture2D tex, string path) 26 | { 27 | var bytes = tex.EncodeToPNG(); 28 | File.WriteAllBytes(Path.Combine(Application.dataPath, path), bytes); 29 | } 30 | } -------------------------------------------------------------------------------- /Assets/Script/ImageHelper.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6872aacc9f10ea3488555acce93e0d82 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Script/camera.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEditor; 5 | using System.IO; 6 | 7 | public class RayCamera 8 | { 9 | private Vector3 origin; 10 | private Vector3 lower_left_corner; 11 | private Vector3 horizontal; 12 | private Vector3 vertical; 13 | 14 | 15 | public RayCamera() 16 | { 17 | origin = Vector3.zero; 18 | lower_left_corner = new Vector3(-2.0f, -1.0f, -1.0f); 19 | horizontal = new Vector3(4, 0, 0); 20 | vertical = new Vector3(0, 2, 0); 21 | } 22 | 23 | public RayCamera(Vector3 ori,Vector3 corner,Vector3 h,Vector3 v) 24 | { 25 | origin = ori; 26 | lower_left_corner = corner; 27 | horizontal = h; 28 | vertical = v; 29 | } 30 | 31 | public RayCamera(float fov, float aspect) 32 | { 33 | float theta = Mathf.Deg2Rad * fov; 34 | float half_height = Mathf.Tan(theta * 0.5f); 35 | float half_width = aspect * half_height; 36 | lower_left_corner = new Vector3(-half_width, -half_height, -1.0f); 37 | horizontal = new Vector3(2 * half_width, 0, 0); 38 | vertical = new Vector3(0, 2 * half_height, 0); 39 | origin = Vector3.zero; 40 | } 41 | 42 | public RayCamera(Vector3 lookfrom,Vector3 lookat,Vector3 vup, float fov, float aspect) 43 | { 44 | Vector3 u, v, w; 45 | float theta = Mathf.Deg2Rad * fov; 46 | float half_height = Mathf.Tan(theta * 0.5f); 47 | float half_width = aspect * half_height; 48 | origin = lookfrom; 49 | w = (lookfrom - lookat).normalized; 50 | u = Vector3.Cross(vup, w).normalized; 51 | v = Vector3.Cross(w, u); 52 | 53 | lower_left_corner = new Vector3(-half_width, -half_height, -1.0f); 54 | lower_left_corner = origin - half_width * u - half_height * v - w; 55 | horizontal = 2 * half_width * u; 56 | vertical = 2 * half_height * v; 57 | } 58 | 59 | 60 | public Ray GetRay(float u,float v) 61 | { 62 | return new Ray(origin, lower_left_corner + u * horizontal + v * vertical - origin); 63 | } 64 | 65 | } 66 | 67 | 68 | public class MotionBlurRayCamera 69 | { 70 | private Vector3 origin; 71 | private Vector3 lower_left_corner; 72 | private Vector3 horizontal; 73 | private Vector3 vertical; 74 | private Vector3 u, v, w; 75 | private float lens_radius; 76 | private float focus; 77 | System.Random random = new System.Random(); 78 | 79 | private Vector2 Random_in_unit_disk() 80 | { 81 | Vector2 v = new Vector2((float)(random.NextDouble() * 2 - 1.0f), 82 | (float)(random.NextDouble() * 2 - 1.0f)); 83 | return v; 84 | } 85 | 86 | private Vector2 Random_in_unit_disk(System.Random seed) 87 | { 88 | Vector2 v = new Vector2((float)(seed.NextDouble() * 2 - 1.0f), 89 | (float)(seed.NextDouble() * 2 - 1.0f)); 90 | return v; 91 | } 92 | 93 | public MotionBlurRayCamera(Vector3 lookfrom, Vector3 lookat, Vector3 vup, float fov, float aspect,float aperture,float focus_dist) 94 | { 95 | lens_radius = aperture / 2; 96 | float theta = Mathf.Deg2Rad * fov; 97 | float half_height = Mathf.Tan(theta * 0.5f); 98 | float half_width = aspect * half_height; 99 | origin = lookfrom; 100 | w = (lookfrom - lookat).normalized; 101 | u = Vector3.Cross(vup, w).normalized; 102 | v = Vector3.Cross(w, u); 103 | focus = focus_dist; 104 | 105 | lower_left_corner = origin - half_width * focus_dist * u - half_height* focus_dist * v - focus_dist * w; 106 | horizontal = 2 * half_width * focus_dist * u; 107 | vertical = 2 * half_height * focus_dist * v; 108 | } 109 | 110 | 111 | public Ray GetRay(float s, float t) 112 | { 113 | Vector2 rd = lens_radius * Random_in_unit_disk(); 114 | Vector3 offset = u * rd.x + v * rd.y; 115 | return new Ray(origin + offset, lower_left_corner + s * horizontal + t * vertical - origin - offset); 116 | } 117 | 118 | public Ray GetRay(float s, float t,System.Random seed) 119 | { 120 | Vector2 rd = lens_radius * Random_in_unit_disk(seed); 121 | Vector3 offset = u * rd.x + v * rd.y; 122 | return new Ray(origin + offset, lower_left_corner + s * horizontal + t * vertical - origin - offset); 123 | } 124 | } -------------------------------------------------------------------------------- /Assets/Script/camera.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c17f396998bae754cb8d390520d6236d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Script/chapter1.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | 4 | public class Chapter1 5 | { 6 | [MenuItem("Raytracing/Chapter1")] 7 | public static void Main() 8 | { 9 | int nx = 1280; 10 | int ny = 720; 11 | 12 | Texture2D tex = ImageHelper.CreateImg(nx, ny); 13 | for (int j = ny - 1; j >= 0; --j) 14 | { 15 | for (int i = 0; i < nx; ++i) 16 | { 17 | float r = (float)(i) / (float)(nx); 18 | float g = (float)(j) / (float)(ny); 19 | float b = 0.2f; 20 | ImageHelper.SetPixel(tex, i, j, r, g, b); 21 | } 22 | } 23 | 24 | ImageHelper.SaveImg(tex, "Img/chapter1.png"); 25 | } 26 | } -------------------------------------------------------------------------------- /Assets/Script/chapter1.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ab898f04730293942985be3609ee360e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Script/chapter10.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System.Collections.Generic; 4 | 5 | namespace Chapter10 6 | { 7 | public struct Hit_record 8 | { 9 | public float t; 10 | public Vector3 hitpoint; 11 | public Vector3 normal; 12 | public IMaterial mat; 13 | }; 14 | 15 | public interface IMaterial 16 | { 17 | bool Scatter(ref Ray r, ref Hit_record rec, ref Vector3 attenuation, ref Ray scattered); 18 | }; 19 | 20 | 21 | 22 | public interface Hitable 23 | { 24 | bool Hit(Ray r, ref float t_min, ref float t_max, out Hit_record record); 25 | }; 26 | 27 | public class HitList : Hitable 28 | { 29 | private List list = new List(); 30 | 31 | public HitList() 32 | { 33 | } 34 | 35 | public int GetCount() 36 | { 37 | return list.Count; 38 | } 39 | 40 | public void Add(Hitable item) 41 | { 42 | list.Add(item); 43 | } 44 | 45 | public bool Hit(Ray r, ref float t_min, ref float t_max, out Hit_record record) 46 | { 47 | Hit_record temp_rec = new Hit_record(); 48 | record = temp_rec; 49 | bool hit_anything = false; 50 | float closest_so_far = t_max; 51 | 52 | for (int i = 0; i < list.Count; ++i) 53 | { 54 | if (list[i].Hit(r, ref t_min, ref closest_so_far, out temp_rec)) 55 | { 56 | hit_anything = true; 57 | closest_so_far = temp_rec.t; 58 | record = temp_rec; 59 | } 60 | } 61 | 62 | return hit_anything; 63 | } 64 | }; 65 | 66 | 67 | public class Lambertian : IMaterial 68 | { 69 | public Vector3 albedo; 70 | 71 | public Lambertian(Vector3 a) 72 | { 73 | albedo = a; 74 | } 75 | 76 | public bool Scatter(ref Ray r, ref Hit_record rec, ref Vector3 attenuation, ref Ray scattered) 77 | { 78 | Vector3 target = rec.normal.normalized * 0.5f + 79 | new Vector3(Random.Range(-1, 1f), Random.Range(-1f, 1f), Random.Range(-1f, 1f)).normalized; 80 | 81 | scattered.origin = rec.hitpoint; 82 | scattered.direction = target; 83 | attenuation = albedo; 84 | return true; 85 | } 86 | } 87 | 88 | 89 | public class MetalNoFuzz : IMaterial 90 | { 91 | public Vector3 albedo; 92 | 93 | public MetalNoFuzz(Vector3 a) 94 | { 95 | albedo = a; 96 | } 97 | 98 | public bool Scatter(ref Ray r, ref Hit_record rec, ref Vector3 attenuation, ref Ray scattered) 99 | { 100 | Vector3 reflected = Vector3.Reflect(r.direction.normalized, rec.normal.normalized); 101 | 102 | scattered.origin = rec.hitpoint; 103 | scattered.direction = reflected; 104 | attenuation = albedo; 105 | return Vector3.Dot(scattered.direction, rec.normal) > 0; 106 | } 107 | } 108 | 109 | public class Metal : IMaterial 110 | { 111 | public Vector3 albedo; 112 | public float fuzz; 113 | 114 | public Metal(Vector3 a,float f) 115 | { 116 | albedo = a; 117 | fuzz = f; 118 | } 119 | 120 | private Vector3 Random_in_unit_sphere() 121 | { 122 | return new Vector3(Random.Range(-1f, 1f), Random.Range(-1, 1f), Random.Range(-1f, 1f)).normalized; 123 | } 124 | 125 | public bool Scatter(ref Ray r, ref Hit_record rec, ref Vector3 attenuation, ref Ray scattered) 126 | { 127 | Vector3 reflected = Vector3.Reflect(r.direction.normalized, rec.normal.normalized); 128 | reflected = reflected + fuzz * Random_in_unit_sphere(); 129 | 130 | scattered.origin = rec.hitpoint; 131 | scattered.direction = reflected; 132 | attenuation = albedo; 133 | return Vector3.Dot(scattered.direction, rec.normal) > 0; 134 | } 135 | } 136 | 137 | public class Dielectric : IMaterial 138 | { 139 | public float ref_idx; 140 | 141 | public Dielectric(float r) 142 | { 143 | ref_idx = r; 144 | } 145 | 146 | private bool Refract(Vector3 v, Vector3 n, float ni_over_nt,out Vector3 refracted) 147 | { 148 | 149 | v.Normalize(); 150 | n.Normalize(); 151 | float dt = Vector3.Dot(v.normalized, n.normalized); 152 | float discriminant = 1.0f - ni_over_nt * ni_over_nt * (1.0f - dt * dt); 153 | if (discriminant > 0) 154 | { 155 | refracted = ni_over_nt * (v.normalized - n * dt) - n * Mathf.Sqrt(discriminant); 156 | return true; 157 | } 158 | refracted = Vector3.one; 159 | return false; 160 | } 161 | 162 | public bool Scatter(ref Ray r, ref Hit_record rec, ref Vector3 attenuation, ref Ray scattered) 163 | { 164 | Vector3 outward_normal = Vector3.zero; 165 | Vector3 reflected = Vector3.Reflect(r.direction.normalized, rec.normal.normalized); 166 | float ni_over_nt = 0f; 167 | attenuation.x = 1.0f; 168 | attenuation.y = 1.0f; 169 | attenuation.z = 1.0f; 170 | Vector3 refracted; 171 | if (Vector3.Dot(r.direction,rec.normal) > 0) 172 | { 173 | outward_normal = -rec.normal; 174 | ni_over_nt = ref_idx; 175 | } 176 | else 177 | { 178 | outward_normal = rec.normal; 179 | ni_over_nt = 1.0f / ref_idx; 180 | } 181 | 182 | if (Refract(r.direction,outward_normal,ni_over_nt,out refracted)) 183 | { 184 | scattered.origin = rec.hitpoint; 185 | scattered.direction = refracted; 186 | return true; 187 | } 188 | else 189 | { 190 | scattered.origin = rec.hitpoint; 191 | scattered.direction = reflected; 192 | return false; 193 | } 194 | } 195 | } 196 | 197 | public class DielectricShlick : IMaterial 198 | { 199 | public float ref_idx; 200 | 201 | public DielectricShlick(float r) 202 | { 203 | ref_idx = r; 204 | } 205 | 206 | private bool Refract(Vector3 v, Vector3 n, float ni_over_nt, out Vector3 refracted) 207 | { 208 | 209 | v.Normalize(); 210 | n.Normalize(); 211 | float dt = Vector3.Dot(v.normalized, n.normalized); 212 | float discriminant = 1.0f - ni_over_nt * ni_over_nt * (1.0f - dt * dt); 213 | if (discriminant > 0) 214 | { 215 | refracted = ni_over_nt * (v.normalized - n * dt) - n * Mathf.Sqrt(discriminant); 216 | return true; 217 | } 218 | refracted = Vector3.one; 219 | return false; 220 | } 221 | 222 | private float Schlick(float cosine,float ref_idx) 223 | { 224 | float r0 = (1.0f - ref_idx) / (1 + ref_idx); 225 | r0 *= r0; 226 | return r0 + (1 - r0) * Mathf.Pow((1 - cosine), 5); 227 | } 228 | 229 | public bool Scatter(ref Ray r, ref Hit_record rec, ref Vector3 attenuation, ref Ray scattered) 230 | { 231 | Vector3 outward_normal = Vector3.zero; 232 | Vector3 reflected = Vector3.Reflect(r.direction.normalized, rec.normal.normalized); 233 | float ni_over_nt = 0f; 234 | attenuation.x = 1.0f; 235 | attenuation.y = 1.0f; 236 | attenuation.z = 1.0f; 237 | Vector3 refracted; 238 | float reflect_prob; 239 | float cosine; 240 | if (Vector3.Dot(r.direction, rec.normal) > 0) 241 | { 242 | outward_normal = -rec.normal; 243 | ni_over_nt = ref_idx; 244 | cosine = ref_idx * Vector3.Dot(r.direction, rec.normal) / r.direction.magnitude; 245 | } 246 | else 247 | { 248 | outward_normal = rec.normal; 249 | ni_over_nt = 1.0f / ref_idx; 250 | cosine = -Vector3.Dot(r.direction.normalized, rec.normal) / r.direction.magnitude; 251 | } 252 | 253 | var bRefracted = Refract(r.direction, outward_normal, ni_over_nt, out refracted); 254 | if (bRefracted) 255 | { 256 | reflect_prob = Schlick(cosine, ref_idx); 257 | } 258 | else 259 | { 260 | scattered.origin = rec.hitpoint; 261 | scattered.direction = reflected; 262 | reflect_prob = 1.0f; 263 | } 264 | if (Random.Range(0, 1) < reflect_prob) 265 | { 266 | scattered.origin = rec.hitpoint; 267 | scattered.direction = reflected; 268 | } 269 | else 270 | { 271 | scattered.origin = rec.hitpoint; 272 | scattered.direction = refracted; 273 | } 274 | return true; 275 | } 276 | } 277 | 278 | //////////////////////////////////////// 279 | public class Sphere : Hitable 280 | { 281 | public Vector3 center; 282 | 283 | public float radius; 284 | 285 | public IMaterial mat; 286 | 287 | public Sphere() 288 | { 289 | center = Vector3.zero; 290 | radius = 1; 291 | } 292 | 293 | public Sphere(Vector3 c, float r) 294 | { 295 | center = c; 296 | radius = r; 297 | } 298 | 299 | public Sphere(Vector3 c, float r, IMaterial m) 300 | { 301 | center = c; 302 | radius = r; 303 | mat = m; 304 | } 305 | 306 | public bool Hit(Ray ray, ref float t_min, ref float t_max, out Hit_record record) 307 | { 308 | record = new Hit_record(); 309 | Vector3 oc = ray.origin - center; 310 | float a = Vector3.Dot(ray.direction, ray.direction); 311 | float b = Vector3.Dot(oc, ray.direction); 312 | float c = Vector3.Dot(oc, oc) - radius * radius; 313 | float d = b * b - a * c; 314 | if (d > 0) 315 | { 316 | float temp = (-b - Mathf.Sqrt(d)) / a; 317 | if (temp < t_max && temp > t_min) 318 | { 319 | record.t = temp; 320 | record.hitpoint = ray.GetPoint(temp); 321 | record.normal = (record.hitpoint - center) / radius; 322 | record.mat = mat; 323 | return true; 324 | } 325 | temp = (-b + Mathf.Sqrt(d)) / a; 326 | if (temp < t_max && temp > t_min) 327 | { 328 | record.t = temp; 329 | record.hitpoint = ray.GetPoint(temp); 330 | record.normal = (record.hitpoint - center) / radius; 331 | record.mat = mat; 332 | return true; 333 | } 334 | } 335 | return false; 336 | } 337 | }; 338 | 339 | public class Chapter10 340 | { 341 | private static Vector3 topColor = Vector3.one; 342 | private static Vector3 bottomColor = new Vector3(0.5f, 0.9f, 1.0f); 343 | 344 | public static Vector3 RayCast(Ray ray, Hitable world, int depth) 345 | { 346 | Hit_record rec; 347 | float min = 0; 348 | float max = float.MaxValue; 349 | if (world.Hit(ray, ref min, ref max, out rec)) 350 | { 351 | Ray scattered = new Ray(); 352 | Vector3 attenuation = Vector3.one; 353 | 354 | if (depth < 50 && rec.mat.Scatter(ref ray, ref rec, ref attenuation, ref scattered)) 355 | { 356 | var color = RayCast(scattered, world, depth + 1); 357 | attenuation.x *= color.x; 358 | attenuation.y *= color.y; 359 | attenuation.z *= color.z; 360 | return attenuation; 361 | } 362 | else 363 | { 364 | return Vector3.zero; 365 | } 366 | } 367 | else 368 | { 369 | Vector3 unit_direction = ray.direction.normalized; 370 | float t = 0.5f * (unit_direction.y + 1.0f); 371 | return Vector3.Lerp(topColor, bottomColor, t); 372 | } 373 | } 374 | 375 | [MenuItem("Raytracing/Chapter10/1")] 376 | public static void Main() 377 | { 378 | int nx = 1280; 379 | int ny = 640; 380 | int ns = 16; 381 | 382 | RayCamera camera = new RayCamera(); 383 | float R = Mathf.Cos(Mathf.PI / 4); 384 | HitList list = new HitList(); 385 | list.Add(new Sphere(new Vector3(-R, 0, -1), R, new Lambertian(new Vector3(0f, 0f, 1f)))); 386 | list.Add(new Sphere(new Vector3(R, 0, -1), R, new Lambertian(new Vector3(1f, 0f, 0f)))); 387 | 388 | Texture2D tex = ImageHelper.CreateImg(nx, ny); 389 | 390 | for (int j = ny - 1; j >= 0; --j) 391 | { 392 | for (int i = 0; i < nx; ++i) 393 | { 394 | Vector3 color = Vector3.zero; 395 | for (int k = 0; k < ns; ++k) 396 | { 397 | float u = (float)(i + Random.Range(-1f, 1f)) / (float)(nx); 398 | float v = (float)(j + Random.Range(-1f, 1f)) / (float)(ny); 399 | 400 | Ray r = camera.GetRay(u, v); 401 | color += RayCast(r, list, 0); 402 | } 403 | color = color / (float)(ns); 404 | color.x = Mathf.Sqrt(color.x); 405 | color.y = Mathf.Sqrt(color.y); 406 | color.z = Mathf.Sqrt(color.z); 407 | ImageHelper.SetPixel(tex, i, j, color); 408 | } 409 | } 410 | 411 | ImageHelper.SaveImg(tex, "Img/chapter10_1.png"); 412 | Debug.Log("Chapter 10_1 done"); 413 | } 414 | 415 | 416 | [MenuItem("Raytracing/Chapter10/2")] 417 | public static void Main2() 418 | { 419 | int nx = 1280; 420 | int ny = 640; 421 | int ns = 16; 422 | Vector3 lookfrom = new Vector3(-2, 2, 1); 423 | Vector3 lookat = new Vector3(0, 0, -1); 424 | Vector3 up = new Vector3(0, 1, 0); 425 | RayCamera camera = new RayCamera(lookfrom,lookat,up,90,(float)(nx) / (float)(ny)); 426 | 427 | HitList list = new HitList(); 428 | list.Add(new Sphere(new Vector3(0, 0, -1), 0.5f, new Lambertian(new Vector3(0.1f, 0.2f, 0.5f)))); 429 | list.Add(new Sphere(new Vector3(0, -100.5f, -1), 100, new Lambertian(new Vector3(0.8f, 0.8f, 0.0f)))); 430 | list.Add(new Sphere(new Vector3(1, 0, -1), 0.5f, new Metal(new Vector3(0.8f, 0.6f, 0.2f), 0.3f))); 431 | list.Add(new Sphere(new Vector3(-1, 0, -1), 0.5f, new DielectricShlick(1.5f))); 432 | list.Add(new Sphere(new Vector3(-1, 0, -1), -0.45f, new DielectricShlick(1.5f))); 433 | Texture2D tex = ImageHelper.CreateImg(nx, ny); 434 | 435 | for (int j = ny - 1; j >= 0; --j) 436 | { 437 | for (int i = 0; i < nx; ++i) 438 | { 439 | Vector3 color = Vector3.zero; 440 | for (int k = 0; k < ns; ++k) 441 | { 442 | float u = (float)(i + Random.Range(0f, 1f)) / (float)(nx); 443 | float v = (float)(j + Random.Range(0f, 1f)) / (float)(ny); 444 | 445 | Ray r = camera.GetRay(u, v); 446 | color += RayCast(r, list, 0); 447 | } 448 | color = color / (float)(ns); 449 | color.x = Mathf.Sqrt(color.x); 450 | color.y = Mathf.Sqrt(color.y); 451 | color.z = Mathf.Sqrt(color.z); 452 | ImageHelper.SetPixel(tex, i, j, color); 453 | } 454 | } 455 | 456 | ImageHelper.SaveImg(tex, "Img/chapter10_2.png"); 457 | Debug.Log("Chapter 10_2 done"); 458 | } 459 | 460 | 461 | [MenuItem("Raytracing/Chapter10/3")] 462 | public static void Main3() 463 | { 464 | int nx = 1280; 465 | int ny = 640; 466 | int ns = 16; 467 | Vector3 lookfrom = new Vector3(-2, 2, 1); 468 | Vector3 lookat = new Vector3(0, 0, -1); 469 | Vector3 up = new Vector3(0, 1, 0); 470 | RayCamera camera = new RayCamera(lookfrom, lookat, up, 35, (float)(nx) / (float)(ny)); 471 | 472 | HitList list = new HitList(); 473 | list.Add(new Sphere(new Vector3(0, 0, -1), 0.5f, new Lambertian(new Vector3(0.1f, 0.2f, 0.5f)))); 474 | list.Add(new Sphere(new Vector3(0, -100.5f, -1), 100, new Lambertian(new Vector3(0.8f, 0.8f, 0.0f)))); 475 | list.Add(new Sphere(new Vector3(1, 0, -1), 0.5f, new Metal(new Vector3(0.8f, 0.6f, 0.2f), 0.3f))); 476 | list.Add(new Sphere(new Vector3(-1, 0, -1), 0.5f, new DielectricShlick(1.5f))); 477 | list.Add(new Sphere(new Vector3(-1, 0, -1), -0.45f, new DielectricShlick(1.5f))); 478 | Texture2D tex = ImageHelper.CreateImg(nx, ny); 479 | 480 | for (int j = ny - 1; j >= 0; --j) 481 | { 482 | for (int i = 0; i < nx; ++i) 483 | { 484 | Vector3 color = Vector3.zero; 485 | for (int k = 0; k < ns; ++k) 486 | { 487 | float u = (float)(i + Random.Range(0f, 1f)) / (float)(nx); 488 | float v = (float)(j + Random.Range(0f, 1f)) / (float)(ny); 489 | 490 | Ray r = camera.GetRay(u, v); 491 | color += RayCast(r, list, 0); 492 | } 493 | color = color / (float)(ns); 494 | color.x = Mathf.Sqrt(color.x); 495 | color.y = Mathf.Sqrt(color.y); 496 | color.z = Mathf.Sqrt(color.z); 497 | ImageHelper.SetPixel(tex, i, j, color); 498 | } 499 | } 500 | 501 | ImageHelper.SaveImg(tex, "Img/chapter10_3.png"); 502 | Debug.Log("Chapter 10_3 done"); 503 | } 504 | 505 | } 506 | } -------------------------------------------------------------------------------- /Assets/Script/chapter10.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fcc1eb594dc6cb24d9e55993dd4ffb7b 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Script/chapter11.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System.Collections.Generic; 4 | 5 | namespace Chapter11 6 | { 7 | public struct Hit_record 8 | { 9 | public float t; 10 | public Vector3 hitpoint; 11 | public Vector3 normal; 12 | public IMaterial mat; 13 | }; 14 | 15 | public interface IMaterial 16 | { 17 | bool Scatter(ref Ray r, ref Hit_record rec, ref Vector3 attenuation, ref Ray scattered); 18 | }; 19 | 20 | 21 | 22 | public interface Hitable 23 | { 24 | bool Hit(Ray r, ref float t_min, ref float t_max, out Hit_record record); 25 | }; 26 | 27 | public class HitList : Hitable 28 | { 29 | private List list = new List(); 30 | 31 | public HitList() 32 | { 33 | } 34 | 35 | public int GetCount() 36 | { 37 | return list.Count; 38 | } 39 | 40 | public void Add(Hitable item) 41 | { 42 | list.Add(item); 43 | } 44 | 45 | public bool Hit(Ray r, ref float t_min, ref float t_max, out Hit_record record) 46 | { 47 | Hit_record temp_rec = new Hit_record(); 48 | record = temp_rec; 49 | bool hit_anything = false; 50 | float closest_so_far = t_max; 51 | 52 | for (int i = 0; i < list.Count; ++i) 53 | { 54 | if (list[i].Hit(r, ref t_min, ref closest_so_far, out temp_rec)) 55 | { 56 | hit_anything = true; 57 | closest_so_far = temp_rec.t; 58 | record = temp_rec; 59 | } 60 | } 61 | 62 | return hit_anything; 63 | } 64 | }; 65 | 66 | 67 | public class Lambertian : IMaterial 68 | { 69 | public Vector3 albedo; 70 | 71 | public Lambertian(Vector3 a) 72 | { 73 | albedo = a; 74 | } 75 | 76 | public bool Scatter(ref Ray r, ref Hit_record rec, ref Vector3 attenuation, ref Ray scattered) 77 | { 78 | Vector3 target = rec.normal.normalized * 0.5f + 79 | new Vector3(Chapter11.RandomFloat11(), Chapter11.RandomFloat11(), Chapter11.RandomFloat11()).normalized; 80 | 81 | scattered.origin = rec.hitpoint; 82 | scattered.direction = target; 83 | attenuation = albedo; 84 | return true; 85 | } 86 | } 87 | 88 | 89 | public class MetalNoFuzz : IMaterial 90 | { 91 | public Vector3 albedo; 92 | 93 | public MetalNoFuzz(Vector3 a) 94 | { 95 | albedo = a; 96 | } 97 | 98 | public bool Scatter(ref Ray r, ref Hit_record rec, ref Vector3 attenuation, ref Ray scattered) 99 | { 100 | Vector3 reflected = Vector3.Reflect(r.direction.normalized, rec.normal.normalized); 101 | 102 | scattered.origin = rec.hitpoint; 103 | scattered.direction = reflected; 104 | attenuation = albedo; 105 | return Vector3.Dot(scattered.direction, rec.normal) > 0; 106 | } 107 | } 108 | 109 | public class Metal : IMaterial 110 | { 111 | public Vector3 albedo; 112 | public float fuzz; 113 | 114 | public Metal(Vector3 a,float f) 115 | { 116 | albedo = a; 117 | fuzz = f; 118 | } 119 | 120 | private Vector3 Random_in_unit_sphere() 121 | { 122 | return new Vector3(Chapter11.RandomFloat11(), Chapter11.RandomFloat11(), Chapter11.RandomFloat11()).normalized; 123 | } 124 | 125 | public bool Scatter(ref Ray r, ref Hit_record rec, ref Vector3 attenuation, ref Ray scattered) 126 | { 127 | Vector3 reflected = Vector3.Reflect(r.direction.normalized, rec.normal.normalized); 128 | reflected = reflected + fuzz * Random_in_unit_sphere(); 129 | 130 | scattered.origin = rec.hitpoint; 131 | scattered.direction = reflected; 132 | attenuation = albedo; 133 | return Vector3.Dot(scattered.direction, rec.normal) > 0; 134 | } 135 | } 136 | 137 | public class Dielectric : IMaterial 138 | { 139 | public float ref_idx; 140 | 141 | public Dielectric(float r) 142 | { 143 | ref_idx = r; 144 | } 145 | 146 | private bool Refract(Vector3 v, Vector3 n, float ni_over_nt,out Vector3 refracted) 147 | { 148 | 149 | v.Normalize(); 150 | n.Normalize(); 151 | float dt = Vector3.Dot(v.normalized, n.normalized); 152 | float discriminant = 1.0f - ni_over_nt * ni_over_nt * (1.0f - dt * dt); 153 | if (discriminant > 0) 154 | { 155 | refracted = ni_over_nt * (v.normalized - n * dt) - n * Mathf.Sqrt(discriminant); 156 | return true; 157 | } 158 | refracted = Vector3.one; 159 | return false; 160 | } 161 | 162 | public bool Scatter(ref Ray r, ref Hit_record rec, ref Vector3 attenuation, ref Ray scattered) 163 | { 164 | Vector3 outward_normal = Vector3.zero; 165 | Vector3 reflected = Vector3.Reflect(r.direction.normalized, rec.normal.normalized); 166 | float ni_over_nt = 0f; 167 | attenuation.x = 1.0f; 168 | attenuation.y = 1.0f; 169 | attenuation.z = 1.0f; 170 | Vector3 refracted; 171 | if (Vector3.Dot(r.direction,rec.normal) > 0) 172 | { 173 | outward_normal = -rec.normal; 174 | ni_over_nt = ref_idx; 175 | } 176 | else 177 | { 178 | outward_normal = rec.normal; 179 | ni_over_nt = 1.0f / ref_idx; 180 | } 181 | 182 | if (Refract(r.direction,outward_normal,ni_over_nt,out refracted)) 183 | { 184 | scattered.origin = rec.hitpoint; 185 | scattered.direction = refracted; 186 | return true; 187 | } 188 | else 189 | { 190 | scattered.origin = rec.hitpoint; 191 | scattered.direction = reflected; 192 | return false; 193 | } 194 | } 195 | } 196 | 197 | public class DielectricShlick : IMaterial 198 | { 199 | public float ref_idx; 200 | 201 | public DielectricShlick(float r) 202 | { 203 | ref_idx = r; 204 | } 205 | 206 | private bool Refract(Vector3 v, Vector3 n, float ni_over_nt, out Vector3 refracted) 207 | { 208 | 209 | v.Normalize(); 210 | n.Normalize(); 211 | float dt = Vector3.Dot(v.normalized, n.normalized); 212 | float discriminant = 1.0f - ni_over_nt * ni_over_nt * (1.0f - dt * dt); 213 | if (discriminant > 0) 214 | { 215 | refracted = ni_over_nt * (v.normalized - n * dt) - n * Mathf.Sqrt(discriminant); 216 | return true; 217 | } 218 | refracted = Vector3.one; 219 | return false; 220 | } 221 | 222 | private float Schlick(float cosine,float ref_idx) 223 | { 224 | float r0 = (1.0f - ref_idx) / (1 + ref_idx); 225 | r0 *= r0; 226 | return r0 + (1 - r0) * Mathf.Pow((1 - cosine), 5); 227 | } 228 | 229 | public bool Scatter(ref Ray r, ref Hit_record rec, ref Vector3 attenuation, ref Ray scattered) 230 | { 231 | Vector3 outward_normal = Vector3.zero; 232 | Vector3 reflected = Vector3.Reflect(r.direction.normalized, rec.normal.normalized); 233 | float ni_over_nt = 0f; 234 | attenuation.x = 1.0f; 235 | attenuation.y = 1.0f; 236 | attenuation.z = 1.0f; 237 | Vector3 refracted; 238 | float reflect_prob; 239 | float cosine; 240 | if (Vector3.Dot(r.direction, rec.normal) > 0) 241 | { 242 | outward_normal = -rec.normal; 243 | ni_over_nt = ref_idx; 244 | cosine = ref_idx * Vector3.Dot(r.direction, rec.normal) / r.direction.magnitude; 245 | } 246 | else 247 | { 248 | outward_normal = rec.normal; 249 | ni_over_nt = 1.0f / ref_idx; 250 | cosine = -Vector3.Dot(r.direction.normalized, rec.normal) / r.direction.magnitude; 251 | } 252 | 253 | var bRefracted = Refract(r.direction, outward_normal, ni_over_nt, out refracted); 254 | if (bRefracted) 255 | { 256 | reflect_prob = Schlick(cosine, ref_idx); 257 | } 258 | else 259 | { 260 | scattered.origin = rec.hitpoint; 261 | scattered.direction = reflected; 262 | reflect_prob = 1.0f; 263 | } 264 | if (Chapter11.RandomFloat01() < reflect_prob) 265 | { 266 | scattered.origin = rec.hitpoint; 267 | scattered.direction = reflected; 268 | } 269 | else 270 | { 271 | scattered.origin = rec.hitpoint; 272 | scattered.direction = refracted; 273 | } 274 | return true; 275 | } 276 | } 277 | 278 | //////////////////////////////////////// 279 | public class Sphere : Hitable 280 | { 281 | public Vector3 center; 282 | 283 | public float radius; 284 | 285 | public IMaterial mat; 286 | 287 | public Sphere() 288 | { 289 | center = Vector3.zero; 290 | radius = 1; 291 | } 292 | 293 | public Sphere(Vector3 c, float r) 294 | { 295 | center = c; 296 | radius = r; 297 | } 298 | 299 | public Sphere(Vector3 c, float r, IMaterial m) 300 | { 301 | center = c; 302 | radius = r; 303 | mat = m; 304 | } 305 | 306 | public bool Hit(Ray ray, ref float t_min, ref float t_max, out Hit_record record) 307 | { 308 | record = new Hit_record(); 309 | Vector3 oc = ray.origin - center; 310 | float a = Vector3.Dot(ray.direction, ray.direction); 311 | float b = Vector3.Dot(oc, ray.direction); 312 | float c = Vector3.Dot(oc, oc) - radius * radius; 313 | float d = b * b - a * c; 314 | if (d > 0) 315 | { 316 | float temp = (-b - Mathf.Sqrt(d)) / a; 317 | if (temp < t_max && temp > t_min) 318 | { 319 | record.t = temp; 320 | record.hitpoint = ray.GetPoint(temp); 321 | record.normal = (record.hitpoint - center) / radius; 322 | record.mat = mat; 323 | return true; 324 | } 325 | temp = (-b + Mathf.Sqrt(d)) / a; 326 | if (temp < t_max && temp > t_min) 327 | { 328 | record.t = temp; 329 | record.hitpoint = ray.GetPoint(temp); 330 | record.normal = (record.hitpoint - center) / radius; 331 | record.mat = mat; 332 | return true; 333 | } 334 | } 335 | return false; 336 | } 337 | }; 338 | 339 | public class Chapter11 340 | { 341 | private static Vector3 topColor = Vector3.one; 342 | private static Vector3 bottomColor = new Vector3(0.5f, 0.9f, 1.0f); 343 | 344 | private static System.Random random = new System.Random(); 345 | 346 | public static Vector3 RayCast(Ray ray, Hitable world, int depth) 347 | { 348 | Hit_record rec; 349 | float min = 0; 350 | float max = float.MaxValue; 351 | if (world.Hit(ray, ref min, ref max, out rec)) 352 | { 353 | Ray scattered = new Ray(); 354 | Vector3 attenuation = Vector3.one; 355 | 356 | if (depth < 50 && rec.mat.Scatter(ref ray, ref rec, ref attenuation, ref scattered)) 357 | { 358 | var color = RayCast(scattered, world, depth + 1); 359 | attenuation.x *= color.x; 360 | attenuation.y *= color.y; 361 | attenuation.z *= color.z; 362 | return attenuation; 363 | } 364 | else 365 | { 366 | return Vector3.zero; 367 | } 368 | } 369 | else 370 | { 371 | Vector3 unit_direction = ray.direction.normalized; 372 | float t = 0.5f * (unit_direction.y + 1.0f); 373 | return Vector3.Lerp(topColor, bottomColor, t); 374 | } 375 | } 376 | 377 | public static float RandomFloat01() 378 | { 379 | return (float)(random.NextDouble()); 380 | } 381 | 382 | public static float RandomFloat11() 383 | { 384 | return (float)(random.NextDouble() * 2.0f - 1.0f); 385 | } 386 | 387 | [MenuItem("Raytracing/Chapter11")] 388 | public static void Main() 389 | { 390 | int nx = 1280; 391 | int ny = 640; 392 | int ns = 100; 393 | Vector3 lookfrom = new Vector3(3, 3, 2); 394 | Vector3 lookat = new Vector3(0, 0, -1); 395 | float dist_to_focus = (lookfrom - lookat).magnitude; 396 | float aperture = 2.0f; 397 | Vector3 up = new Vector3(0, 1, 0); 398 | MotionBlurRayCamera camera = new MotionBlurRayCamera(lookfrom, lookat, up, 20, 399 | (float)(nx) / (float)(ny),aperture,dist_to_focus); 400 | 401 | HitList list = new HitList(); 402 | list.Add(new Sphere(new Vector3(0, 0, -1), 0.5f, new Lambertian(new Vector3(0.1f, 0.2f, 0.5f)))); 403 | list.Add(new Sphere(new Vector3(0, -100.5f, -1), 100, new Lambertian(new Vector3(0.8f, 0.8f, 0.0f)))); 404 | list.Add(new Sphere(new Vector3(1, 0, -1), 0.5f, new Metal(new Vector3(0.8f, 0.6f, 0.2f), 0.3f))); 405 | list.Add(new Sphere(new Vector3(-1, 0, -1), 0.5f, new DielectricShlick(1.5f))); 406 | list.Add(new Sphere(new Vector3(-1, 0, -1), -0.45f, new DielectricShlick(1.5f))); 407 | Texture2D tex = ImageHelper.CreateImg(nx, ny); 408 | 409 | for (int j = ny - 1; j >= 0; --j) 410 | { 411 | for (int i = 0; i < nx; ++i) 412 | { 413 | Vector3 color = Vector3.zero; 414 | for (int k = 0; k < ns; ++k) 415 | { 416 | float u = (float)(i + RandomFloat01()) / (float)(nx); 417 | float v = (float)(j + RandomFloat01()) / (float)(ny); 418 | 419 | Ray r = camera.GetRay(u, v); 420 | color += RayCast(r, list, 0); 421 | } 422 | color = color / (float)(ns); 423 | color.x = Mathf.Sqrt(color.x); 424 | color.y = Mathf.Sqrt(color.y); 425 | color.z = Mathf.Sqrt(color.z); 426 | ImageHelper.SetPixel(tex, i, j, color); 427 | } 428 | } 429 | 430 | ImageHelper.SaveImg(tex, "Img/chapter11_1.png"); 431 | Debug.Log("Chapter 11 done"); 432 | } 433 | 434 | } 435 | } -------------------------------------------------------------------------------- /Assets/Script/chapter11.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a27ac217ba7ccde4eafac169c0a65a09 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Script/chapter12.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System.Threading; 4 | using System.Collections.Generic; 5 | 6 | namespace Chapter12 7 | { 8 | public struct Hit_record 9 | { 10 | public float t; 11 | public Vector3 hitpoint; 12 | public Vector3 normal; 13 | public IMaterial mat; 14 | }; 15 | 16 | public interface IMaterial 17 | { 18 | bool Scatter(ref Ray r, ref Hit_record rec, ref Vector3 attenuation, ref Ray scattered,System.Random seed); 19 | }; 20 | 21 | 22 | 23 | public interface Hitable 24 | { 25 | bool Hit(Ray r, ref float t_min, ref float t_max, out Hit_record record); 26 | }; 27 | 28 | public class HitList : Hitable 29 | { 30 | private List list = new List(); 31 | 32 | public HitList() 33 | { 34 | } 35 | 36 | public int GetCount() 37 | { 38 | return list.Count; 39 | } 40 | 41 | public void Add(Hitable item) 42 | { 43 | list.Add(item); 44 | } 45 | 46 | public bool Hit(Ray r, ref float t_min, ref float t_max, out Hit_record record) 47 | { 48 | Hit_record temp_rec = new Hit_record(); 49 | record = temp_rec; 50 | bool hit_anything = false; 51 | float closest_so_far = t_max; 52 | 53 | for (int i = 0; i < list.Count; ++i) 54 | { 55 | if (list[i].Hit(r, ref t_min, ref closest_so_far, out temp_rec)) 56 | { 57 | hit_anything = true; 58 | closest_so_far = temp_rec.t; 59 | record = temp_rec; 60 | } 61 | } 62 | 63 | return hit_anything; 64 | } 65 | }; 66 | 67 | 68 | public class Lambertian : IMaterial 69 | { 70 | public Vector3 albedo; 71 | 72 | public Lambertian(Vector3 a) 73 | { 74 | albedo = a; 75 | } 76 | 77 | public bool Scatter(ref Ray r, ref Hit_record rec, ref Vector3 attenuation, ref Ray scattered,System.Random seed) 78 | { 79 | Vector3 target = rec.normal.normalized * 0.5f + 80 | new Vector3(Chapter12.RandomFloat11(seed), Chapter12.RandomFloat11(seed), Chapter12.RandomFloat11(seed)).normalized; 81 | 82 | scattered.origin = rec.hitpoint; 83 | scattered.direction = target; 84 | attenuation = albedo; 85 | return true; 86 | } 87 | } 88 | 89 | 90 | public class MetalNoFuzz : IMaterial 91 | { 92 | public Vector3 albedo; 93 | 94 | public MetalNoFuzz(Vector3 a) 95 | { 96 | albedo = a; 97 | } 98 | 99 | public bool Scatter(ref Ray r, ref Hit_record rec, ref Vector3 attenuation, ref Ray scattered, System.Random seed) 100 | { 101 | Vector3 reflected = Vector3.Reflect(r.direction.normalized, rec.normal.normalized); 102 | 103 | scattered.origin = rec.hitpoint; 104 | scattered.direction = reflected; 105 | attenuation = albedo; 106 | return Vector3.Dot(scattered.direction, rec.normal) > 0; 107 | } 108 | } 109 | 110 | public class Metal : IMaterial 111 | { 112 | public Vector3 albedo; 113 | public float fuzz; 114 | 115 | public Metal(Vector3 a, float f) 116 | { 117 | albedo = a; 118 | fuzz = f; 119 | } 120 | 121 | private Vector3 Random_in_unit_sphere(System.Random seed) 122 | { 123 | return new Vector3(Chapter12.RandomFloat11(seed), Chapter12.RandomFloat11(seed), Chapter12.RandomFloat11(seed)).normalized; 124 | } 125 | 126 | public bool Scatter(ref Ray r, ref Hit_record rec, ref Vector3 attenuation, ref Ray scattered, System.Random seed) 127 | { 128 | Vector3 reflected = Vector3.Reflect(r.direction.normalized, rec.normal.normalized); 129 | reflected = reflected + fuzz * Random_in_unit_sphere(seed); 130 | 131 | scattered.origin = rec.hitpoint; 132 | scattered.direction = reflected; 133 | attenuation = albedo; 134 | return Vector3.Dot(scattered.direction, rec.normal) > 0; 135 | } 136 | } 137 | 138 | public class Dielectric : IMaterial 139 | { 140 | public float ref_idx; 141 | 142 | public Dielectric(float r) 143 | { 144 | ref_idx = r; 145 | } 146 | 147 | private bool Refract(Vector3 v, Vector3 n, float ni_over_nt, out Vector3 refracted) 148 | { 149 | 150 | v.Normalize(); 151 | n.Normalize(); 152 | float dt = Vector3.Dot(v.normalized, n.normalized); 153 | float discriminant = 1.0f - ni_over_nt * ni_over_nt * (1.0f - dt * dt); 154 | if (discriminant > 0) 155 | { 156 | refracted = ni_over_nt * (v.normalized - n * dt) - n * Mathf.Sqrt(discriminant); 157 | return true; 158 | } 159 | refracted = Vector3.one; 160 | return false; 161 | } 162 | 163 | public bool Scatter(ref Ray r, ref Hit_record rec, ref Vector3 attenuation, ref Ray scattered, System.Random seed) 164 | { 165 | Vector3 outward_normal = Vector3.zero; 166 | Vector3 reflected = Vector3.Reflect(r.direction.normalized, rec.normal.normalized); 167 | float ni_over_nt = 0f; 168 | attenuation.x = 1.0f; 169 | attenuation.y = 1.0f; 170 | attenuation.z = 1.0f; 171 | Vector3 refracted; 172 | if (Vector3.Dot(r.direction, rec.normal) > 0) 173 | { 174 | outward_normal = -rec.normal; 175 | ni_over_nt = ref_idx; 176 | } 177 | else 178 | { 179 | outward_normal = rec.normal; 180 | ni_over_nt = 1.0f / ref_idx; 181 | } 182 | 183 | if (Refract(r.direction, outward_normal, ni_over_nt, out refracted)) 184 | { 185 | scattered.origin = rec.hitpoint; 186 | scattered.direction = refracted; 187 | return true; 188 | } 189 | else 190 | { 191 | scattered.origin = rec.hitpoint; 192 | scattered.direction = reflected; 193 | return false; 194 | } 195 | } 196 | } 197 | 198 | public class DielectricShlick : IMaterial 199 | { 200 | public float ref_idx; 201 | 202 | public DielectricShlick(float r) 203 | { 204 | ref_idx = r; 205 | } 206 | 207 | private bool Refract(Vector3 v, Vector3 n, float ni_over_nt, out Vector3 refracted) 208 | { 209 | 210 | v.Normalize(); 211 | n.Normalize(); 212 | float dt = Vector3.Dot(v.normalized, n.normalized); 213 | float discriminant = 1.0f - ni_over_nt * ni_over_nt * (1.0f - dt * dt); 214 | if (discriminant > 0) 215 | { 216 | refracted = ni_over_nt * (v.normalized - n * dt) - n * Mathf.Sqrt(discriminant); 217 | return true; 218 | } 219 | refracted = Vector3.one; 220 | return false; 221 | } 222 | 223 | private float Schlick(float cosine, float idx) 224 | { 225 | float r0 = (1.0f - idx) / (1 + idx); 226 | r0 *= r0; 227 | return r0 + (1 - r0) * Mathf.Pow((1 - cosine), 5); 228 | } 229 | 230 | public bool Scatter(ref Ray r, ref Hit_record rec, ref Vector3 attenuation, ref Ray scattered, System.Random seed) 231 | { 232 | Vector3 outward_normal = Vector3.zero; 233 | Vector3 reflected = Vector3.Reflect(r.direction.normalized, rec.normal.normalized); 234 | float ni_over_nt = 0f; 235 | attenuation.x = 1.0f; 236 | attenuation.y = 1.0f; 237 | attenuation.z = 1.0f; 238 | Vector3 refracted; 239 | float reflect_prob; 240 | float cosine; 241 | if (Vector3.Dot(r.direction, rec.normal) > 0) 242 | { 243 | outward_normal = -rec.normal; 244 | ni_over_nt = ref_idx; 245 | cosine = ref_idx * Vector3.Dot(r.direction, rec.normal) / r.direction.magnitude; 246 | } 247 | else 248 | { 249 | outward_normal = rec.normal; 250 | ni_over_nt = 1.0f / ref_idx; 251 | cosine = -Vector3.Dot(r.direction.normalized, rec.normal) / r.direction.magnitude; 252 | } 253 | 254 | var bRefracted = Refract(r.direction, outward_normal, ni_over_nt, out refracted); 255 | if (bRefracted) 256 | { 257 | reflect_prob = Schlick(cosine, ref_idx); 258 | } 259 | else 260 | { 261 | scattered.origin = rec.hitpoint; 262 | scattered.direction = reflected; 263 | reflect_prob = 1.0f; 264 | } 265 | if (Chapter12.RandomFloat01(seed) < reflect_prob) 266 | { 267 | scattered.origin = rec.hitpoint; 268 | scattered.direction = reflected; 269 | } 270 | else 271 | { 272 | scattered.origin = rec.hitpoint; 273 | scattered.direction = refracted; 274 | } 275 | return true; 276 | } 277 | } 278 | 279 | //////////////////////////////////////// 280 | public class Sphere : Hitable 281 | { 282 | public Vector3 center; 283 | 284 | public float radius; 285 | 286 | public IMaterial mat; 287 | 288 | public Sphere() 289 | { 290 | center = Vector3.zero; 291 | radius = 1; 292 | } 293 | 294 | public Sphere(Vector3 c, float r) 295 | { 296 | center = c; 297 | radius = r; 298 | } 299 | 300 | public Sphere(Vector3 c, float r, IMaterial m) 301 | { 302 | center = c; 303 | radius = r; 304 | mat = m; 305 | } 306 | 307 | public bool Hit(Ray ray, ref float t_min, ref float t_max, out Hit_record record) 308 | { 309 | record = new Hit_record(); 310 | Vector3 oc = ray.origin - center; 311 | float a = Vector3.Dot(ray.direction, ray.direction); 312 | float b = Vector3.Dot(oc, ray.direction); 313 | float c = Vector3.Dot(oc, oc) - radius * radius; 314 | float d = b * b - a * c; 315 | if (d > 0) 316 | { 317 | float temp = (-b - Mathf.Sqrt(d)) / a; 318 | if (temp < t_max && temp > t_min) 319 | { 320 | record.t = temp; 321 | record.hitpoint = ray.GetPoint(temp); 322 | record.normal = (record.hitpoint - center) / radius; 323 | record.mat = mat; 324 | return true; 325 | } 326 | temp = (-b + Mathf.Sqrt(d)) / a; 327 | if (temp < t_max && temp > t_min) 328 | { 329 | record.t = temp; 330 | record.hitpoint = ray.GetPoint(temp); 331 | record.normal = (record.hitpoint - center) / radius; 332 | record.mat = mat; 333 | return true; 334 | } 335 | } 336 | return false; 337 | } 338 | }; 339 | 340 | public class Chapter12 341 | { 342 | private static Vector3 topColor = Vector3.one; 343 | private static Vector3 bottomColor = new Vector3(0.5f, 0.9f, 1.0f); 344 | 345 | private static System.Random gSeed = new System.Random(); 346 | //private static readonly object locker = new object(); 347 | 348 | private static int myThreadCount = 0; 349 | 350 | public class Param 351 | { 352 | public Hitable world; 353 | public MotionBlurRayCamera camera; 354 | public int pos_x; 355 | public int pos_y; 356 | public int img_width; 357 | public int img_height; 358 | public int times; 359 | public Vector3[,] img; 360 | public ManualResetEvent mre; 361 | public System.Random seed; 362 | } 363 | 364 | public static void ThreadRayMain(System.Object obj) 365 | { 366 | Param parma = (Param)obj; 367 | DoRaycastInThread(parma.world, parma.camera, parma.pos_x, parma.pos_y, 368 | parma.img_width, parma.img_height, parma.times, parma.img,parma.mre,parma.seed); 369 | } 370 | 371 | public static void DoRaycastInThread(Hitable world, MotionBlurRayCamera camera, 372 | int i, int j, int nx, float ny, int ns, Vector3[,] img,ManualResetEvent mre,System.Random seed) 373 | { 374 | Vector3 color = Vector3.zero; 375 | for (int k = 0; k < ns; ++k) 376 | { 377 | float u = (float)(i + RandomFloat01(seed)) / (float)(nx); 378 | float v = (float)(j + RandomFloat01(seed)) / (float)(ny); 379 | Ray r = camera.GetRay(u, v,seed); 380 | color += RayCast(r, world,seed,0); 381 | } 382 | color = color / (float)(ns); 383 | color.x = Mathf.Sqrt(color.x); 384 | color.y = Mathf.Sqrt(color.y); 385 | color.z = Mathf.Sqrt(color.z); 386 | 387 | //lock (img) 388 | { 389 | img[i, j] = color; 390 | } 391 | 392 | if (Interlocked.Decrement(ref myThreadCount) == 0) 393 | { 394 | mre.Set(); 395 | } 396 | 397 | } 398 | 399 | public static Vector3 RayCast(Ray ray, Hitable world,System.Random seed, int depth) 400 | { 401 | Hit_record rec; 402 | float min = 0; 403 | float max = float.MaxValue; 404 | if (world.Hit(ray, ref min, ref max, out rec)) 405 | { 406 | Ray scattered = new Ray(); 407 | Vector3 attenuation = Vector3.one; 408 | 409 | if (depth < 50 && rec.mat.Scatter(ref ray, ref rec, ref attenuation, ref scattered,seed)) 410 | { 411 | var color = RayCast(scattered, world, seed,depth + 1); 412 | attenuation.x *= color.x; 413 | attenuation.y *= color.y; 414 | attenuation.z *= color.z; 415 | return attenuation; 416 | } 417 | else 418 | { 419 | return Vector3.zero; 420 | } 421 | } 422 | else 423 | { 424 | Vector3 unit_direction = ray.direction.normalized; 425 | float t = 0.5f * (unit_direction.y + 1.0f); 426 | return Vector3.Lerp(topColor, bottomColor, t); 427 | } 428 | } 429 | 430 | public static float RandomFloat01(System.Random random) 431 | { 432 | //lock (locker) 433 | //{ 434 | // return (float)(random.NextDouble()); 435 | //} 436 | return (float)(random.NextDouble() * 2.0f - 1.0f); 437 | } 438 | 439 | public static float RandomFloat11(System.Random random) 440 | { 441 | //lock (locker) 442 | //{ 443 | // return (float)(random.NextDouble() * 2.0f - 1.0f); 444 | //} 445 | return (float)(random.NextDouble() * 2.0f - 1.0f); 446 | } 447 | 448 | private static void RandomScene(ref HitList list) 449 | { 450 | list.Add(new Sphere(new Vector3(0, -1000, 0), 1000f, new Lambertian(new Vector3(0.5f, 0.5f, 0.5f)))); 451 | for (int i = -11; i < 11; ++i) 452 | { 453 | for (int j = -11; j < 11; ++j) 454 | { 455 | Vector3 center = new Vector3(i + 0.9f * RandomFloat01(gSeed), 0.2f, j + 0.9f * RandomFloat01(gSeed)); 456 | Vector3 baseCenter = new Vector3(4, 0.2f, 0); 457 | float choose_mat = RandomFloat01(gSeed); 458 | if ((center - baseCenter).magnitude > 0.9) 459 | { 460 | if (choose_mat < 0.5f) 461 | { 462 | list.Add(new Sphere(center, 0.2f, new Lambertian(new Vector3(RandomFloat01(gSeed) * RandomFloat01(gSeed), 463 | RandomFloat01(gSeed) * RandomFloat01(gSeed), RandomFloat01(gSeed) * RandomFloat01(gSeed))))); 464 | } 465 | else if (choose_mat < 0.75f) 466 | { 467 | list.Add(new Sphere(center, 0.2f, new Metal(new Vector3(0.5f * (1 + RandomFloat01(gSeed)), 468 | 0.5f * (1 + RandomFloat01(gSeed)), 469 | 0.5f * (1 + RandomFloat01(gSeed))), 0.5f * RandomFloat01(gSeed)))); 470 | } 471 | else 472 | { 473 | list.Add(new Sphere(center, 0.2f, new Dielectric(1.5f))); 474 | } 475 | } 476 | } 477 | } 478 | 479 | list.Add(new Sphere(new Vector3(0, 1, 0), 1f, new Dielectric(1.5f))); 480 | list.Add(new Sphere(new Vector3(-4, 1, 0), 1f, new Lambertian(new Vector3(0.4f, 0.2f, 0.1f)))); 481 | list.Add(new Sphere(new Vector3(4, 1, 0), 1f, new Metal(new Vector3(0.7f, 0.6f, 0.5f), 0.0f))); 482 | } 483 | 484 | [MenuItem("Raytracing/Chapter12/SingleThread(Slow)")] 485 | public static void Main() 486 | { 487 | int nx = 640; 488 | int ny = 480; 489 | int ns = 32; 490 | 491 | Vector3 lookfrom = new Vector3(13, 5, 3); 492 | Vector3 lookat = new Vector3(0, 0, 0); 493 | float dist_to_focus = 10; 494 | float aperture = 0.1f; 495 | Vector3 up = new Vector3(0, 1, 0); 496 | MotionBlurRayCamera camera = new MotionBlurRayCamera(lookfrom, lookat, up, 20, 497 | (float)(nx) / (float)(ny), aperture, dist_to_focus); 498 | 499 | HitList list = new HitList(); 500 | RandomScene(ref list); 501 | Texture2D tex = ImageHelper.CreateImg(nx, ny); 502 | 503 | for (int j = ny - 1; j >= 0; --j) 504 | { 505 | for (int i = 0; i < nx; ++i) 506 | { 507 | Vector3 color = Vector3.zero; 508 | for (int k = 0; k < ns; ++k) 509 | { 510 | float u = (float)(i + RandomFloat01(gSeed)) / (float)(nx); 511 | float v = (float)(j + RandomFloat01(gSeed)) / (float)(ny); 512 | 513 | Ray r = camera.GetRay(u, v); 514 | color += RayCast(r, list,gSeed, 0); 515 | } 516 | color = color / (float)(ns); 517 | color.x = Mathf.Sqrt(color.x); 518 | color.y = Mathf.Sqrt(color.y); 519 | color.z = Mathf.Sqrt(color.z); 520 | ImageHelper.SetPixel(tex, i, j, color); 521 | } 522 | } 523 | 524 | ImageHelper.SaveImg(tex, "Img/chapter12_single.png"); 525 | Debug.Log("Chapter 12 done"); 526 | } 527 | 528 | 529 | [MenuItem("Raytracing/Chapter12/MutiThread")] 530 | public static void Test() 531 | { 532 | var b = ThreadPool.SetMaxThreads(System.Environment.ProcessorCount, System.Environment.ProcessorCount); 533 | //Debug.Log(b); 534 | 535 | int nx = 1280; 536 | int ny = 720; 537 | int ns = 128; 538 | 539 | myThreadCount = nx * ny ; 540 | 541 | Vector3 lookfrom = new Vector3(13, 3, 3); 542 | Vector3 lookat = new Vector3(0, 0, 0); 543 | float dist_to_focus = 10; 544 | float aperture = 0.1f; 545 | Vector3 up = new Vector3(0, 1, 0); 546 | MotionBlurRayCamera camera = new MotionBlurRayCamera(lookfrom, lookat, up, 20, 547 | (float)(nx) / (float)(ny), aperture, dist_to_focus); 548 | 549 | HitList list = new HitList(); 550 | RandomScene(ref list); 551 | Texture2D tex = ImageHelper.CreateImg(nx, ny); 552 | Vector3[,] imgBin = new Vector3[nx, ny]; 553 | 554 | ManualResetEvent resetEvent = new ManualResetEvent(false); 555 | 556 | for (int j = ny - 1; j >= 0; --j) 557 | { 558 | for (int i = 0; i < nx; ++i) 559 | { 560 | var param = new Param(); 561 | param.world = list; 562 | param.camera = camera; 563 | param.pos_x = i; 564 | param.pos_y = j; 565 | param.img_width = nx; 566 | param.img_height = ny; 567 | param.times = ns; 568 | param.img = imgBin; 569 | param.mre = resetEvent; 570 | param.seed = new System.Random(); 571 | 572 | while (!ThreadPool.QueueUserWorkItem(ThreadRayMain, param)) 573 | { 574 | Debug.Log("wait "); 575 | Thread.Sleep(500); 576 | } 577 | } 578 | } 579 | resetEvent.WaitOne(); 580 | 581 | for (int j = ny - 1; j >= 0; --j) 582 | { 583 | for (int i = 0; i < nx; ++i) 584 | { 585 | ImageHelper.SetPixel(tex, i, j, imgBin[i, j]); 586 | } 587 | } 588 | ImageHelper.SaveImg(tex, "Img/chapter12.png"); 589 | Debug.Log("Chapter 12 done"); 590 | } 591 | } 592 | } -------------------------------------------------------------------------------- /Assets/Script/chapter12.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 160c6cf66053ebc48b553cf041db5fff 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Script/chapter3.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | 4 | public class Chapter3 5 | { 6 | private static Vector3 topColor = Vector3.one; 7 | private static Vector3 bottomColor = new Vector3(0.5f, 0.7f, 1.0f); 8 | 9 | 10 | public static Vector3 RayCast(Ray ray) 11 | { 12 | Vector3 unit_direction = ray.direction.normalized; 13 | float t = 0.5f * (unit_direction.y + 1.0f); 14 | return Vector3.Lerp(topColor, bottomColor, t); 15 | } 16 | 17 | [MenuItem("Raytracing/Chapter3")] 18 | public static void Main() 19 | { 20 | int nx = 1280; 21 | int ny = 720; 22 | 23 | Vector3 lower_left_corner = new Vector3(-2.0f, -1.0f, -1.0f); 24 | Vector3 horizontal = new Vector3(4.0f, 0.0f, 0.0f); 25 | Vector3 vertical = new Vector3(0.0f, 2.0f, 0.0f); 26 | Vector3 origin = Vector3.zero; 27 | 28 | Texture2D tex = ImageHelper.CreateImg(nx, ny); 29 | for (int j = ny - 1; j >= 0; --j) 30 | { 31 | for (int i = 0; i < nx; ++i) 32 | { 33 | float u = (float)(i) / (float)(nx); 34 | float v = (float)(j) / (float)(ny); 35 | 36 | Ray r = new Ray(origin, lower_left_corner + u * horizontal + v * vertical); 37 | Vector3 color = RayCast(r); 38 | 39 | ImageHelper.SetPixel(tex, i, j, color); 40 | } 41 | } 42 | 43 | ImageHelper.SaveImg(tex, "Img/chapter3.png"); 44 | } 45 | } -------------------------------------------------------------------------------- /Assets/Script/chapter3.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 376059c3cd5bfa842835bef145fa109e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Script/chapter4.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | 4 | public class Chapter4 5 | { 6 | private static Vector3 topColor = Vector3.one; 7 | private static Vector3 bottomColor = new Vector3(0.5f, 0.7f, 1.0f); 8 | private static Vector3 ballColor = new Vector3(1, 0, 0); 9 | 10 | private static Vector3 center = new Vector3(0, 0, -1); 11 | private static float radius = 0.5f; 12 | 13 | public static bool Hit_sphere(Vector3 center,float radius,Ray ray) 14 | { 15 | Vector3 oc = ray.origin - center; 16 | float a = Vector3.Dot(ray.direction, ray.direction); 17 | float b = 2.0f * Vector3.Dot(oc, ray.direction); 18 | float c = Vector3.Dot(oc, oc) - radius * radius; 19 | float d = b * b - 4 * a * c; 20 | return d > 0; 21 | } 22 | 23 | public static Vector3 RayCast(Ray ray) 24 | { 25 | if (Hit_sphere(center, radius, ray)) 26 | { 27 | return ballColor; 28 | } 29 | Vector3 unit_direction = ray.direction.normalized; 30 | float t = 0.5f * (unit_direction.y + 1.0f); 31 | return Vector3.Lerp(topColor, bottomColor, t); 32 | } 33 | 34 | [MenuItem("Raytracing/Chapter4")] 35 | public static void Main() 36 | { 37 | int nx = 1280; 38 | int ny = 640; 39 | 40 | Vector3 lower_left_corner = new Vector3(-2.0f, -1.0f, -1.0f); 41 | Vector3 horizontal = new Vector3(4.0f, 0.0f, 0.0f); 42 | Vector3 vertical = new Vector3(0.0f, 2.0f, 0.0f); 43 | Vector3 origin = Vector3.zero; 44 | 45 | Texture2D tex = ImageHelper.CreateImg(nx, ny); 46 | for (int j = ny - 1; j >= 0; --j) 47 | { 48 | for (int i = 0; i < nx; ++i) 49 | { 50 | float u = (float)(i) / (float)(nx); 51 | float v = (float)(j) / (float)(ny); 52 | 53 | Ray r = new Ray(origin, lower_left_corner + u * horizontal + v * vertical); 54 | Vector3 color = RayCast(r); 55 | 56 | ImageHelper.SetPixel(tex, i, j, color); 57 | } 58 | } 59 | 60 | ImageHelper.SaveImg(tex, "Img/Chapter4.png"); 61 | } 62 | } -------------------------------------------------------------------------------- /Assets/Script/chapter4.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8dd9565c79ec152418c639944ecb7a68 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Script/chapter5_1.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | 4 | public class Chapter5_1 5 | { 6 | private static Vector3 topColor = Vector3.one; 7 | private static Vector3 bottomColor = new Vector3(0.5f, 0.7f, 1.0f); 8 | private static Vector3 ballColor = new Vector3(1, 0, 0); 9 | 10 | private static Vector3 center = new Vector3(0, 0, -1); 11 | private static float radius = 0.5f; 12 | 13 | public static float Hit_sphere(Vector3 center,float radius,Ray ray) 14 | { 15 | Vector3 oc = ray.origin - center; 16 | float a = Vector3.Dot(ray.direction, ray.direction); 17 | float b = 2.0f * Vector3.Dot(oc, ray.direction); 18 | float c = Vector3.Dot(oc, oc) - radius * radius; 19 | float d = b * b - 4 * a * c; 20 | if (d < 0) 21 | { 22 | return -1; 23 | } 24 | else 25 | { 26 | return (-b - Mathf.Sqrt(d)) / (2 * a); 27 | } 28 | } 29 | 30 | public static Vector3 RayCast(Ray ray) 31 | { 32 | var t = Hit_sphere(center, radius, ray); 33 | if (t > 0) 34 | { 35 | Vector3 N = (ray.GetPoint(t) - new Vector3(0, 0, -1)).normalized; 36 | return 0.5f * (N + Vector3.one); 37 | } 38 | Vector3 unit_direction = ray.direction.normalized; 39 | t = 0.5f * (unit_direction.y + 1.0f); 40 | return Vector3.Lerp(topColor, bottomColor, t); 41 | } 42 | 43 | [MenuItem("Raytracing/Chapter5/1")] 44 | public static void Main() 45 | { 46 | int nx = 1280; 47 | int ny = 640; 48 | 49 | Vector3 lower_left_corner = new Vector3(-2.0f, -1.0f, -1.0f); 50 | Vector3 horizontal = new Vector3(4.0f, 0.0f, 0.0f); 51 | Vector3 vertical = new Vector3(0.0f, 2.0f, 0.0f); 52 | Vector3 origin = Vector3.zero; 53 | 54 | Texture2D tex = ImageHelper.CreateImg(nx, ny); 55 | for (int j = ny - 1; j >= 0; --j) 56 | { 57 | for (int i = 0; i < nx; ++i) 58 | { 59 | float u = (float)(i) / (float)(nx); 60 | float v = (float)(j) / (float)(ny); 61 | 62 | Ray r = new Ray(origin, lower_left_corner + u * horizontal + v * vertical); 63 | Vector3 color = RayCast(r); 64 | 65 | ImageHelper.SetPixel(tex, i, j, color); 66 | } 67 | } 68 | 69 | ImageHelper.SaveImg(tex, "Img/Chapter5_1.png"); 70 | } 71 | } -------------------------------------------------------------------------------- /Assets/Script/chapter5_1.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 04183d323c104144a94ad87ea84ecd80 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Script/chapter5_2.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System.Collections.Generic; 4 | 5 | namespace Chapter5_2 6 | { 7 | public struct Hit_record 8 | { 9 | public float t; 10 | public Vector3 hitpoint; 11 | public Vector3 normal; 12 | }; 13 | 14 | 15 | public interface Hitable 16 | { 17 | bool Hit(Ray r, ref float t_min, ref float t_max, out Hit_record record); 18 | }; 19 | 20 | public class Sphere : Hitable 21 | { 22 | public Vector3 center; 23 | 24 | public float radius; 25 | 26 | public Sphere() 27 | { 28 | center = Vector3.zero; 29 | radius = 1; 30 | } 31 | 32 | public Sphere(Vector3 c, float r) 33 | { 34 | center = c; 35 | radius = r; 36 | } 37 | 38 | public bool Hit(Ray ray, ref float t_min, ref float t_max, out Hit_record record) 39 | { 40 | record = new Hit_record(); 41 | Vector3 oc = ray.origin - center; 42 | float a = Vector3.Dot(ray.direction, ray.direction); 43 | float b = Vector3.Dot(oc, ray.direction); 44 | float c = Vector3.Dot(oc, oc) - radius * radius; 45 | float d = b * b - a * c; 46 | if (d > 0) 47 | { 48 | float temp = (-b - Mathf.Sqrt(d)) / a; 49 | if (temp < t_max && temp > t_min) 50 | { 51 | record.t = temp; 52 | record.hitpoint = ray.GetPoint(temp); 53 | record.normal = (record.hitpoint - center) / radius; 54 | return true; 55 | } 56 | temp = (-b + Mathf.Sqrt(d)) / a; 57 | if (temp < t_max && temp > t_min) 58 | { 59 | record.t = temp; 60 | record.hitpoint = ray.GetPoint(temp); 61 | record.normal = (record.hitpoint - center) / radius; 62 | return true; 63 | } 64 | } 65 | return false; 66 | } 67 | } 68 | 69 | public class HitList : Hitable 70 | { 71 | private List list = new List(); 72 | 73 | public HitList() 74 | { 75 | } 76 | 77 | public int GetCount() 78 | { 79 | return list.Count; 80 | } 81 | 82 | public void Add(Hitable item) 83 | { 84 | list.Add(item); 85 | } 86 | 87 | public bool Hit(Ray r, ref float t_min, ref float t_max, out Hit_record record) 88 | { 89 | Hit_record temp_rec = new Hit_record(); 90 | record = temp_rec; 91 | bool hit_anything = false; 92 | float closest_so_far = t_max; 93 | 94 | for (int i = 0; i < list.Count; ++i) 95 | { 96 | if (list[i].Hit(r, ref t_min, ref closest_so_far, out temp_rec)) 97 | { 98 | hit_anything = true; 99 | closest_so_far = temp_rec.t; 100 | record = temp_rec; 101 | } 102 | } 103 | 104 | return hit_anything; 105 | } 106 | } 107 | 108 | public class Chapter5_2 109 | { 110 | 111 | private static Vector3 topColor = Vector3.one; 112 | private static Vector3 bottomColor = new Vector3(0.5f, 0.7f, 1.0f); 113 | 114 | public static Vector3 RayCast(Ray ray, Hitable world) 115 | { 116 | Hit_record rec; 117 | float min = 0; 118 | float max = float.MaxValue; 119 | if (world.Hit(ray, ref min, ref max, out rec)) 120 | { 121 | return 0.5f * (rec.normal.normalized + Vector3.one); 122 | } 123 | else 124 | { 125 | Vector3 unit_direction = ray.direction.normalized; 126 | float t = 0.5f * (unit_direction.y + 1.0f); 127 | return Vector3.Lerp(topColor, bottomColor, t); 128 | } 129 | } 130 | 131 | [MenuItem("Raytracing/Chapter5/2")] 132 | public static void Main() 133 | { 134 | int nx = 1280; 135 | int ny = 640; 136 | 137 | Vector3 lower_left_corner = new Vector3(-2.0f, -1.0f, -1.0f); 138 | Vector3 horizontal = new Vector3(4.0f, 0.0f, 0.0f); 139 | Vector3 vertical = new Vector3(0.0f, 2.0f, 0.0f); 140 | Vector3 origin = Vector3.zero; 141 | 142 | HitList list = new HitList(); 143 | list.Add(new Sphere(new Vector3(0, 0, -1), 0.5f)); 144 | list.Add(new Sphere(new Vector3(0, -100.5f, -1), 100)); 145 | 146 | 147 | 148 | Texture2D tex = ImageHelper.CreateImg(nx, ny); 149 | for (int j = ny - 1; j >= 0; --j) 150 | { 151 | for (int i = 0; i < nx; ++i) 152 | { 153 | float u = (float)(i) / (float)(nx); 154 | float v = (float)(j) / (float)(ny); 155 | 156 | Ray r = new Ray(origin, lower_left_corner + u * horizontal + v * vertical); 157 | Vector3 color = RayCast(r, list); 158 | 159 | ImageHelper.SetPixel(tex, i, j, color); 160 | } 161 | } 162 | 163 | ImageHelper.SaveImg(tex, "Img/Chapter5_2.png"); 164 | } 165 | } 166 | } -------------------------------------------------------------------------------- /Assets/Script/chapter5_2.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 04dc7bd8d7099e74c90e356da5172646 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Script/chapter6.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System.Collections.Generic; 4 | 5 | namespace Chapter6 6 | { 7 | public struct Hit_record 8 | { 9 | public float t; 10 | public Vector3 hitpoint; 11 | public Vector3 normal; 12 | }; 13 | 14 | 15 | public interface Hitable 16 | { 17 | bool Hit(Ray r, ref float t_min, ref float t_max, out Hit_record record); 18 | }; 19 | 20 | public class Sphere : Hitable 21 | { 22 | public Vector3 center; 23 | 24 | public float radius; 25 | 26 | public Sphere() 27 | { 28 | center = Vector3.zero; 29 | radius = 1; 30 | } 31 | 32 | public Sphere(Vector3 c, float r) 33 | { 34 | center = c; 35 | radius = r; 36 | } 37 | 38 | public bool Hit(Ray ray, ref float t_min, ref float t_max, out Hit_record record) 39 | { 40 | record = new Hit_record(); 41 | Vector3 oc = ray.origin - center; 42 | float a = Vector3.Dot(ray.direction, ray.direction); 43 | float b = Vector3.Dot(oc, ray.direction); 44 | float c = Vector3.Dot(oc, oc) - radius * radius; 45 | float d = b * b - a * c; 46 | if (d > 0) 47 | { 48 | float temp = (-b - Mathf.Sqrt(d)) / a; 49 | if (temp < t_max && temp > t_min) 50 | { 51 | record.t = temp; 52 | record.hitpoint = ray.GetPoint(temp); 53 | record.normal = (record.hitpoint - center) / radius; 54 | return true; 55 | } 56 | temp = (-b + Mathf.Sqrt(d)) / a; 57 | if (temp < t_max && temp > t_min) 58 | { 59 | record.t = temp; 60 | record.hitpoint = ray.GetPoint(temp); 61 | record.normal = (record.hitpoint - center) / radius; 62 | return true; 63 | } 64 | } 65 | return false; 66 | } 67 | } 68 | 69 | public class HitList : Hitable 70 | { 71 | private List list = new List(); 72 | 73 | public HitList() 74 | { 75 | } 76 | 77 | public int GetCount() 78 | { 79 | return list.Count; 80 | } 81 | 82 | public void Add(Hitable item) 83 | { 84 | list.Add(item); 85 | } 86 | 87 | public bool Hit(Ray r, ref float t_min, ref float t_max, out Hit_record record) 88 | { 89 | Hit_record temp_rec = new Hit_record(); 90 | record = temp_rec; 91 | bool hit_anything = false; 92 | float closest_so_far = t_max; 93 | 94 | for (int i = 0; i < list.Count; ++i) 95 | { 96 | if (list[i].Hit(r, ref t_min, ref closest_so_far, out temp_rec)) 97 | { 98 | hit_anything = true; 99 | closest_so_far = temp_rec.t; 100 | record = temp_rec; 101 | } 102 | } 103 | 104 | return hit_anything; 105 | } 106 | } 107 | 108 | public class Chapter6 109 | { 110 | private static Vector3 topColor = Vector3.one; 111 | private static Vector3 bottomColor = new Vector3(0.5f, 0.7f, 1.0f); 112 | 113 | public static Vector3 RayCast(Ray ray, Hitable world) 114 | { 115 | Hit_record rec; 116 | float min = 0; 117 | float max = float.MaxValue; 118 | if (world.Hit(ray, ref min, ref max, out rec)) 119 | { 120 | return 0.5f * (rec.normal.normalized + Vector3.one); 121 | } 122 | else 123 | { 124 | Vector3 unit_direction = ray.direction.normalized; 125 | float t = 0.5f * (unit_direction.y + 1.0f); 126 | return Vector3.Lerp(topColor, bottomColor, t); 127 | } 128 | } 129 | 130 | [MenuItem("Raytracing/Chapter6")] 131 | public static void Main() 132 | { 133 | int nx = 1280; 134 | int ny = 640; 135 | int ns = 64; 136 | 137 | RayCamera camera = new RayCamera(); 138 | 139 | 140 | HitList list = new HitList(); 141 | list.Add(new Sphere(new Vector3(0, 0, -1), 0.5f)); 142 | list.Add(new Sphere(new Vector3(0, -100.5f, -1), 100)); 143 | 144 | Texture2D tex = ImageHelper.CreateImg(nx, ny); 145 | for (int j = ny - 1; j >= 0; --j) 146 | { 147 | for (int i = 0; i < nx; ++i) 148 | { 149 | Vector3 color = Vector3.zero; 150 | for (int k = 0; k < ns; ++k) 151 | { 152 | float u = (float)(i + Random.Range(-1f, 1f)) / (float)(nx); 153 | float v = (float)(j + Random.Range(-1f, 1f)) / (float)(ny); 154 | 155 | Ray r = camera.GetRay(u, v); 156 | color += RayCast(r, list); 157 | } 158 | color = color / (float)(ns); 159 | ImageHelper.SetPixel(tex, i, j, color); 160 | } 161 | } 162 | 163 | ImageHelper.SaveImg(tex, "Img/chapter6.png"); 164 | Debug.Log("Chapter 6 done"); 165 | } 166 | } 167 | } -------------------------------------------------------------------------------- /Assets/Script/chapter6.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6f36962c983f3aa4786c4d8d5349207d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Script/chapter7.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System.Collections.Generic; 4 | 5 | 6 | namespace Chapter7 7 | { 8 | public struct Hit_record 9 | { 10 | public float t; 11 | public Vector3 hitpoint; 12 | public Vector3 normal; 13 | 14 | }; 15 | 16 | 17 | public interface Hitable 18 | { 19 | bool Hit(Ray r, ref float t_min, ref float t_max, out Hit_record record); 20 | }; 21 | 22 | public class HitList : Hitable 23 | { 24 | private List list = new List(); 25 | 26 | public HitList() 27 | { 28 | } 29 | 30 | public int GetCount() 31 | { 32 | return list.Count; 33 | } 34 | 35 | public void Add(Hitable item) 36 | { 37 | list.Add(item); 38 | } 39 | 40 | public bool Hit(Ray r, ref float t_min, ref float t_max, out Hit_record record) 41 | { 42 | Hit_record temp_rec = new Hit_record(); 43 | record = temp_rec; 44 | bool hit_anything = false; 45 | float closest_so_far = t_max; 46 | 47 | for (int i = 0; i < list.Count; ++i) 48 | { 49 | if (list[i].Hit(r, ref t_min, ref closest_so_far, out temp_rec)) 50 | { 51 | hit_anything = true; 52 | closest_so_far = temp_rec.t; 53 | record = temp_rec; 54 | } 55 | } 56 | 57 | return hit_anything; 58 | } 59 | }; 60 | 61 | public class Sphere : Hitable 62 | { 63 | public Vector3 center; 64 | 65 | public float radius; 66 | 67 | 68 | public Sphere() 69 | { 70 | center = Vector3.zero; 71 | radius = 1; 72 | } 73 | 74 | public Sphere(Vector3 c, float r) 75 | { 76 | center = c; 77 | radius = r; 78 | } 79 | 80 | public bool Hit(Ray ray, ref float t_min, ref float t_max, out Hit_record record) 81 | { 82 | record = new Hit_record(); 83 | Vector3 oc = ray.origin - center; 84 | float a = Vector3.Dot(ray.direction, ray.direction); 85 | float b = Vector3.Dot(oc, ray.direction); 86 | float c = Vector3.Dot(oc, oc) - radius * radius; 87 | float d = b * b - a * c; 88 | if (d > 0) 89 | { 90 | float temp = (-b - Mathf.Sqrt(d)) / a; 91 | if (temp < t_max && temp > t_min) 92 | { 93 | record.t = temp; 94 | record.hitpoint = ray.GetPoint(temp); 95 | record.normal = (record.hitpoint - center) / radius; 96 | return true; 97 | } 98 | temp = (-b + Mathf.Sqrt(d)) / a; 99 | if (temp < t_max && temp > t_min) 100 | { 101 | record.t = temp; 102 | record.hitpoint = ray.GetPoint(temp); 103 | record.normal = (record.hitpoint - center) / radius; 104 | return true; 105 | } 106 | } 107 | return false; 108 | } 109 | }; 110 | 111 | 112 | public class Chapter7 113 | { 114 | 115 | private static Vector3 topColor = Vector3.one; 116 | private static Vector3 bottomColor = new Vector3(0.5f, 0.7f, 1.0f); 117 | 118 | public static Vector3 RayCast(Ray ray, Hitable world) 119 | { 120 | Hit_record rec; 121 | float min = 0; 122 | float max = float.MaxValue; 123 | if (world.Hit(ray, ref min, ref max, out rec)) 124 | { 125 | var target = rec.normal.normalized + 126 | new Vector3(Random.Range(-1, 1f), Random.Range(-1f, 1f), Random.Range(-1f, 1f)).normalized; 127 | 128 | return 0.5f * RayCast(new Ray(rec.hitpoint, target), world); 129 | } 130 | else 131 | { 132 | Vector3 unit_direction = ray.direction.normalized; 133 | float t = 0.5f * (unit_direction.y + 1.0f); 134 | return Vector3.Lerp(topColor, bottomColor, t); 135 | } 136 | } 137 | 138 | [MenuItem("Raytracing/Chapter7/1")] 139 | public static void Main() 140 | { 141 | int nx = 1280; 142 | int ny = 640; 143 | int ns = 8; 144 | 145 | RayCamera camera = new RayCamera(); 146 | 147 | HitList list = new HitList(); 148 | list.Add(new Sphere(new Vector3(0, 0, -1), 0.5f)); 149 | list.Add(new Sphere(new Vector3(0, -100.5f, -1), 100)); 150 | 151 | Texture2D tex = ImageHelper.CreateImg(nx, ny); 152 | Texture2D tex2 = ImageHelper.CreateImg(nx, ny); 153 | 154 | for (int j = ny - 1; j >= 0; --j) 155 | { 156 | for (int i = 0; i < nx; ++i) 157 | { 158 | Vector3 color = Vector3.zero; 159 | for (int k = 0; k < ns; ++k) 160 | { 161 | float u = (float)(i + Random.Range(-1f, 1f)) / (float)(nx); 162 | float v = (float)(j + Random.Range(-1f, 1f)) / (float)(ny); 163 | 164 | Ray r = camera.GetRay(u, v); 165 | color += RayCast(r, list); 166 | } 167 | color = color / (float)(ns); 168 | ImageHelper.SetPixel(tex, i, j, color); 169 | color.x = Mathf.Pow(color.x, 1 / 2.2f); 170 | color.y = Mathf.Pow(color.y, 1 / 2.2f); 171 | color.z = Mathf.Pow(color.z, 1 / 2.2f); 172 | ImageHelper.SetPixel(tex2, i, j, color); 173 | } 174 | } 175 | 176 | ImageHelper.SaveImg(tex, "Img/chapter7_1.png"); 177 | ImageHelper.SaveImg(tex2, "Img/chapter7_2.png"); 178 | Debug.Log("Done"); 179 | } 180 | } 181 | } -------------------------------------------------------------------------------- /Assets/Script/chapter7.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b9a540c086581ae4ba67187c506c0a35 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Script/chapter8.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System.Collections.Generic; 4 | 5 | namespace Chapter8 6 | { 7 | public struct Hit_record 8 | { 9 | public float t; 10 | public Vector3 hitpoint; 11 | public Vector3 normal; 12 | public IMaterial mat; 13 | }; 14 | 15 | public interface IMaterial 16 | { 17 | bool Scatter(ref Ray r, ref Hit_record rec, ref Vector3 attenuation, ref Ray scattered); 18 | }; 19 | 20 | 21 | 22 | public interface Hitable 23 | { 24 | bool Hit(Ray r, ref float t_min, ref float t_max, out Hit_record record); 25 | }; 26 | 27 | public class HitList : Hitable 28 | { 29 | private List list = new List(); 30 | 31 | public HitList() 32 | { 33 | } 34 | 35 | public int GetCount() 36 | { 37 | return list.Count; 38 | } 39 | 40 | public void Add(Hitable item) 41 | { 42 | list.Add(item); 43 | } 44 | 45 | public bool Hit(Ray r, ref float t_min, ref float t_max, out Hit_record record) 46 | { 47 | Hit_record temp_rec = new Hit_record(); 48 | record = temp_rec; 49 | bool hit_anything = false; 50 | float closest_so_far = t_max; 51 | 52 | for (int i = 0; i < list.Count; ++i) 53 | { 54 | if (list[i].Hit(r, ref t_min, ref closest_so_far, out temp_rec)) 55 | { 56 | hit_anything = true; 57 | closest_so_far = temp_rec.t; 58 | record = temp_rec; 59 | } 60 | } 61 | 62 | return hit_anything; 63 | } 64 | }; 65 | 66 | 67 | public class Lambertian : IMaterial 68 | { 69 | public Vector3 albedo; 70 | public float reflect; 71 | 72 | public Lambertian(Vector3 a,float r) 73 | { 74 | albedo = a; 75 | reflect = r; 76 | } 77 | 78 | public bool Scatter(ref Ray r, ref Hit_record rec, ref Vector3 attenuation, ref Ray scattered) 79 | { 80 | Vector3 target = rec.normal.normalized + 81 | new Vector3(Random.Range(-1, 1f), Random.Range(-1f, 1f), Random.Range(-1f, 1f)).normalized; 82 | 83 | scattered.origin = rec.hitpoint; 84 | scattered.direction = target; 85 | attenuation = albedo * reflect; 86 | return true; 87 | } 88 | } 89 | 90 | 91 | public class MetalNoFuzz : IMaterial 92 | { 93 | public Vector3 albedo; 94 | 95 | public MetalNoFuzz(Vector3 a) 96 | { 97 | albedo = a; 98 | } 99 | 100 | public bool Scatter(ref Ray r, ref Hit_record rec, ref Vector3 attenuation, ref Ray scattered) 101 | { 102 | Vector3 reflected = Vector3.Reflect(r.direction.normalized, rec.normal.normalized); 103 | 104 | scattered.origin = rec.hitpoint; 105 | scattered.direction = reflected; 106 | attenuation = albedo; 107 | return Vector3.Dot(scattered.direction, rec.normal) > 0; 108 | } 109 | } 110 | 111 | public class Metal : IMaterial 112 | { 113 | public Vector3 albedo; 114 | public float fuzz; 115 | 116 | public Metal(Vector3 a,float f) 117 | { 118 | albedo = a; 119 | fuzz = f; 120 | } 121 | 122 | private Vector3 Random_in_unit_sphere() 123 | { 124 | return new Vector3(Random.Range(-1f, 1f), Random.Range(-1, 1f), Random.Range(-1f, 1f)).normalized; 125 | } 126 | 127 | public bool Scatter(ref Ray r, ref Hit_record rec, ref Vector3 attenuation, ref Ray scattered) 128 | { 129 | Vector3 reflected = Vector3.Reflect(r.direction.normalized, rec.normal.normalized); 130 | reflected = reflected + fuzz * Random_in_unit_sphere(); 131 | 132 | scattered.origin = rec.hitpoint; 133 | scattered.direction = reflected; 134 | attenuation = albedo; 135 | return Vector3.Dot(scattered.direction, rec.normal) > 0; 136 | } 137 | } 138 | 139 | //////////////////////////////////////// 140 | public class Sphere : Hitable 141 | { 142 | public Vector3 center; 143 | 144 | public float radius; 145 | 146 | public IMaterial mat; 147 | 148 | public Sphere() 149 | { 150 | center = Vector3.zero; 151 | radius = 1; 152 | } 153 | 154 | public Sphere(Vector3 c, float r) 155 | { 156 | center = c; 157 | radius = r; 158 | } 159 | 160 | public Sphere(Vector3 c, float r, IMaterial m) 161 | { 162 | center = c; 163 | radius = r; 164 | mat = m; 165 | } 166 | 167 | public bool Hit(Ray ray, ref float t_min, ref float t_max, out Hit_record record) 168 | { 169 | record = new Hit_record(); 170 | Vector3 oc = ray.origin - center; 171 | float a = Vector3.Dot(ray.direction, ray.direction); 172 | float b = Vector3.Dot(oc, ray.direction); 173 | float c = Vector3.Dot(oc, oc) - radius * radius; 174 | float d = b * b - a * c; 175 | if (d > 0) 176 | { 177 | float temp = (-b - Mathf.Sqrt(d)) / a; 178 | if (temp < t_max && temp > t_min) 179 | { 180 | record.t = temp; 181 | record.hitpoint = ray.GetPoint(temp); 182 | record.normal = (record.hitpoint - center) / radius; 183 | record.mat = mat; 184 | return true; 185 | } 186 | temp = (-b + Mathf.Sqrt(d)) / a; 187 | if (temp < t_max && temp > t_min) 188 | { 189 | record.t = temp; 190 | record.hitpoint = ray.GetPoint(temp); 191 | record.normal = (record.hitpoint - center) / radius; 192 | record.mat = mat; 193 | return true; 194 | } 195 | } 196 | return false; 197 | } 198 | }; 199 | 200 | public class Chapter8 201 | { 202 | private static Vector3 topColor = Vector3.one; 203 | private static Vector3 bottomColor = new Vector3(0.5f, 0.8f, 1.0f); 204 | private static int MaxDepth = 50; 205 | 206 | public static Vector3 RayCast(Ray ray, Hitable world, int depth) 207 | { 208 | Hit_record rec; 209 | float min = 0; 210 | float max = float.MaxValue; 211 | if (world.Hit(ray, ref min, ref max, out rec)) 212 | { 213 | Ray scattered = new Ray(); 214 | Vector3 attenuation = Vector3.one; 215 | 216 | if (depth < MaxDepth && rec.mat.Scatter(ref ray, ref rec, ref attenuation, ref scattered)) 217 | { 218 | var color = RayCast(scattered, world, depth + 1); 219 | attenuation.x *= color.x; 220 | attenuation.y *= color.y; 221 | attenuation.z *= color.z; 222 | return attenuation; 223 | } 224 | else 225 | { 226 | return Vector3.zero; 227 | } 228 | } 229 | else 230 | { 231 | Vector3 unit_direction = ray.direction.normalized; 232 | float t = 0.5f * (unit_direction.y + 1.0f); 233 | return Vector3.Lerp(topColor, bottomColor, t); 234 | } 235 | } 236 | 237 | [MenuItem("Raytracing/Chapter8/1")] 238 | public static void MainMetalNoFuzz() 239 | { 240 | int nx = 1280; 241 | int ny = 640; 242 | int ns = 64; 243 | 244 | RayCamera camera = new RayCamera(); 245 | 246 | HitList list = new HitList(); 247 | list.Add(new Sphere(new Vector3(0, 0, -1), 0.5f, new Lambertian(new Vector3(0.8f, 0.3f, 0.3f),0.382f))); 248 | list.Add(new Sphere(new Vector3(0, -100.5f, -1), 100, new Lambertian(new Vector3(0.8f, 0.8f, 0.0f),0.618f))); 249 | list.Add(new Sphere(new Vector3(1, 0, -1), 0.5f, new MetalNoFuzz(new Vector3(0.8f, 0.6f, 0.2f)))); 250 | list.Add(new Sphere(new Vector3(-1, 0, -1), 0.5f, new MetalNoFuzz(new Vector3(0.8f, 0.8f, 0.8f)))); 251 | Texture2D tex = ImageHelper.CreateImg(nx, ny); 252 | 253 | for (int j = ny - 1; j >= 0; --j) 254 | { 255 | for (int i = 0; i < nx; ++i) 256 | { 257 | Vector3 color = Vector3.zero; 258 | for (int k = 0; k < ns; ++k) 259 | { 260 | float u = (float)(i + Random.Range(-1f, 1f)) / (float)(nx); 261 | float v = (float)(j + Random.Range(-1f, 1f)) / (float)(ny); 262 | 263 | Ray r = camera.GetRay(u, v); 264 | color += RayCast(r, list, 0); 265 | } 266 | color = color / (float)(ns); 267 | color.x = Mathf.Sqrt(color.x); 268 | color.y = Mathf.Sqrt(color.y); 269 | color.z = Mathf.Sqrt(color.z); 270 | ImageHelper.SetPixel(tex, i, j, color); 271 | } 272 | } 273 | 274 | ImageHelper.SaveImg(tex, "Img/chapter8_1.png"); 275 | Debug.Log("Chapter 8 is done"); 276 | } 277 | 278 | 279 | [MenuItem("Raytracing/Chapter8/2")] 280 | public static void Main() 281 | { 282 | int nx = 1280; 283 | int ny = 640; 284 | int ns = 64; 285 | 286 | RayCamera camera = new RayCamera(); 287 | 288 | HitList list = new HitList(); 289 | list.Add(new Sphere(new Vector3(0, 0, -1), 0.5f, new Lambertian(new Vector3(0.8f, 0.3f, 0.3f), 0.382f))); 290 | list.Add(new Sphere(new Vector3(0, -100.5f, -1), 100, new Lambertian(new Vector3(0.8f, 0.8f, 0.0f), 0.618f))); 291 | list.Add(new Sphere(new Vector3(1, 0, -1), 0.5f, new Metal(new Vector3(0.8f, 0.6f, 0.2f),0.3f))); 292 | list.Add(new Sphere(new Vector3(-1, 0, -1), 0.5f, new Metal(new Vector3(0.8f, 0.8f, 0.8f),1.0f))); 293 | Texture2D tex = ImageHelper.CreateImg(nx, ny); 294 | 295 | for (int j = ny - 1; j >= 0; --j) 296 | { 297 | for (int i = 0; i < nx; ++i) 298 | { 299 | Vector3 color = Vector3.zero; 300 | for (int k = 0; k < ns; ++k) 301 | { 302 | float u = (float)(i + Random.Range(-1f, 1f)) / (float)(nx); 303 | float v = (float)(j + Random.Range(-1f, 1f)) / (float)(ny); 304 | 305 | Ray r = camera.GetRay(u, v); 306 | color += RayCast(r, list, 0); 307 | } 308 | color = color / (float)(ns); 309 | color.x = Mathf.Sqrt(color.x); 310 | color.y = Mathf.Sqrt(color.y); 311 | color.z = Mathf.Sqrt(color.z); 312 | ImageHelper.SetPixel(tex, i, j, color); 313 | } 314 | } 315 | 316 | ImageHelper.SaveImg(tex, "Img/chapter8fuzz2.png"); 317 | Debug.Log("Chapter 8 fuzz is done"); 318 | } 319 | } 320 | } -------------------------------------------------------------------------------- /Assets/Script/chapter8.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 05f8d20d31f80404a97a14263c36fe81 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Script/chapter9.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System.Collections.Generic; 4 | 5 | namespace Chapter9 6 | { 7 | public struct Hit_record 8 | { 9 | public float t; 10 | public Vector3 hitpoint; 11 | public Vector3 normal; 12 | public IMaterial mat; 13 | }; 14 | 15 | public interface IMaterial 16 | { 17 | bool Scatter(ref Ray r, ref Hit_record rec, ref Vector3 attenuation, ref Ray scattered); 18 | }; 19 | 20 | 21 | 22 | public interface Hitable 23 | { 24 | bool Hit(Ray r, ref float t_min, ref float t_max, out Hit_record record); 25 | }; 26 | 27 | public class HitList : Hitable 28 | { 29 | private List list = new List(); 30 | 31 | public HitList() 32 | { 33 | } 34 | 35 | public int GetCount() 36 | { 37 | return list.Count; 38 | } 39 | 40 | public void Add(Hitable item) 41 | { 42 | list.Add(item); 43 | } 44 | 45 | public bool Hit(Ray r, ref float t_min, ref float t_max, out Hit_record record) 46 | { 47 | Hit_record temp_rec = new Hit_record(); 48 | record = temp_rec; 49 | bool hit_anything = false; 50 | float closest_so_far = t_max; 51 | 52 | for (int i = 0; i < list.Count; ++i) 53 | { 54 | if (list[i].Hit(r, ref t_min, ref closest_so_far, out temp_rec)) 55 | { 56 | hit_anything = true; 57 | closest_so_far = temp_rec.t; 58 | record = temp_rec; 59 | } 60 | } 61 | 62 | return hit_anything; 63 | } 64 | }; 65 | 66 | 67 | public class Lambertian : IMaterial 68 | { 69 | public Vector3 albedo; 70 | 71 | public Lambertian(Vector3 a) 72 | { 73 | albedo = a; 74 | } 75 | 76 | public bool Scatter(ref Ray r, ref Hit_record rec, ref Vector3 attenuation, ref Ray scattered) 77 | { 78 | Vector3 target = rec.normal.normalized * 0.5f + 79 | new Vector3(Random.Range(-1, 1f), Random.Range(-1f, 1f), Random.Range(-1f, 1f)).normalized; 80 | 81 | scattered.origin = rec.hitpoint; 82 | scattered.direction = target; 83 | attenuation = albedo; 84 | return true; 85 | } 86 | } 87 | 88 | 89 | public class MetalNoFuzz : IMaterial 90 | { 91 | public Vector3 albedo; 92 | 93 | public MetalNoFuzz(Vector3 a) 94 | { 95 | albedo = a; 96 | } 97 | 98 | public bool Scatter(ref Ray r, ref Hit_record rec, ref Vector3 attenuation, ref Ray scattered) 99 | { 100 | Vector3 reflected = Vector3.Reflect(r.direction.normalized, rec.normal.normalized); 101 | 102 | scattered.origin = rec.hitpoint; 103 | scattered.direction = reflected; 104 | attenuation = albedo; 105 | return Vector3.Dot(scattered.direction, rec.normal) > 0; 106 | } 107 | } 108 | 109 | public class Metal : IMaterial 110 | { 111 | public Vector3 albedo; 112 | public float fuzz; 113 | 114 | public Metal(Vector3 a,float f) 115 | { 116 | albedo = a; 117 | fuzz = f; 118 | } 119 | 120 | private Vector3 Random_in_unit_sphere() 121 | { 122 | return new Vector3(Random.Range(-1f, 1f), Random.Range(-1, 1f), Random.Range(-1f, 1f)).normalized; 123 | } 124 | 125 | public bool Scatter(ref Ray r, ref Hit_record rec, ref Vector3 attenuation, ref Ray scattered) 126 | { 127 | Vector3 reflected = Vector3.Reflect(r.direction.normalized, rec.normal.normalized); 128 | reflected = reflected + fuzz * Random_in_unit_sphere(); 129 | 130 | scattered.origin = rec.hitpoint; 131 | scattered.direction = reflected; 132 | attenuation = albedo; 133 | return Vector3.Dot(scattered.direction, rec.normal) > 0; 134 | } 135 | } 136 | 137 | public class Dielectric : IMaterial 138 | { 139 | public float ref_idx; 140 | 141 | public Dielectric(float r) 142 | { 143 | ref_idx = r; 144 | } 145 | 146 | private bool Refract(Vector3 v, Vector3 n, float ni_over_nt,out Vector3 refracted) 147 | { 148 | 149 | v.Normalize(); 150 | n.Normalize(); 151 | float dt = Vector3.Dot(-v.normalized, n.normalized); 152 | float discriminant = 1.0f - ni_over_nt * ni_over_nt * (1.0f - dt * dt); 153 | if (discriminant > 0) 154 | { 155 | refracted = ni_over_nt * (v.normalized + n * dt) - n * Mathf.Sqrt(discriminant); 156 | return true; 157 | } 158 | refracted = Vector3.one; 159 | return false; 160 | } 161 | 162 | public bool Scatter(ref Ray r, ref Hit_record rec, ref Vector3 attenuation, ref Ray scattered) 163 | { 164 | Vector3 outward_normal = Vector3.zero; 165 | Vector3 reflected = Vector3.Reflect(r.direction.normalized, rec.normal.normalized); 166 | float ni_over_nt = 0f; 167 | attenuation.x = 1.0f; 168 | attenuation.y = 1.0f; 169 | attenuation.z = 1.0f; 170 | Vector3 refracted; 171 | if (Vector3.Dot(r.direction,rec.normal) > 0) 172 | { 173 | outward_normal = -rec.normal; 174 | ni_over_nt = ref_idx; 175 | } 176 | else 177 | { 178 | outward_normal = rec.normal; 179 | ni_over_nt = 1.0f / ref_idx; 180 | } 181 | 182 | if (Refract(r.direction,outward_normal,ni_over_nt,out refracted)) 183 | { 184 | scattered.origin = rec.hitpoint; 185 | scattered.direction = refracted; 186 | return true; 187 | } 188 | else 189 | { 190 | scattered.origin = rec.hitpoint; 191 | scattered.direction = reflected; 192 | return false; 193 | } 194 | } 195 | } 196 | 197 | public class DielectricShlick : IMaterial 198 | { 199 | public float ref_idx; 200 | 201 | public DielectricShlick(float r) 202 | { 203 | ref_idx = r; 204 | } 205 | 206 | private bool Refract(Vector3 v, Vector3 n, float ni_over_nt, out Vector3 refracted) 207 | { 208 | 209 | v.Normalize(); 210 | n.Normalize(); 211 | float dt = Vector3.Dot(-v.normalized, n.normalized); 212 | float discriminant = 1.0f - ni_over_nt * ni_over_nt * (1.0f - dt * dt); 213 | if (discriminant > 0) 214 | { 215 | refracted = ni_over_nt * (v.normalized + n * dt) - n * Mathf.Sqrt(discriminant); 216 | return true; 217 | } 218 | refracted = Vector3.one; 219 | return false; 220 | } 221 | 222 | private float Schlick(float cosine,float ref_idx) 223 | { 224 | float r0 = (1.0f - ref_idx) / (1 + ref_idx); 225 | r0 *= r0; 226 | return r0 + (1 - r0) * Mathf.Pow((1 - cosine), 5); 227 | } 228 | 229 | public bool Scatter(ref Ray r, ref Hit_record rec, ref Vector3 attenuation, ref Ray scattered) 230 | { 231 | Vector3 outward_normal = Vector3.zero; 232 | Vector3 reflected = Vector3.Reflect(r.direction.normalized, rec.normal.normalized); 233 | float ni_over_nt = 0f; 234 | attenuation.x = 1.0f; 235 | attenuation.y = 1.0f; 236 | attenuation.z = 1.0f; 237 | Vector3 refracted; 238 | float reflect_prob; 239 | float cosine; 240 | if (Vector3.Dot(r.direction, rec.normal) > 0) 241 | { 242 | outward_normal = -rec.normal; 243 | ni_over_nt = ref_idx; 244 | cosine = ref_idx * Vector3.Dot(r.direction, rec.normal) / r.direction.magnitude; 245 | } 246 | else 247 | { 248 | outward_normal = rec.normal; 249 | ni_over_nt = 1.0f / ref_idx; 250 | cosine = -Vector3.Dot(r.direction.normalized, rec.normal) / r.direction.magnitude; 251 | } 252 | 253 | var bRefracted = Refract(r.direction, outward_normal, ni_over_nt, out refracted); 254 | if (bRefracted) 255 | { 256 | reflect_prob = Schlick(cosine, ref_idx); 257 | } 258 | else 259 | { 260 | scattered.origin = rec.hitpoint; 261 | scattered.direction = reflected; 262 | reflect_prob = 1.0f; 263 | } 264 | if (Random.Range(0, 1) < reflect_prob) 265 | { 266 | scattered.origin = rec.hitpoint; 267 | scattered.direction = reflected; 268 | } 269 | else 270 | { 271 | scattered.origin = rec.hitpoint; 272 | scattered.direction = refracted; 273 | } 274 | return true; 275 | } 276 | } 277 | 278 | //////////////////////////////////////// 279 | public class Sphere : Hitable 280 | { 281 | public Vector3 center; 282 | 283 | public float radius; 284 | 285 | public IMaterial mat; 286 | 287 | public Sphere() 288 | { 289 | center = Vector3.zero; 290 | radius = 1; 291 | } 292 | 293 | public Sphere(Vector3 c, float r) 294 | { 295 | center = c; 296 | radius = r; 297 | } 298 | 299 | public Sphere(Vector3 c, float r, IMaterial m) 300 | { 301 | center = c; 302 | radius = r; 303 | mat = m; 304 | } 305 | 306 | public bool Hit(Ray ray, ref float t_min, ref float t_max, out Hit_record record) 307 | { 308 | record = new Hit_record(); 309 | Vector3 oc = ray.origin - center; 310 | float a = Vector3.Dot(ray.direction, ray.direction); 311 | float b = Vector3.Dot(oc, ray.direction); 312 | float c = Vector3.Dot(oc, oc) - radius * radius; 313 | float d = b * b - a * c; 314 | if (d > 0) 315 | { 316 | float temp = (-b - Mathf.Sqrt(d)) / a; 317 | if (temp < t_max && temp > t_min) 318 | { 319 | record.t = temp; 320 | record.hitpoint = ray.GetPoint(temp); 321 | record.normal = (record.hitpoint - center) / radius; 322 | record.mat = mat; 323 | return true; 324 | } 325 | temp = (-b + Mathf.Sqrt(d)) / a; 326 | if (temp < t_max && temp > t_min) 327 | { 328 | record.t = temp; 329 | record.hitpoint = ray.GetPoint(temp); 330 | record.normal = (record.hitpoint - center) / radius; 331 | record.mat = mat; 332 | return true; 333 | } 334 | } 335 | return false; 336 | } 337 | }; 338 | 339 | public class Chapter9 340 | { 341 | private static Vector3 topColor = Vector3.one; 342 | private static Vector3 bottomColor = new Vector3(0.5f, 0.9f, 1.0f); 343 | 344 | public static Vector3 RayCast(Ray ray, Hitable world, int depth) 345 | { 346 | Hit_record rec; 347 | float min = 0; 348 | float max = float.MaxValue; 349 | if (world.Hit(ray, ref min, ref max, out rec)) 350 | { 351 | Ray scattered = new Ray(); 352 | Vector3 attenuation = Vector3.one; 353 | 354 | if (depth < 50 && rec.mat.Scatter(ref ray, ref rec, ref attenuation, ref scattered)) 355 | { 356 | var color = RayCast(scattered, world, depth + 1); 357 | attenuation.x *= color.x; 358 | attenuation.y *= color.y; 359 | attenuation.z *= color.z; 360 | return attenuation; 361 | } 362 | else 363 | { 364 | return Vector3.zero; 365 | } 366 | } 367 | else 368 | { 369 | Vector3 unit_direction = ray.direction.normalized; 370 | float t = 0.5f * (unit_direction.y + 1.0f); 371 | return Vector3.Lerp(topColor, bottomColor, t); 372 | } 373 | } 374 | 375 | [MenuItem("Raytracing/Chapter9/1")] 376 | public static void Main() 377 | { 378 | int nx = 1280; 379 | int ny = 640; 380 | int ns = 128; 381 | 382 | RayCamera camera = new RayCamera(); 383 | 384 | HitList list = new HitList(); 385 | list.Add(new Sphere(new Vector3(0, 0, -1), 0.5f, new Lambertian(new Vector3(0.1f, 0.2f, 0.5f)))); 386 | list.Add(new Sphere(new Vector3(0, -100.5f, -1), 100, new Lambertian(new Vector3(0.8f, 0.8f, 0.0f)))); 387 | list.Add(new Sphere(new Vector3(1, 0, -1), 0.5f, new Metal(new Vector3(0.8f, 0.6f, 0.2f),0.3f))); 388 | list.Add(new Sphere(new Vector3(-1, 0, -1), 0.5f, new Dielectric(1.5f))); 389 | Texture2D tex = ImageHelper.CreateImg(nx, ny); 390 | 391 | for (int j = ny - 1; j >= 0; --j) 392 | { 393 | for (int i = 0; i < nx; ++i) 394 | { 395 | Vector3 color = Vector3.zero; 396 | for (int k = 0; k < ns; ++k) 397 | { 398 | float u = (float)(i + Random.Range(-1f, 1f)) / (float)(nx); 399 | float v = (float)(j + Random.Range(-1f, 1f)) / (float)(ny); 400 | 401 | Ray r = camera.GetRay(u, v); 402 | color += RayCast(r, list, 0); 403 | } 404 | color = color / (float)(ns); 405 | color.x = Mathf.Sqrt(color.x); 406 | color.y = Mathf.Sqrt(color.y); 407 | color.z = Mathf.Sqrt(color.z); 408 | ImageHelper.SetPixel(tex, i, j, color); 409 | } 410 | } 411 | 412 | ImageHelper.SaveImg(tex, "Img/chapter9_1my.png"); 413 | Debug.Log("Chapter 9_1 done"); 414 | } 415 | 416 | 417 | [MenuItem("Raytracing/Chapter9/2")] 418 | public static void Main2() 419 | { 420 | int nx = 1280; 421 | int ny = 640; 422 | int ns = 64; 423 | 424 | RayCamera camera = new RayCamera(); 425 | 426 | HitList list = new HitList(); 427 | list.Add(new Sphere(new Vector3(0, 0, -1), 0.5f, new Lambertian(new Vector3(0.1f, 0.2f, 0.5f)))); 428 | list.Add(new Sphere(new Vector3(0, -100.5f, -1), 100, new Lambertian(new Vector3(0.8f, 0.8f, 0.0f)))); 429 | list.Add(new Sphere(new Vector3(1, 0, -1), 0.5f, new Metal(new Vector3(0.8f, 0.6f, 0.2f), 0.3f))); 430 | list.Add(new Sphere(new Vector3(-1, 0, -1), 0.5f, new DielectricShlick(1.5f))); 431 | list.Add(new Sphere(new Vector3(-1, 0, -1), 0.45f, new DielectricShlick(1.5f))); 432 | Texture2D tex = ImageHelper.CreateImg(nx, ny); 433 | 434 | for (int j = ny - 1; j >= 0; --j) 435 | { 436 | for (int i = 0; i < nx; ++i) 437 | { 438 | Vector3 color = Vector3.zero; 439 | for (int k = 0; k < ns; ++k) 440 | { 441 | float u = (float)(i + Random.Range(0f, 1f)) / (float)(nx); 442 | float v = (float)(j + Random.Range(0f, 1f)) / (float)(ny); 443 | 444 | Ray r = camera.GetRay(u, v); 445 | color += RayCast(r, list, 0); 446 | } 447 | color = color / (float)(ns); 448 | color.x = Mathf.Sqrt(color.x); 449 | color.y = Mathf.Sqrt(color.y); 450 | color.z = Mathf.Sqrt(color.z); 451 | ImageHelper.SetPixel(tex, i, j, color); 452 | } 453 | } 454 | 455 | ImageHelper.SaveImg(tex, "Img/chapter9_2.png"); 456 | Debug.Log("Chapter 9_2 done"); 457 | } 458 | 459 | } 460 | } -------------------------------------------------------------------------------- /Assets/Script/chapter9.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 543c26f9df94241408f3c7e76d037f3e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/figure.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2d23a3c6c4408744c9437df45b778094 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/figure/chapter3-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyonggit/RayTracingInOneWeekend_CSharp/31372c481f9e4d45e8ba30ebcb78548bd00ed8b8/Assets/figure/chapter3-1.png -------------------------------------------------------------------------------- /Assets/figure/chapter3-1.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2aef2463b8e32284cbc44ed12883b3db 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | externalObjects: {} 6 | serializedVersion: 9 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 1 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | isReadable: 0 24 | streamingMipmaps: 0 25 | streamingMipmapsPriority: 0 26 | grayScaleToAlpha: 0 27 | generateCubemap: 6 28 | cubemapConvolution: 0 29 | seamlessCubemap: 0 30 | textureFormat: 1 31 | maxTextureSize: 2048 32 | textureSettings: 33 | serializedVersion: 2 34 | filterMode: -1 35 | aniso: -1 36 | mipBias: -100 37 | wrapU: -1 38 | wrapV: -1 39 | wrapW: -1 40 | nPOTScale: 1 41 | lightmap: 0 42 | compressionQuality: 50 43 | spriteMode: 0 44 | spriteExtrude: 1 45 | spriteMeshType: 1 46 | alignment: 0 47 | spritePivot: {x: 0.5, y: 0.5} 48 | spritePixelsToUnits: 100 49 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 50 | spriteGenerateFallbackPhysicsShape: 1 51 | alphaUsage: 1 52 | alphaIsTransparency: 0 53 | spriteTessellationDetail: -1 54 | textureType: 0 55 | textureShape: 1 56 | singleChannelComponent: 0 57 | maxTextureSizeSet: 0 58 | compressionQualitySet: 0 59 | textureFormatSet: 0 60 | platformSettings: 61 | - serializedVersion: 2 62 | buildTarget: DefaultTexturePlatform 63 | maxTextureSize: 2048 64 | resizeAlgorithm: 0 65 | textureFormat: -1 66 | textureCompression: 1 67 | compressionQuality: 50 68 | crunchedCompression: 0 69 | allowsAlphaSplitting: 0 70 | overridden: 0 71 | androidETC2FallbackOverride: 0 72 | spriteSheet: 73 | serializedVersion: 2 74 | sprites: [] 75 | outline: [] 76 | physicsShape: [] 77 | bones: [] 78 | spriteID: 79 | vertices: [] 80 | indices: 81 | edges: [] 82 | weights: [] 83 | spritePackingTag: 84 | pSDRemoveMatte: 0 85 | pSDShowRemoveMatteOption: 0 86 | userData: 87 | assetBundleName: 88 | assetBundleVariant: 89 | -------------------------------------------------------------------------------- /Assets/figure/chapter3-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyonggit/RayTracingInOneWeekend_CSharp/31372c481f9e4d45e8ba30ebcb78548bd00ed8b8/Assets/figure/chapter3-2.png -------------------------------------------------------------------------------- /Assets/figure/chapter3-2.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 944555791159e834f89dab753242cc54 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | externalObjects: {} 6 | serializedVersion: 9 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 1 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | isReadable: 0 24 | streamingMipmaps: 0 25 | streamingMipmapsPriority: 0 26 | grayScaleToAlpha: 0 27 | generateCubemap: 6 28 | cubemapConvolution: 0 29 | seamlessCubemap: 0 30 | textureFormat: 1 31 | maxTextureSize: 2048 32 | textureSettings: 33 | serializedVersion: 2 34 | filterMode: -1 35 | aniso: -1 36 | mipBias: -100 37 | wrapU: -1 38 | wrapV: -1 39 | wrapW: -1 40 | nPOTScale: 1 41 | lightmap: 0 42 | compressionQuality: 50 43 | spriteMode: 0 44 | spriteExtrude: 1 45 | spriteMeshType: 1 46 | alignment: 0 47 | spritePivot: {x: 0.5, y: 0.5} 48 | spritePixelsToUnits: 100 49 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 50 | spriteGenerateFallbackPhysicsShape: 1 51 | alphaUsage: 1 52 | alphaIsTransparency: 0 53 | spriteTessellationDetail: -1 54 | textureType: 0 55 | textureShape: 1 56 | singleChannelComponent: 0 57 | maxTextureSizeSet: 0 58 | compressionQualitySet: 0 59 | textureFormatSet: 0 60 | platformSettings: 61 | - serializedVersion: 2 62 | buildTarget: DefaultTexturePlatform 63 | maxTextureSize: 2048 64 | resizeAlgorithm: 0 65 | textureFormat: -1 66 | textureCompression: 1 67 | compressionQuality: 50 68 | crunchedCompression: 0 69 | allowsAlphaSplitting: 0 70 | overridden: 0 71 | androidETC2FallbackOverride: 0 72 | spriteSheet: 73 | serializedVersion: 2 74 | sprites: [] 75 | outline: [] 76 | physicsShape: [] 77 | bones: [] 78 | spriteID: 79 | vertices: [] 80 | indices: 81 | edges: [] 82 | weights: [] 83 | spritePackingTag: 84 | pSDRemoveMatte: 0 85 | pSDShowRemoveMatteOption: 0 86 | userData: 87 | assetBundleName: 88 | assetBundleVariant: 89 | -------------------------------------------------------------------------------- /Assets/figure/chapter3-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyonggit/RayTracingInOneWeekend_CSharp/31372c481f9e4d45e8ba30ebcb78548bd00ed8b8/Assets/figure/chapter3-3.png -------------------------------------------------------------------------------- /Assets/figure/chapter3-3.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3d752f7a9d3bc6741b104d3d8da6c55b 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | externalObjects: {} 6 | serializedVersion: 9 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 1 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | isReadable: 0 24 | streamingMipmaps: 0 25 | streamingMipmapsPriority: 0 26 | grayScaleToAlpha: 0 27 | generateCubemap: 6 28 | cubemapConvolution: 0 29 | seamlessCubemap: 0 30 | textureFormat: 1 31 | maxTextureSize: 2048 32 | textureSettings: 33 | serializedVersion: 2 34 | filterMode: -1 35 | aniso: -1 36 | mipBias: -100 37 | wrapU: -1 38 | wrapV: -1 39 | wrapW: -1 40 | nPOTScale: 1 41 | lightmap: 0 42 | compressionQuality: 50 43 | spriteMode: 0 44 | spriteExtrude: 1 45 | spriteMeshType: 1 46 | alignment: 0 47 | spritePivot: {x: 0.5, y: 0.5} 48 | spritePixelsToUnits: 100 49 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 50 | spriteGenerateFallbackPhysicsShape: 1 51 | alphaUsage: 1 52 | alphaIsTransparency: 0 53 | spriteTessellationDetail: -1 54 | textureType: 0 55 | textureShape: 1 56 | singleChannelComponent: 0 57 | maxTextureSizeSet: 0 58 | compressionQualitySet: 0 59 | textureFormatSet: 0 60 | platformSettings: 61 | - serializedVersion: 2 62 | buildTarget: DefaultTexturePlatform 63 | maxTextureSize: 2048 64 | resizeAlgorithm: 0 65 | textureFormat: -1 66 | textureCompression: 1 67 | compressionQuality: 50 68 | crunchedCompression: 0 69 | allowsAlphaSplitting: 0 70 | overridden: 0 71 | androidETC2FallbackOverride: 0 72 | spriteSheet: 73 | serializedVersion: 2 74 | sprites: [] 75 | outline: [] 76 | physicsShape: [] 77 | bones: [] 78 | spriteID: 79 | vertices: [] 80 | indices: 81 | edges: [] 82 | weights: [] 83 | spritePackingTag: 84 | pSDRemoveMatte: 0 85 | pSDShowRemoveMatteOption: 0 86 | userData: 87 | assetBundleName: 88 | assetBundleVariant: 89 | -------------------------------------------------------------------------------- /Assets/figure/chapter4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyonggit/RayTracingInOneWeekend_CSharp/31372c481f9e4d45e8ba30ebcb78548bd00ed8b8/Assets/figure/chapter4-1.png -------------------------------------------------------------------------------- /Assets/figure/chapter4-1.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1333238f48e961849bcf399102383b5d 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | externalObjects: {} 6 | serializedVersion: 9 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 1 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | isReadable: 0 24 | streamingMipmaps: 0 25 | streamingMipmapsPriority: 0 26 | grayScaleToAlpha: 0 27 | generateCubemap: 6 28 | cubemapConvolution: 0 29 | seamlessCubemap: 0 30 | textureFormat: 1 31 | maxTextureSize: 2048 32 | textureSettings: 33 | serializedVersion: 2 34 | filterMode: -1 35 | aniso: -1 36 | mipBias: -100 37 | wrapU: -1 38 | wrapV: -1 39 | wrapW: -1 40 | nPOTScale: 1 41 | lightmap: 0 42 | compressionQuality: 50 43 | spriteMode: 0 44 | spriteExtrude: 1 45 | spriteMeshType: 1 46 | alignment: 0 47 | spritePivot: {x: 0.5, y: 0.5} 48 | spritePixelsToUnits: 100 49 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 50 | spriteGenerateFallbackPhysicsShape: 1 51 | alphaUsage: 1 52 | alphaIsTransparency: 0 53 | spriteTessellationDetail: -1 54 | textureType: 0 55 | textureShape: 1 56 | singleChannelComponent: 0 57 | maxTextureSizeSet: 0 58 | compressionQualitySet: 0 59 | textureFormatSet: 0 60 | platformSettings: 61 | - serializedVersion: 2 62 | buildTarget: DefaultTexturePlatform 63 | maxTextureSize: 2048 64 | resizeAlgorithm: 0 65 | textureFormat: -1 66 | textureCompression: 1 67 | compressionQuality: 50 68 | crunchedCompression: 0 69 | allowsAlphaSplitting: 0 70 | overridden: 0 71 | androidETC2FallbackOverride: 0 72 | spriteSheet: 73 | serializedVersion: 2 74 | sprites: [] 75 | outline: [] 76 | physicsShape: [] 77 | bones: [] 78 | spriteID: 79 | vertices: [] 80 | indices: 81 | edges: [] 82 | weights: [] 83 | spritePackingTag: 84 | pSDRemoveMatte: 0 85 | pSDShowRemoveMatteOption: 0 86 | userData: 87 | assetBundleName: 88 | assetBundleVariant: 89 | -------------------------------------------------------------------------------- /Assets/figure/figure10-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyonggit/RayTracingInOneWeekend_CSharp/31372c481f9e4d45e8ba30ebcb78548bd00ed8b8/Assets/figure/figure10-1.png -------------------------------------------------------------------------------- /Assets/figure/figure10-1.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 731672a96b80e164bbba5991efa36bda 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | externalObjects: {} 6 | serializedVersion: 9 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 1 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | isReadable: 0 24 | streamingMipmaps: 0 25 | streamingMipmapsPriority: 0 26 | grayScaleToAlpha: 0 27 | generateCubemap: 6 28 | cubemapConvolution: 0 29 | seamlessCubemap: 0 30 | textureFormat: 1 31 | maxTextureSize: 2048 32 | textureSettings: 33 | serializedVersion: 2 34 | filterMode: -1 35 | aniso: -1 36 | mipBias: -100 37 | wrapU: -1 38 | wrapV: -1 39 | wrapW: -1 40 | nPOTScale: 1 41 | lightmap: 0 42 | compressionQuality: 50 43 | spriteMode: 0 44 | spriteExtrude: 1 45 | spriteMeshType: 1 46 | alignment: 0 47 | spritePivot: {x: 0.5, y: 0.5} 48 | spritePixelsToUnits: 100 49 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 50 | spriteGenerateFallbackPhysicsShape: 1 51 | alphaUsage: 1 52 | alphaIsTransparency: 0 53 | spriteTessellationDetail: -1 54 | textureType: 0 55 | textureShape: 1 56 | singleChannelComponent: 0 57 | maxTextureSizeSet: 0 58 | compressionQualitySet: 0 59 | textureFormatSet: 0 60 | platformSettings: 61 | - serializedVersion: 2 62 | buildTarget: DefaultTexturePlatform 63 | maxTextureSize: 2048 64 | resizeAlgorithm: 0 65 | textureFormat: -1 66 | textureCompression: 1 67 | compressionQuality: 50 68 | crunchedCompression: 0 69 | allowsAlphaSplitting: 0 70 | overridden: 0 71 | androidETC2FallbackOverride: 0 72 | spriteSheet: 73 | serializedVersion: 2 74 | sprites: [] 75 | outline: [] 76 | physicsShape: [] 77 | bones: [] 78 | spriteID: 79 | vertices: [] 80 | indices: 81 | edges: [] 82 | weights: [] 83 | spritePackingTag: 84 | pSDRemoveMatte: 0 85 | pSDShowRemoveMatteOption: 0 86 | userData: 87 | assetBundleName: 88 | assetBundleVariant: 89 | -------------------------------------------------------------------------------- /Assets/figure/figure10-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyonggit/RayTracingInOneWeekend_CSharp/31372c481f9e4d45e8ba30ebcb78548bd00ed8b8/Assets/figure/figure10-2.png -------------------------------------------------------------------------------- /Assets/figure/figure10-2.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 23ed82ba1c52ed24db289d0cf2484ac4 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | externalObjects: {} 6 | serializedVersion: 9 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 1 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | isReadable: 0 24 | streamingMipmaps: 0 25 | streamingMipmapsPriority: 0 26 | grayScaleToAlpha: 0 27 | generateCubemap: 6 28 | cubemapConvolution: 0 29 | seamlessCubemap: 0 30 | textureFormat: 1 31 | maxTextureSize: 2048 32 | textureSettings: 33 | serializedVersion: 2 34 | filterMode: -1 35 | aniso: -1 36 | mipBias: -100 37 | wrapU: -1 38 | wrapV: -1 39 | wrapW: -1 40 | nPOTScale: 1 41 | lightmap: 0 42 | compressionQuality: 50 43 | spriteMode: 0 44 | spriteExtrude: 1 45 | spriteMeshType: 1 46 | alignment: 0 47 | spritePivot: {x: 0.5, y: 0.5} 48 | spritePixelsToUnits: 100 49 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 50 | spriteGenerateFallbackPhysicsShape: 1 51 | alphaUsage: 1 52 | alphaIsTransparency: 0 53 | spriteTessellationDetail: -1 54 | textureType: 0 55 | textureShape: 1 56 | singleChannelComponent: 0 57 | maxTextureSizeSet: 0 58 | compressionQualitySet: 0 59 | textureFormatSet: 0 60 | platformSettings: 61 | - serializedVersion: 2 62 | buildTarget: DefaultTexturePlatform 63 | maxTextureSize: 2048 64 | resizeAlgorithm: 0 65 | textureFormat: -1 66 | textureCompression: 1 67 | compressionQuality: 50 68 | crunchedCompression: 0 69 | allowsAlphaSplitting: 0 70 | overridden: 0 71 | androidETC2FallbackOverride: 0 72 | spriteSheet: 73 | serializedVersion: 2 74 | sprites: [] 75 | outline: [] 76 | physicsShape: [] 77 | bones: [] 78 | spriteID: 79 | vertices: [] 80 | indices: 81 | edges: [] 82 | weights: [] 83 | spritePackingTag: 84 | pSDRemoveMatte: 0 85 | pSDShowRemoveMatteOption: 0 86 | userData: 87 | assetBundleName: 88 | assetBundleVariant: 89 | -------------------------------------------------------------------------------- /Assets/figure/figure10-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyonggit/RayTracingInOneWeekend_CSharp/31372c481f9e4d45e8ba30ebcb78548bd00ed8b8/Assets/figure/figure10-3.png -------------------------------------------------------------------------------- /Assets/figure/figure10-3.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b4cc756a8b776ab4a8a0d9c5b98b7bd4 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | externalObjects: {} 6 | serializedVersion: 9 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 1 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | isReadable: 0 24 | streamingMipmaps: 0 25 | streamingMipmapsPriority: 0 26 | grayScaleToAlpha: 0 27 | generateCubemap: 6 28 | cubemapConvolution: 0 29 | seamlessCubemap: 0 30 | textureFormat: 1 31 | maxTextureSize: 2048 32 | textureSettings: 33 | serializedVersion: 2 34 | filterMode: -1 35 | aniso: -1 36 | mipBias: -100 37 | wrapU: -1 38 | wrapV: -1 39 | wrapW: -1 40 | nPOTScale: 1 41 | lightmap: 0 42 | compressionQuality: 50 43 | spriteMode: 0 44 | spriteExtrude: 1 45 | spriteMeshType: 1 46 | alignment: 0 47 | spritePivot: {x: 0.5, y: 0.5} 48 | spritePixelsToUnits: 100 49 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 50 | spriteGenerateFallbackPhysicsShape: 1 51 | alphaUsage: 1 52 | alphaIsTransparency: 0 53 | spriteTessellationDetail: -1 54 | textureType: 0 55 | textureShape: 1 56 | singleChannelComponent: 0 57 | maxTextureSizeSet: 0 58 | compressionQualitySet: 0 59 | textureFormatSet: 0 60 | platformSettings: 61 | - serializedVersion: 2 62 | buildTarget: DefaultTexturePlatform 63 | maxTextureSize: 2048 64 | resizeAlgorithm: 0 65 | textureFormat: -1 66 | textureCompression: 1 67 | compressionQuality: 50 68 | crunchedCompression: 0 69 | allowsAlphaSplitting: 0 70 | overridden: 0 71 | androidETC2FallbackOverride: 0 72 | spriteSheet: 73 | serializedVersion: 2 74 | sprites: [] 75 | outline: [] 76 | physicsShape: [] 77 | bones: [] 78 | spriteID: 79 | vertices: [] 80 | indices: 81 | edges: [] 82 | weights: [] 83 | spritePackingTag: 84 | pSDRemoveMatte: 0 85 | pSDShowRemoveMatteOption: 0 86 | userData: 87 | assetBundleName: 88 | assetBundleVariant: 89 | -------------------------------------------------------------------------------- /Assets/figure/figure11-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyonggit/RayTracingInOneWeekend_CSharp/31372c481f9e4d45e8ba30ebcb78548bd00ed8b8/Assets/figure/figure11-1.png -------------------------------------------------------------------------------- /Assets/figure/figure11-1.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 608c08f6317df984aa2bd0f627701930 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | externalObjects: {} 6 | serializedVersion: 9 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 1 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | isReadable: 0 24 | streamingMipmaps: 0 25 | streamingMipmapsPriority: 0 26 | grayScaleToAlpha: 0 27 | generateCubemap: 6 28 | cubemapConvolution: 0 29 | seamlessCubemap: 0 30 | textureFormat: 1 31 | maxTextureSize: 2048 32 | textureSettings: 33 | serializedVersion: 2 34 | filterMode: -1 35 | aniso: -1 36 | mipBias: -100 37 | wrapU: -1 38 | wrapV: -1 39 | wrapW: -1 40 | nPOTScale: 1 41 | lightmap: 0 42 | compressionQuality: 50 43 | spriteMode: 0 44 | spriteExtrude: 1 45 | spriteMeshType: 1 46 | alignment: 0 47 | spritePivot: {x: 0.5, y: 0.5} 48 | spritePixelsToUnits: 100 49 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 50 | spriteGenerateFallbackPhysicsShape: 1 51 | alphaUsage: 1 52 | alphaIsTransparency: 0 53 | spriteTessellationDetail: -1 54 | textureType: 0 55 | textureShape: 1 56 | singleChannelComponent: 0 57 | maxTextureSizeSet: 0 58 | compressionQualitySet: 0 59 | textureFormatSet: 0 60 | platformSettings: 61 | - serializedVersion: 2 62 | buildTarget: DefaultTexturePlatform 63 | maxTextureSize: 2048 64 | resizeAlgorithm: 0 65 | textureFormat: -1 66 | textureCompression: 1 67 | compressionQuality: 50 68 | crunchedCompression: 0 69 | allowsAlphaSplitting: 0 70 | overridden: 0 71 | androidETC2FallbackOverride: 0 72 | spriteSheet: 73 | serializedVersion: 2 74 | sprites: [] 75 | outline: [] 76 | physicsShape: [] 77 | bones: [] 78 | spriteID: 79 | vertices: [] 80 | indices: 81 | edges: [] 82 | weights: [] 83 | spritePackingTag: 84 | pSDRemoveMatte: 0 85 | pSDShowRemoveMatteOption: 0 86 | userData: 87 | assetBundleName: 88 | assetBundleVariant: 89 | -------------------------------------------------------------------------------- /Assets/figure/figure11-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyonggit/RayTracingInOneWeekend_CSharp/31372c481f9e4d45e8ba30ebcb78548bd00ed8b8/Assets/figure/figure11-2.png -------------------------------------------------------------------------------- /Assets/figure/figure11-2.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7e07f5a39778bce44acd9f562c12d602 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | externalObjects: {} 6 | serializedVersion: 9 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 1 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | isReadable: 0 24 | streamingMipmaps: 0 25 | streamingMipmapsPriority: 0 26 | grayScaleToAlpha: 0 27 | generateCubemap: 6 28 | cubemapConvolution: 0 29 | seamlessCubemap: 0 30 | textureFormat: 1 31 | maxTextureSize: 2048 32 | textureSettings: 33 | serializedVersion: 2 34 | filterMode: -1 35 | aniso: -1 36 | mipBias: -100 37 | wrapU: -1 38 | wrapV: -1 39 | wrapW: -1 40 | nPOTScale: 1 41 | lightmap: 0 42 | compressionQuality: 50 43 | spriteMode: 0 44 | spriteExtrude: 1 45 | spriteMeshType: 1 46 | alignment: 0 47 | spritePivot: {x: 0.5, y: 0.5} 48 | spritePixelsToUnits: 100 49 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 50 | spriteGenerateFallbackPhysicsShape: 1 51 | alphaUsage: 1 52 | alphaIsTransparency: 0 53 | spriteTessellationDetail: -1 54 | textureType: 0 55 | textureShape: 1 56 | singleChannelComponent: 0 57 | maxTextureSizeSet: 0 58 | compressionQualitySet: 0 59 | textureFormatSet: 0 60 | platformSettings: 61 | - serializedVersion: 2 62 | buildTarget: DefaultTexturePlatform 63 | maxTextureSize: 2048 64 | resizeAlgorithm: 0 65 | textureFormat: -1 66 | textureCompression: 1 67 | compressionQuality: 50 68 | crunchedCompression: 0 69 | allowsAlphaSplitting: 0 70 | overridden: 0 71 | androidETC2FallbackOverride: 0 72 | spriteSheet: 73 | serializedVersion: 2 74 | sprites: [] 75 | outline: [] 76 | physicsShape: [] 77 | bones: [] 78 | spriteID: 79 | vertices: [] 80 | indices: 81 | edges: [] 82 | weights: [] 83 | spritePackingTag: 84 | pSDRemoveMatte: 0 85 | pSDShowRemoveMatteOption: 0 86 | userData: 87 | assetBundleName: 88 | assetBundleVariant: 89 | -------------------------------------------------------------------------------- /Assets/figure/figure5-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyonggit/RayTracingInOneWeekend_CSharp/31372c481f9e4d45e8ba30ebcb78548bd00ed8b8/Assets/figure/figure5-1.png -------------------------------------------------------------------------------- /Assets/figure/figure5-1.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8d6fd9ecd1f406348b1da2ac4b772261 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | externalObjects: {} 6 | serializedVersion: 9 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 1 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | isReadable: 0 24 | streamingMipmaps: 0 25 | streamingMipmapsPriority: 0 26 | grayScaleToAlpha: 0 27 | generateCubemap: 6 28 | cubemapConvolution: 0 29 | seamlessCubemap: 0 30 | textureFormat: 1 31 | maxTextureSize: 2048 32 | textureSettings: 33 | serializedVersion: 2 34 | filterMode: -1 35 | aniso: -1 36 | mipBias: -100 37 | wrapU: -1 38 | wrapV: -1 39 | wrapW: -1 40 | nPOTScale: 1 41 | lightmap: 0 42 | compressionQuality: 50 43 | spriteMode: 0 44 | spriteExtrude: 1 45 | spriteMeshType: 1 46 | alignment: 0 47 | spritePivot: {x: 0.5, y: 0.5} 48 | spritePixelsToUnits: 100 49 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 50 | spriteGenerateFallbackPhysicsShape: 1 51 | alphaUsage: 1 52 | alphaIsTransparency: 0 53 | spriteTessellationDetail: -1 54 | textureType: 0 55 | textureShape: 1 56 | singleChannelComponent: 0 57 | maxTextureSizeSet: 0 58 | compressionQualitySet: 0 59 | textureFormatSet: 0 60 | platformSettings: 61 | - serializedVersion: 2 62 | buildTarget: DefaultTexturePlatform 63 | maxTextureSize: 2048 64 | resizeAlgorithm: 0 65 | textureFormat: -1 66 | textureCompression: 1 67 | compressionQuality: 50 68 | crunchedCompression: 0 69 | allowsAlphaSplitting: 0 70 | overridden: 0 71 | androidETC2FallbackOverride: 0 72 | spriteSheet: 73 | serializedVersion: 2 74 | sprites: [] 75 | outline: [] 76 | physicsShape: [] 77 | bones: [] 78 | spriteID: 79 | vertices: [] 80 | indices: 81 | edges: [] 82 | weights: [] 83 | spritePackingTag: 84 | pSDRemoveMatte: 0 85 | pSDShowRemoveMatteOption: 0 86 | userData: 87 | assetBundleName: 88 | assetBundleVariant: 89 | -------------------------------------------------------------------------------- /Assets/figure/figure7-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyonggit/RayTracingInOneWeekend_CSharp/31372c481f9e4d45e8ba30ebcb78548bd00ed8b8/Assets/figure/figure7-1.png -------------------------------------------------------------------------------- /Assets/figure/figure7-1.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 863916c545379e24ea1c919d342aaf1a 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | externalObjects: {} 6 | serializedVersion: 9 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 1 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | isReadable: 0 24 | streamingMipmaps: 0 25 | streamingMipmapsPriority: 0 26 | grayScaleToAlpha: 0 27 | generateCubemap: 6 28 | cubemapConvolution: 0 29 | seamlessCubemap: 0 30 | textureFormat: 1 31 | maxTextureSize: 2048 32 | textureSettings: 33 | serializedVersion: 2 34 | filterMode: -1 35 | aniso: -1 36 | mipBias: -100 37 | wrapU: -1 38 | wrapV: -1 39 | wrapW: -1 40 | nPOTScale: 1 41 | lightmap: 0 42 | compressionQuality: 50 43 | spriteMode: 0 44 | spriteExtrude: 1 45 | spriteMeshType: 1 46 | alignment: 0 47 | spritePivot: {x: 0.5, y: 0.5} 48 | spritePixelsToUnits: 100 49 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 50 | spriteGenerateFallbackPhysicsShape: 1 51 | alphaUsage: 1 52 | alphaIsTransparency: 0 53 | spriteTessellationDetail: -1 54 | textureType: 0 55 | textureShape: 1 56 | singleChannelComponent: 0 57 | maxTextureSizeSet: 0 58 | compressionQualitySet: 0 59 | textureFormatSet: 0 60 | platformSettings: 61 | - serializedVersion: 2 62 | buildTarget: DefaultTexturePlatform 63 | maxTextureSize: 2048 64 | resizeAlgorithm: 0 65 | textureFormat: -1 66 | textureCompression: 1 67 | compressionQuality: 50 68 | crunchedCompression: 0 69 | allowsAlphaSplitting: 0 70 | overridden: 0 71 | androidETC2FallbackOverride: 0 72 | spriteSheet: 73 | serializedVersion: 2 74 | sprites: [] 75 | outline: [] 76 | physicsShape: [] 77 | bones: [] 78 | spriteID: 79 | vertices: [] 80 | indices: 81 | edges: [] 82 | weights: [] 83 | spritePackingTag: 84 | pSDRemoveMatte: 0 85 | pSDShowRemoveMatteOption: 0 86 | userData: 87 | assetBundleName: 88 | assetBundleVariant: 89 | -------------------------------------------------------------------------------- /Assets/figure/figure7-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyonggit/RayTracingInOneWeekend_CSharp/31372c481f9e4d45e8ba30ebcb78548bd00ed8b8/Assets/figure/figure7-2.png -------------------------------------------------------------------------------- /Assets/figure/figure7-2.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 29ebe6edf7e765849a1ca7173f5726c4 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | externalObjects: {} 6 | serializedVersion: 9 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 1 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | isReadable: 0 24 | streamingMipmaps: 0 25 | streamingMipmapsPriority: 0 26 | grayScaleToAlpha: 0 27 | generateCubemap: 6 28 | cubemapConvolution: 0 29 | seamlessCubemap: 0 30 | textureFormat: 1 31 | maxTextureSize: 2048 32 | textureSettings: 33 | serializedVersion: 2 34 | filterMode: -1 35 | aniso: -1 36 | mipBias: -100 37 | wrapU: -1 38 | wrapV: -1 39 | wrapW: -1 40 | nPOTScale: 1 41 | lightmap: 0 42 | compressionQuality: 50 43 | spriteMode: 0 44 | spriteExtrude: 1 45 | spriteMeshType: 1 46 | alignment: 0 47 | spritePivot: {x: 0.5, y: 0.5} 48 | spritePixelsToUnits: 100 49 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 50 | spriteGenerateFallbackPhysicsShape: 1 51 | alphaUsage: 1 52 | alphaIsTransparency: 0 53 | spriteTessellationDetail: -1 54 | textureType: 0 55 | textureShape: 1 56 | singleChannelComponent: 0 57 | maxTextureSizeSet: 0 58 | compressionQualitySet: 0 59 | textureFormatSet: 0 60 | platformSettings: 61 | - serializedVersion: 2 62 | buildTarget: DefaultTexturePlatform 63 | maxTextureSize: 2048 64 | resizeAlgorithm: 0 65 | textureFormat: -1 66 | textureCompression: 1 67 | compressionQuality: 50 68 | crunchedCompression: 0 69 | allowsAlphaSplitting: 0 70 | overridden: 0 71 | androidETC2FallbackOverride: 0 72 | spriteSheet: 73 | serializedVersion: 2 74 | sprites: [] 75 | outline: [] 76 | physicsShape: [] 77 | bones: [] 78 | spriteID: 79 | vertices: [] 80 | indices: 81 | edges: [] 82 | weights: [] 83 | spritePackingTag: 84 | pSDRemoveMatte: 0 85 | pSDShowRemoveMatteOption: 0 86 | userData: 87 | assetBundleName: 88 | assetBundleVariant: 89 | -------------------------------------------------------------------------------- /Assets/figure/figure8-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyonggit/RayTracingInOneWeekend_CSharp/31372c481f9e4d45e8ba30ebcb78548bd00ed8b8/Assets/figure/figure8-1.png -------------------------------------------------------------------------------- /Assets/figure/figure8-1.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8c398e00e05fcf744b4bd0a33ea15988 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | externalObjects: {} 6 | serializedVersion: 9 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 1 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | isReadable: 0 24 | streamingMipmaps: 0 25 | streamingMipmapsPriority: 0 26 | grayScaleToAlpha: 0 27 | generateCubemap: 6 28 | cubemapConvolution: 0 29 | seamlessCubemap: 0 30 | textureFormat: 1 31 | maxTextureSize: 2048 32 | textureSettings: 33 | serializedVersion: 2 34 | filterMode: -1 35 | aniso: -1 36 | mipBias: -100 37 | wrapU: -1 38 | wrapV: -1 39 | wrapW: -1 40 | nPOTScale: 1 41 | lightmap: 0 42 | compressionQuality: 50 43 | spriteMode: 0 44 | spriteExtrude: 1 45 | spriteMeshType: 1 46 | alignment: 0 47 | spritePivot: {x: 0.5, y: 0.5} 48 | spritePixelsToUnits: 100 49 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 50 | spriteGenerateFallbackPhysicsShape: 1 51 | alphaUsage: 1 52 | alphaIsTransparency: 0 53 | spriteTessellationDetail: -1 54 | textureType: 0 55 | textureShape: 1 56 | singleChannelComponent: 0 57 | maxTextureSizeSet: 0 58 | compressionQualitySet: 0 59 | textureFormatSet: 0 60 | platformSettings: 61 | - serializedVersion: 2 62 | buildTarget: DefaultTexturePlatform 63 | maxTextureSize: 2048 64 | resizeAlgorithm: 0 65 | textureFormat: -1 66 | textureCompression: 1 67 | compressionQuality: 50 68 | crunchedCompression: 0 69 | allowsAlphaSplitting: 0 70 | overridden: 0 71 | androidETC2FallbackOverride: 0 72 | spriteSheet: 73 | serializedVersion: 2 74 | sprites: [] 75 | outline: [] 76 | physicsShape: [] 77 | bones: [] 78 | spriteID: 79 | vertices: [] 80 | indices: 81 | edges: [] 82 | weights: [] 83 | spritePackingTag: 84 | pSDRemoveMatte: 0 85 | pSDShowRemoveMatteOption: 0 86 | userData: 87 | assetBundleName: 88 | assetBundleVariant: 89 | -------------------------------------------------------------------------------- /Assets/figure/figure9-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyonggit/RayTracingInOneWeekend_CSharp/31372c481f9e4d45e8ba30ebcb78548bd00ed8b8/Assets/figure/figure9-1.png -------------------------------------------------------------------------------- /Assets/figure/figure9-1.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 910f6d04a8ed7b14bb86494b6d5c6dae 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | externalObjects: {} 6 | serializedVersion: 9 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 1 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | isReadable: 0 24 | streamingMipmaps: 0 25 | streamingMipmapsPriority: 0 26 | grayScaleToAlpha: 0 27 | generateCubemap: 6 28 | cubemapConvolution: 0 29 | seamlessCubemap: 0 30 | textureFormat: 1 31 | maxTextureSize: 2048 32 | textureSettings: 33 | serializedVersion: 2 34 | filterMode: -1 35 | aniso: -1 36 | mipBias: -100 37 | wrapU: -1 38 | wrapV: -1 39 | wrapW: -1 40 | nPOTScale: 1 41 | lightmap: 0 42 | compressionQuality: 50 43 | spriteMode: 0 44 | spriteExtrude: 1 45 | spriteMeshType: 1 46 | alignment: 0 47 | spritePivot: {x: 0.5, y: 0.5} 48 | spritePixelsToUnits: 100 49 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 50 | spriteGenerateFallbackPhysicsShape: 1 51 | alphaUsage: 1 52 | alphaIsTransparency: 0 53 | spriteTessellationDetail: -1 54 | textureType: 0 55 | textureShape: 1 56 | singleChannelComponent: 0 57 | maxTextureSizeSet: 0 58 | compressionQualitySet: 0 59 | textureFormatSet: 0 60 | platformSettings: 61 | - serializedVersion: 2 62 | buildTarget: DefaultTexturePlatform 63 | maxTextureSize: 2048 64 | resizeAlgorithm: 0 65 | textureFormat: -1 66 | textureCompression: 1 67 | compressionQuality: 50 68 | crunchedCompression: 0 69 | allowsAlphaSplitting: 0 70 | overridden: 0 71 | androidETC2FallbackOverride: 0 72 | spriteSheet: 73 | serializedVersion: 2 74 | sprites: [] 75 | outline: [] 76 | physicsShape: [] 77 | bones: [] 78 | spriteID: 79 | vertices: [] 80 | indices: 81 | edges: [] 82 | weights: [] 83 | spritePackingTag: 84 | pSDRemoveMatte: 0 85 | pSDShowRemoveMatteOption: 0 86 | userData: 87 | assetBundleName: 88 | assetBundleVariant: 89 | -------------------------------------------------------------------------------- /README.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyonggit/RayTracingInOneWeekend_CSharp/31372c481f9e4d45e8ba30ebcb78548bd00ed8b8/README.pdf --------------------------------------------------------------------------------