Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/uber lit shader #32

Merged
merged 21 commits into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
248c0ea
Merge branch 'main' into feature/uber_lit_gui
CyTakayukiKiyohara Jul 12, 2022
1a7a04b
Implementation GUI for lit.
CyTakayukiKiyohara Jul 12, 2022
5959f8b
New UberLit features include normalMap, metallicMap, and smoothnessMap.
CyTakayukiKiyohara Jul 12, 2022
e6b0de0
Implement Lit( On the way).
CyTakayukiKiyohara Jul 19, 2022
305f217
Implementation Lit( On the way ).
CyTakayukiKiyohara Jul 19, 2022
360a352
Finished the Metallic WorkflowMode is Implemented.
CyTakayukiKiyohara Jul 19, 2022
1258079
Add _NormalMapBumpScale property.
CyTakayukiKiyohara Jul 19, 2022
2596758
Implementation UberLit test
CyTakayukiKiyohara Jul 26, 2022
356dcd8
Add tests for uber lit.
CyTakayukiKiyohara Jul 26, 2022
702257f
Bug Fix : URP and NOVA have different lighting on android.
CyTakayukiKiyohara Jul 27, 2022
4a8ba3c
Merge branch 'develop_lit' into feature/uber_lit_shader
CyTakayukiKiyohara Aug 1, 2022
f084a5c
Add a comment.
CyTakayukiKiyohara Aug 2, 2022
dfe1976
Implement to Picking and SceneSelectionPass.
CyTakayukiKiyohara Aug 2, 2022
8380b8e
Implement DepthNormalPass And DepthOnlyPass.
CyTakayukiKiyohara Aug 2, 2022
51143a8
Add UberLit Test.
CyTakayukiKiyohara Aug 2, 2022
0a86615
Rename the file.
CyTakayukiKiyohara Aug 2, 2022
231e0b7
Fixed : Don't move TestUberLit_00.
CyTakayukiKiyohara Aug 3, 2022
96eab88
Remove useless include files.
CyTakayukiKiyohara Aug 9, 2022
81c3df1
Fixed warning.
CyTakayukiKiyohara Aug 9, 2022
79fad49
Move files from Test folder to Demo folder.
CyTakayukiKiyohara Aug 9, 2022
fca73df
Rebuild Reflection Probe
CyTakayukiKiyohara Aug 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Implement Lit( On the way).
  • Loading branch information
CyTakayukiKiyohara committed Jul 19, 2022
commit e6b0de028878619bf3961af4c22a88f5a95b5e06
2 changes: 2 additions & 0 deletions Assets/Nova/Editor/Core/Scripts/ParticlesUberLitGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ protected override void MaterialChanged(Material material)
{
ParticlesUberUnlitMaterialPostProcessor.SetupMaterialKeywords(material);
ParticlesUberUnlitMaterialPostProcessor.SetupMaterialBlendMode(material);
// todo テスト
material.EnableKeyword("_MAIN_LIGHT_CALCULATE_SHADOWS");
}

#region Foldout Properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,11 @@ SamplerState GetEmissionMapSamplerState()

// Sample the normal map.
#ifdef _BASE_MAP_MODE_2D
#define SAMPLE_NORMAL_MAP(uv, progress) SAMPLE_TEXTURE2D(_NormalMap, GetNormalMapSamplerState(), uv);
#define SAMPLE_NORMAL_MAP(uv, progress) UnpackNormal(SAMPLE_TEXTURE2D(_NormalMap, GetNormalMapSamplerState(), uv));
#elif _BASE_MAP_MODE_2D_ARRAY
#define SAMPLE_NORMAL_MAP(uv, progress) SAMPLE_TEXTURE2D_ARRAY(_NormalMap2DArray, GetNormalMapSamplerState(), uv, progress);
#define SAMPLE_NORMAL_MAP(uv, progress) UnpackNormal(SAMPLE_TEXTURE2D_ARRAY(_NormalMap2DArray, GetNormalMapSamplerState(), uv, progress));
#elif _BASE_MAP_MODE_3D
#define SAMPLE_NORMAL_MAP(uv, progress) SAMPLE_TEXTURE3D_LOD(_NormalMap3D, GetNormalMapSamplerState(), float3(uv, progress), 0);
#define SAMPLE_NORMAL_MAP(uv, progress) UnpackNormal(SAMPLE_TEXTURE3D_LOD(_NormalMap3D, GetNormalMapSamplerState(), float3(uv, progress), 0));
#endif

// Sample the metallic map.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,33 @@
struct AttributesLit
{
Attributes attributesUnlit;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

こんな使い方ができるんですね 👀

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

できるんです!

#ifdef _NORMALMAP
float4 tangentOS : TANGENT;
#endif
};

// Output data from the vertex shader.
struct VaryingsLit
{
Varyings varyingsUnlit;
float3 positionWS : COLOR1;
float3 tangentWS : TANGENT;
float4 positionWS : COLOR1;
#ifdef _NORMALMAP
float4 tangentWS : TANGENT;
float3 binormalWS : BINORMAL;
#endif
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
float4 shadowCoord : COLOR2;
#endif
float3 vertexSH : COLOR3; // SH

};
inline void InitializeFragmentInputLit(in out VaryingsLit input)
{
InitializeFragmentInput(input.varyingsUnlit);
#ifdef _NORMALMAP
input.binormalWS = normalize(input.binormalWS);
input.tangentWS = normalize(input.tangentWS);
#endif
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ Shader "Nova/Particles/UberLit"
#pragma shader_feature_local_fragment _VERTEX_ALPHA_AS_TRANSITION_PROGRESS
#pragma shader_feature_local_fragment _ALPHAMODULATE_ENABLED
#pragma shader_feature_local_fragment _ALPHATEST_ENABLED

// Base Map
#pragma shader_feature_local _BASE_MAP_MODE_2D _BASE_MAP_MODE_2D_ARRAY _BASE_MAP_MODE_3D
#pragma shader_feature_local_vertex _BASE_MAP_ROTATION_ENABLED
Expand Down Expand Up @@ -243,12 +243,14 @@ Shader "Nova/Particles/UberLit"
#pragma shader_feature_local_fragment _VERTEX_ALPHA_AS_TRANSITION_PROGRESS
#pragma shader_feature_local_fragment _ALPHAMODULATE_ENABLED
#pragma shader_feature_local_fragment _ALPHATEST_ENABLED

#pragma shader_feature_local _MAIN_LIGHT_CALCULATE_SHADOWS

// Base Map
#pragma shader_feature_local _BASE_MAP_MODE_2D _BASE_MAP_MODE_2D_ARRAY _BASE_MAP_MODE_3D
#pragma shader_feature_local_vertex _BASE_MAP_ROTATION_ENABLED
#pragma shader_feature_local_fragment _ _BASE_SAMPLER_STATE_POINT_MIRROR _BASE_SAMPLER_STATE_LINEAR_MIRROR _BASE_SAMPLER_STATE_TRILINEAR_MIRROR


// Tint Color
#pragma shader_feature_local _ _TINT_AREA_ALL _TINT_AREA_RIM
#pragma shader_feature_local _ _TINT_COLOR_ENABLED _TINT_MAP_ENABLED _TINT_MAP_3D_ENABLED
Expand Down
123 changes: 123 additions & 0 deletions Assets/Nova/Editor/Core/Scripts/Shaders/ParticlesUberLitForward.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#ifndef NOVA_PARTICLESUBERLITFORWARD_INCLUDED
#define NOVA_PARTICLESUBERLITFORWARD_INCLUDED

#define FRAGMENT_USE_NORMAL_WS
#define FRAGMENT_USE_VIEW_DIR_WS
// todo If _SPECULARHIGHLIGHTS_OFF is defined, specular highlight is disabled.
#define _SPECULARHIGHLIGHTS_OFF
// todo If _ENVIRONMENTREFLECTIONS_OFF is defined, environment reflections are desabled。
#define _ENVIRONMENTREFLECTIONS_OFF
// todo If _NORMALMAP is defind, normal map is used.
#define _NORMALMAP
// todo If REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR is defined, uv coords of shadow map is calculated in vertex shader.
#define REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR
// todo If MAIN_LIGHT_CALCULATE_SHADOWS is defined, shadow are cast on the objects.
#ifdef _MAIN_LIGHT_CALCULATE_SHADOWS
#define MAIN_LIGHT_CALCULATE_SHADOWS
#endif

#include "ParticlesUberUnlitForward.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
#include "ParticlesUberLit.hlsl"

VaryingsLit vertLit(AttributesLit input)
{
VaryingsLit output = (VaryingsLit)0;
output.varyingsUnlit = vert(input.attributesUnlit);

output.positionWS.xyz = TransformObjectToWorld(input.attributesUnlit.positionOS.xyz);

// Calculate tanget and binormal
#ifdef _NORMALMAP
output.tangentWS.xyz = TransformObjectToWorldDir(input.tangentOS.xyz, true);
output.tangentWS.w = input.tangentOS.w;
output.binormalWS = cross(output.varyingsUnlit.normalWS, output.tangentWS) * input.tangentOS.w;
#endif

half3 vertexLight = VertexLighting(output.positionWS, output.varyingsUnlit.normalWS);
half fogFactor = ComputeFogFactor(output.varyingsUnlit.positionHCS.z);
output.positionWS.w = fogFactor;

OUTPUT_SH(output.varyingsUnlit.normalWS.xyz, output.vertexSH);

#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
output.shadowCoord = TransformWorldToShadowCoord(output.positionWS.xyz);
#endif

return output;
}
half GetMetallic( float3 uvw )
{
half4 metallic = SAMPLE_METALLIC_MAP(uvw.xy, uvw.z);
return metallic[(int)_MetallicMapChannelsX.x];;
}
half GetSmoothness( float3 uvw )
{
const half4 smoothness = SAMPLE_SMOOTHNESS_MAP(uvw.xy, uvw.z);
return smoothness[(int)_SmoothnessMapChannelsX.x];
}
half4 fragLit(VaryingsLit input) : SV_Target
{
Varyings inputUnlit = input.varyingsUnlit;
half4 color = frag(inputUnlit);
SurfaceData surfaceData = (SurfaceData)0;
// OK
surfaceData.albedo = color.xyz;
// TODO Survey the SampleNormalTS Function in Particels.hlsl in URP package.
surfaceData.normalTS = SAMPLE_NORMAL_MAP(inputUnlit.baseMapUVAndProgresses.xy, inputUnlit.baseMapUVAndProgresses.z);
// TODO Specular Workflow is not implemented.
// OK
surfaceData.metallic = GetMetallic(inputUnlit.baseMapUVAndProgresses.xyz);
// OK
surfaceData.specular = half3( 0, 0, 0);
surfaceData.smoothness = GetSmoothness(inputUnlit.baseMapUVAndProgresses.xyz);
surfaceData.alpha = color.a;
// The values of clearCoatMask,clearCoatSmoothness and occlusion is referenced from ParticlesLitInput.hlsl in UPR Package.
surfaceData.clearCoatMask = 0;
surfaceData.clearCoatSmoothness = 1;
surfaceData.occlusion = 1;
// todo : What to do emission?
surfaceData.emission = 0;

InputData inputData = (InputData)0;
// OK
inputData.positionWS = input.positionWS.xyz;
#ifdef _NORMALMAP
// OK
inputData.normalWS = TransformTangentToWorld(
surfaceData.normalTS,
half3x3(
input.tangentWS.xyz,
input.binormalWS.xyz,
inputUnlit.normalWS.xyz));

#else
inputData.normalWS = inputUnlit.normalWS.xyz;
#endif
inputData.normalWS = NormalizeNormalPerPixel(inputData.normalWS);
// OK
inputData.viewDirectionWS = inputUnlit.viewDirWS;
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
// OK
inputData.shadowCoord = input.shadowCoord;
#elif defined(MAIN_LIGHT_CALCULATE_SHADOWS)
// todo : Not implemented yet.
inputData.shadowCoord = TransformWorldToShadowCoord(input.positionWS.xyz);
#else
inputData.shadowCoord = float4(0, 0, 0, 0);
#endif
inputData.fogCoord = input.positionWS.w;
// todo : What to do vertexLighting?

inputData.bakedGI = SampleSHPixel(input.vertexSH, inputData.normalWS);
inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(inputUnlit.positionHCS);
// The values of shadowMask and vertexLighting are referenced from ParticlesLitForwardPass.hlsl in UPR Package.
inputData.shadowMask = half4(1, 1, 1, 1);
inputData.vertexLighting = half3(0, 0, 0);

color = UniversalFragmentPBR(inputData, surfaceData);
return color;
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
struct Attributes
{
float4 positionOS : POSITION;
float4 color : COLOR0;
float4 color : COLOR;
float3 normalOS : NORMAL;
float2 texcoord : TEXCOORD0;
#ifndef NOVA_PARTICLE_INSTANCING_ENABLED
Expand Down
66 changes: 0 additions & 66 deletions Assets/Nova/Runtime/Core/Shaders/ParticlesUberLitForward.hlsl

This file was deleted.