Skip to content

Commit

Permalink
Merge pull request #9 from judysng/Atom/njud/six-point-lighting
Browse files Browse the repository at this point in the history
  • Loading branch information
cgalvan authored Aug 10, 2022
2 parents 084469b + 0a82a48 commit fcc225b
Show file tree
Hide file tree
Showing 38 changed files with 2,688 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/

#include <../SixPointSurface.azsli>
#include <Atom/Features/MatrixUtility.azsli>

void EvaluateSixPointSurface(
float3 vertexNormal,
float2 uv[UvSetCount],
float3 tangents[UvSetCount],
float3 bitangents[UvSetCount],
bool isFrontFace,
bool displacementIsClipped,
inout Surface surface)
{
// ------- Base Color -------
float2 baseColorUv = uv[MaterialSrg::m_baseColorMapUvIndex];
float2 sixPointUv = GetUvForCurrentFrame(baseColorUv);
float3 sampledColor = GetBaseColorInput(MaterialSrg::m_baseColorMap, MaterialSrg::m_sampler, sixPointUv, MaterialSrg::m_baseColor.rgb, o_baseColor_useTexture);
float3 baseColor = BlendBaseColor(sampledColor, MaterialSrg::m_baseColor.rgb, MaterialSrg::m_baseColorFactor, o_baseColorTextureBlendMode, o_baseColor_useTexture);

// ------- Metallic -------
float metallic = MaterialSrg::m_metallicFactor;

// ------- Specular -------
float specularF0Factor = MaterialSrg::m_specularF0Factor;
surface.SetAlbedoAndSpecularF0(baseColor, specularF0Factor, metallic);

if(o_sixPointTexturePackMode == SixPointTexturePackMode::TpLftRtBt_FrBck)
{
float4 topLeftRightBottom = MaterialSrg::m_topLeftRightBottomMap.Sample(MaterialSrg::m_sampler, sixPointUv);
float4 frontBack = MaterialSrg::m_frontBackMap.Sample(MaterialSrg::m_sampler, sixPointUv);
surface.top = topLeftRightBottom.r;
surface.left = topLeftRightBottom.g;
surface.right = topLeftRightBottom.b;
surface.bottom = topLeftRightBottom.a;
surface.frontside = frontBack.r;
surface.backside = frontBack.g;
}
else
{
float4 rightLeftTop = MaterialSrg::m_rightLeftTopMap.Sample(MaterialSrg::m_sampler, sixPointUv);
float4 bottomBackFront = MaterialSrg::m_bottomBackFrontMap.Sample(MaterialSrg::m_sampler, sixPointUv);
surface.right = rightLeftTop.r;
surface.left = rightLeftTop.g;
surface.top = rightLeftTop.b;
surface.bottom = bottomBackFront.r;
surface.backside = bottomBackFront.g;
surface.frontside = bottomBackFront.b;
}
surface.tangent = tangents[0];
surface.bitangent = bitangents[0];

// ------- Roughness -------
surface.roughnessLinear = MaterialSrg::m_roughnessFactor;;
surface.CalculateRoughnessA();

// ------- Clearcoat -------
surface.clearCoat.InitializeToZero();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
{
"name": "sixPointLighting",
"displayName": "Six Point Lighting",
"description": "Six point lighting settings.",
"properties": [
{
"name": "texturePackMode",
"displayName": "Texture Pack Mode",
"description": "Determines how the textures are sampled.",
"type": "Enum",
"enumValues": [ "TpLftRtBt_FrBck", "RtLftTp_BtBckFr" ],
"defaultValue": "TpLftRtBt_FrBck",
"connection": {
"type": "ShaderOption",
"name": "o_sixPointTexturePackMode"
}
},
{
"name": "TLRB",
"displayName": "Top Left Right Bottom",
"description": "Top Left Right Bottom Lightmap",
"type": "Image",
"connection": {
"type": "ShaderInput",
"name": "m_topLeftRightBottomMap"
}
},
{
"name": "FB",
"displayName": "Front Back",
"description": "Front Back Lightmap",
"type": "Image",
"connection": {
"type": "ShaderInput",
"name": "m_frontBackMap"
}
},
{
"name": "RLT",
"displayName": "Right Left Top",
"description": "Right Left Top Lightmap",
"type": "Image",
"connection": {
"type": "ShaderInput",
"name": "m_rightLeftTopMap"
}
},
{
"name": "BBF",
"displayName": "Bottom Back Front",
"description": "Bottom Back Front Lightmap",
"type": "Image",
"connection": {
"type": "ShaderInput",
"name": "m_bottomBackFrontMap"
}
},
{
"name": "useDepthTexture",
"displayName": "Use Depth",
"description": "Whether to use the depth map.",
"type": "Bool",
"defaultValue": false
},
{
"name": "depthMap",
"displayName": "Depth",
"description": "Depth texture map",
"type": "Image",
"connection": {
"type": "ShaderInput",
"name": "m_depthMap"
}
},
{
"name": "depthScale",
"displayName": "Scale the Depth Texture",
"description": "Multiplier for the depth texture",
"type": "Float",
"defaultValue": 10.0,
"min": 0.01,
"connection": {
"type": "ShaderInput",
"name": "m_depthScale"
}
},
{
"name": "rowCount",
"displayName": "Rows in Flipbook",
"description": "Total rows of animation in the flipbook",
"type": "Float",
"defaultValue": 8.0,
"min": 1.0,
"step": 1.0,
"connection": {
"type": "ShaderInput",
"name": "m_rowCount"
}
},
{
"name": "columnCount",
"displayName": "Columns in Flipbook",
"description": "Total columns of animation in the flipbook",
"type": "Float",
"defaultValue": 8.0,
"min": 1.0,
"step": 1.0,
"connection": {
"type": "ShaderInput",
"name": "m_columnCount"
}
},
{
"name": "enableDebugFrame",
"displayName": "Enable debugging a specific frame",
"description": "Locks the frame of the animation",
"type": "Bool",
"defaultValue": false,
"connection": {
"type": "ShaderOption",
"name": "o_enableDebugFrame"
}
},
{
"name": "debugFrame",
"displayName": "Debug Frame",
"description": "The frame you want to debug",
"type": "Float",
"defaultValue": 1.0,
"min": 1.0,
"step": 1.0,
"connection": {
"type": "ShaderInput",
"name": "m_debugFrame"
}
}
],
"functors": [
{
"type": "UseTexture",
"args": {
"textureProperty": "depthMap",
"useTextureProperty": "useDepthTexture",
"shaderOption": "o_enableDepthTexture"
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Thomas Iché

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[This repository (Unity-URP-SmokeLighting)](https://github.com/peeweek/Unity-URP-SmokeLighting/tree/main/Assets/VFX/SmokeLighting/Textures/2D) provides the following assets that we include in this directory:
* SmokeBall01_6Way_BBF_8x8.png
* SmokeBall01_6Way_RLT_8x8.png
* SmokeBall01_ColorCC_8x8.png

These assets are distributed under the MIT license, as included in this directory.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
145 changes: 145 additions & 0 deletions atom_gems/AtomTutorials/Assets/SixPointLighting/SixPointLighting.azsli
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/

#pragma once

// Include options first
#include <Atom/Features/PBR/LightingOptions.azsli>

// Then include custom surface and lighting data types
#include <Atom/Features/PBR/Lighting/LightingData.azsli>
#include <SixPointSurface.azsli>

#include <Atom/Features/PBR/LightingUtils.azsli>
#include <Atom/Features/PBR/Microfacet/Brdf.azsli>
#include <Atom/RPI/TangentSpace.azsli>

float ComputeLightMap(const float3 dirToLightWS, const Surface surface)
{
float3 dirToLightTS = WorldSpaceToTangent(dirToLightWS, surface.normal, surface.tangent, surface.bitangent);
float hMap = (dirToLightTS.x > 0.0f) ? (surface.right) : (surface.left); // Picks the correct horizontal side.
float vMap = (dirToLightTS.y > 0.0f) ? (surface.bottom) : (surface.top); // Picks the correct vertical side.
float dMap = (dirToLightTS.z > 0.0f) ? (surface.frontside) : (surface.backside); // Picks the correct front/back side
float lightMap = hMap*dirToLightTS.x*dirToLightTS.x + vMap*dirToLightTS.y*dirToLightTS.y + dMap*dirToLightTS.z*dirToLightTS.z; // Pythagoras!
return lightMap;
}

// Then define the Diffuse and Specular lighting functions
float3 GetDiffuseLighting(Surface surface, LightingData lightingData, float3 lightIntensity, float3 dirToLight)
{
float lightMap = ComputeLightMap(dirToLight, surface);
float3 diffuse = lightMap.rrr;

diffuse *= lightIntensity;
return diffuse;
}

float3 GetSpecularLighting(Surface surface, LightingData lightingData, const float3 lightIntensity, const float3 dirToLight)
{
return float3(0.0f, 0.0f, 0.0f);
}

// Then include everything else
#include <Atom/Features/PBR/Lights/Lights.azsli>

#include <Atom/Features/Debug.azsli>

#include <Atom/RPI/Math.azsli>
#include <Atom/Features/PBR/Lights/LightTypesCommon.azsli>

// Include IBL functions
float3 GetIblSample(Surface surface, float3 direction)
{
float3 irradianceDir = TangentSpaceToWorld(direction, surface.normal, surface.tangent, surface.bitangent);
irradianceDir = MultiplyVectorQuaternion(irradianceDir, SceneSrg::m_iblOrientation);
float3 diffuseSample = SceneSrg::m_diffuseEnvMap.Sample(SceneSrg::m_samplerEnv, GetCubemapCoords(irradianceDir)).rgb;

return diffuseSample;
}

float3 GetIblDiffuse(Surface surface, float3 diffuseResponse)
{
float3 rightSample = GetIblSample(surface, float3(1.0f, 0.0f, 0.0f));
float3 leftSample = GetIblSample(surface, float3(-1.0f, 0.0f, 0.0f));
float3 topSample = GetIblSample(surface, float3(0.0f, -1.0f, 0.0f));
float3 bottomSample = GetIblSample(surface, float3(0.0f, 1.0f, 0.0f));
float3 frontsideSample = GetIblSample(surface, float3(0.0f, 0.0f, 1.0f));
float3 backsideSample = GetIblSample(surface, float3(0.0f, 0.0f, -1.0f));

float3 totalDiffuseSample = (leftSample * surface.left)
+ (rightSample * surface.right)
+ (topSample * surface.top)
+ (bottomSample * surface.bottom)
+ (frontsideSample * surface.frontside)
+ (backsideSample * surface.backside);

return diffuseResponse * surface.albedo * totalDiffuseSample;
}

void ApplyIBL(Surface surface, inout LightingData lightingData)
{
bool useIbl = o_enableIBL && IsIndirectLightingEnabled();

#ifdef FORCE_IBL_IN_FORWARD_PASS
bool useDiffuseIbl = true;
#else
bool isTransparent = (o_opacity_mode == OpacityMode::Blended || o_opacity_mode == OpacityMode::TintedTransparent);
bool useDiffuseIbl = isTransparent;
useIbl = useIbl && useDiffuseIbl;
#endif

if(useIbl)
{
float globalIblExposure = pow(2.0, SceneSrg::m_iblExposure);

if(useDiffuseIbl)
{
float3 iblDiffuse = GetIblDiffuse(surface, lightingData.diffuseResponse);
lightingData.diffuseLighting += (iblDiffuse * globalIblExposure * lightingData.diffuseAmbientOcclusion);
}
}
}

struct PbrLightingOutput
{
float4 m_diffuseColor;
float4 m_specularColor;
float4 m_albedo;
float4 m_specularF0;
float4 m_normal;
};


PbrLightingOutput GetPbrLightingOutput(Surface surface, LightingData lightingData, float alpha)
{
PbrLightingOutput lightingOutput;

lightingOutput.m_diffuseColor = float4(lightingData.diffuseLighting, alpha);
lightingOutput.m_specularColor = float4(lightingData.specularLighting, 1.0);

// albedo, specularF0, roughness, and normals for later passes (specular IBL, Diffuse GI, SSR, AO, etc)
lightingOutput.m_specularF0 = float4(0.0f, 0.0f, 0.0f, surface.roughnessLinear);
lightingOutput.m_albedo.rgb = float3(1.0f, 1.0f, 1.0f) * lightingData.diffuseResponse * lightingData.diffuseAmbientOcclusion;
lightingOutput.m_albedo.a = lightingData.specularOcclusion;
lightingOutput.m_normal.rgb = EncodeNormalSignedOctahedron(surface.normal);
lightingOutput.m_normal.a = 0.0f;

return lightingOutput;
}

PbrLightingOutput DebugOutput(float3 color)
{
PbrLightingOutput output = (PbrLightingOutput)0;

float3 defaultNormal = float3(0.0f, 0.0f, 1.0f);

output.m_diffuseColor = float4(color.rgb, 1.0f);
output.m_normal.rgb = EncodeNormalSignedOctahedron(defaultNormal);

return output;
}
Loading

0 comments on commit fcc225b

Please sign in to comment.