git.s-ol.nu ~forks/DiligentFX / de72455
GLTF PBR Renderer: switched to using texture arrays assiduous 10 months ago
5 changed file(s) with 55 addition(s) and 45 deletion(s). Raw diff Collapse all Expand all
8080
8181 TextureDesc TexDesc;
8282 TexDesc.Name = "White texture for GLTF renderer";
83 TexDesc.Type = RESOURCE_DIM_TEX_2D;
83 TexDesc.Type = RESOURCE_DIM_TEX_2D_ARRAY;
8484 TexDesc.Usage = USAGE_IMMUTABLE;
8585 TexDesc.BindFlags = BIND_SHADER_RESOURCE;
8686 TexDesc.Width = TexDim;
4040 SamplerState g_BRDF_LUT_sampler;
4141 #endif
4242
43 Texture2D g_ColorMap;
44 SamplerState g_ColorMap_sampler;
45
46 Texture2D g_PhysicalDescriptorMap;
47 SamplerState g_PhysicalDescriptorMap_sampler;
48
49 Texture2D g_NormalMap;
50 SamplerState g_NormalMap_sampler;
43 Texture2DArray g_ColorMap;
44 SamplerState g_ColorMap_sampler;
45
46 Texture2DArray g_PhysicalDescriptorMap;
47 SamplerState g_PhysicalDescriptorMap_sampler;
48
49 Texture2DArray g_NormalMap;
50 SamplerState g_NormalMap_sampler;
5151
5252 #if GLTF_PBR_USE_AO
53 Texture2D g_AOMap;
54 SamplerState g_AOMap_sampler;
53 Texture2DArray g_AOMap;
54 SamplerState g_AOMap_sampler;
5555 #endif
5656
5757 #if GLTF_PBR_USE_EMISSIVE
58 Texture2D g_EmissiveMap;
59 SamplerState g_EmissiveMap_sampler;
58 Texture2DArray g_EmissiveMap;
59 SamplerState g_EmissiveMap_sampler;
6060 #endif
6161
6262 float2 GetTextureUV(in float2 UV0, in float2 UV1, float Selector, float4 ScaleBias)
8181 out float4 OutColor : SV_Target)
8282 {
8383 float2 BaseColorUV = GetTextureUV(UV0, UV1, g_MaterialInfo.BaseColorTextureUVSelector, g_MaterialInfo.BaseColorUVScaleBias);
84 float4 BaseColor = g_ColorMap.Sample(g_ColorMap_sampler, BaseColorUV);
84 float4 BaseColor = g_ColorMap.Sample(g_ColorMap_sampler, float3(BaseColorUV, g_MaterialInfo.BaseColorSlice));
8585 BaseColor = SRGBtoLINEAR(BaseColor) * g_MaterialInfo.BaseColorFactor;
8686 //BaseColor *= getVertexColor();
8787
106106 discard;
107107 }
108108
109 float3 TSNormal = g_NormalMap.Sample(g_NormalMap_sampler, NormalMapUV).rgb * float3(2.0, 2.0, 2.0) - float3(1.0, 1.0, 1.0);
109 float3 TSNormal = g_NormalMap.Sample(g_NormalMap_sampler, float3(NormalMapUV, g_MaterialInfo.NormalSlice)).rgb * float3(2.0, 2.0, 2.0) - float3(1.0, 1.0, 1.0);
110110
111111 float Occlusion = 1.0;
112112 #if GLTF_PBR_USE_AO
113113 {
114114 float2 OcclusionUV = GetTextureUV(UV0, UV1, g_MaterialInfo.OcclusionTextureUVSelector, g_MaterialInfo.OcclusionUVScaleBias);
115 Occlusion = g_AOMap.Sample(g_AOMap_sampler, OcclusionUV).r;
115 Occlusion = g_AOMap.Sample(g_AOMap_sampler, float3(OcclusionUV, g_MaterialInfo.OcclusionSlice)).r;
116116 }
117117 #endif
118118
120120 #if GLTF_PBR_USE_EMISSIVE
121121 {
122122 float2 EmissiveUV = GetTextureUV(UV0, UV1, g_MaterialInfo.EmissiveTextureUVSelector, g_MaterialInfo.EmissiveUVScaleBias);
123 Emissive = g_EmissiveMap.Sample(g_EmissiveMap_sampler, EmissiveUV).rgb;
123 Emissive = g_EmissiveMap.Sample(g_EmissiveMap_sampler, float3(EmissiveUV, g_MaterialInfo.EmissiveSlice)).rgb;
124124 }
125125 #endif
126126
127127
128128 float2 PhysicalDescUV = GetTextureUV(UV0, UV1, g_MaterialInfo.PhysicalDescriptorTextureUVSelector, g_MaterialInfo.PhysicalDescriptorUVScaleBias);
129 float4 PhysicalDesc = g_PhysicalDescriptorMap.Sample(g_PhysicalDescriptorMap_sampler, PhysicalDescUV);
129 float4 PhysicalDesc = g_PhysicalDescriptorMap.Sample(g_PhysicalDescriptorMap_sampler, float3(PhysicalDescUV, g_MaterialInfo.PhysicalDescriptorSlice));
130130
131131 float metallic;
132132 if (g_MaterialInfo.Workflow == PBR_WORKFLOW_SPECULAR_GLOSINESS)
6767
6868 float OcclusionTextureUVSelector;
6969 float EmissiveTextureUVSelector;
70 float BaseColorSlice;
71 float PhysicalDescriptorSlice;
72
73 float NormalSlice;
74 float OcclusionSlice;
75 float EmissiveSlice;
7076 float MetallicFactor;
77
7178 float RoughnessFactor;
79 int UseAlphaMask;
80 float AlphaMaskCutoff;
81 float Dummy0;
7282
7383 // When texture atlas is used, UV scale and bias applied to
7484 // each texture coordinate set
7787 float4 NormalMapUVScaleBias;
7888 float4 OcclusionUVScaleBias;
7989 float4 EmissiveUVScaleBias;
80
81 int UseAlphaMask;
82 float AlphaMaskCutoff;
83 float Dummy0;
84 float Dummy1;
8590 };
8691 #ifdef CHECK_STRUCT_ALIGNMENT
8792 CHECK_STRUCT_ALIGNMENT(GLTFMaterialShaderInfo);
6767 "\n"
6868 " float OcclusionTextureUVSelector;\n"
6969 " float EmissiveTextureUVSelector;\n"
70 " float BaseColorSlice;\n"
71 " float PhysicalDescriptorSlice;\n"
72 "\n"
73 " float NormalSlice;\n"
74 " float OcclusionSlice;\n"
75 " float EmissiveSlice;\n"
7076 " float MetallicFactor;\n"
77 "\n"
7178 " float RoughnessFactor;\n"
79 " int UseAlphaMask; \n"
80 " float AlphaMaskCutoff;\n"
81 " float Dummy0;\n"
7282 "\n"
7383 " // When texture atlas is used, UV scale and bias applied to\n"
7484 " // each texture coordinate set\n"
7787 " float4 NormalMapUVScaleBias;\n"
7888 " float4 OcclusionUVScaleBias;\n"
7989 " float4 EmissiveUVScaleBias;\n"
80 "\n"
81 " int UseAlphaMask; \n"
82 " float AlphaMaskCutoff;\n"
83 " float Dummy0;\n"
84 " float Dummy1;\n"
8590 "};\n"
8691 "#ifdef CHECK_STRUCT_ALIGNMENT\n"
8792 " CHECK_STRUCT_ALIGNMENT(GLTFMaterialShaderInfo);\n"
4040 "SamplerState g_BRDF_LUT_sampler;\n"
4141 "#endif\n"
4242 "\n"
43 "Texture2D g_ColorMap;\n"
44 "SamplerState g_ColorMap_sampler;\n"
45 "\n"
46 "Texture2D g_PhysicalDescriptorMap;\n"
47 "SamplerState g_PhysicalDescriptorMap_sampler;\n"
48 "\n"
49 "Texture2D g_NormalMap;\n"
50 "SamplerState g_NormalMap_sampler;\n"
43 "Texture2DArray g_ColorMap;\n"
44 "SamplerState g_ColorMap_sampler;\n"
45 "\n"
46 "Texture2DArray g_PhysicalDescriptorMap;\n"
47 "SamplerState g_PhysicalDescriptorMap_sampler;\n"
48 "\n"
49 "Texture2DArray g_NormalMap;\n"
50 "SamplerState g_NormalMap_sampler;\n"
5151 "\n"
5252 "#if GLTF_PBR_USE_AO\n"
53 "Texture2D g_AOMap;\n"
54 "SamplerState g_AOMap_sampler;\n"
53 "Texture2DArray g_AOMap;\n"
54 "SamplerState g_AOMap_sampler;\n"
5555 "#endif\n"
5656 "\n"
5757 "#if GLTF_PBR_USE_EMISSIVE\n"
58 "Texture2D g_EmissiveMap;\n"
59 "SamplerState g_EmissiveMap_sampler;\n"
58 "Texture2DArray g_EmissiveMap;\n"
59 "SamplerState g_EmissiveMap_sampler;\n"
6060 "#endif\n"
6161 "\n"
6262 "float2 GetTextureUV(in float2 UV0, in float2 UV1, float Selector, float4 ScaleBias)\n"
8181 " out float4 OutColor : SV_Target)\n"
8282 "{\n"
8383 " float2 BaseColorUV = GetTextureUV(UV0, UV1, g_MaterialInfo.BaseColorTextureUVSelector, g_MaterialInfo.BaseColorUVScaleBias);\n"
84 " float4 BaseColor = g_ColorMap.Sample(g_ColorMap_sampler, BaseColorUV);\n"
84 " float4 BaseColor = g_ColorMap.Sample(g_ColorMap_sampler, float3(BaseColorUV, g_MaterialInfo.BaseColorSlice));\n"
8585 " BaseColor = SRGBtoLINEAR(BaseColor) * g_MaterialInfo.BaseColorFactor;\n"
8686 " //BaseColor *= getVertexColor();\n"
8787 "\n"
106106 " discard;\n"
107107 " }\n"
108108 "\n"
109 " float3 TSNormal = g_NormalMap.Sample(g_NormalMap_sampler, NormalMapUV).rgb * float3(2.0, 2.0, 2.0) - float3(1.0, 1.0, 1.0);\n"
109 " float3 TSNormal = g_NormalMap.Sample(g_NormalMap_sampler, float3(NormalMapUV, g_MaterialInfo.NormalSlice)).rgb * float3(2.0, 2.0, 2.0) - float3(1.0, 1.0, 1.0);\n"
110110 "\n"
111111 " float Occlusion = 1.0;\n"
112112 "#if GLTF_PBR_USE_AO\n"
113113 " {\n"
114114 " float2 OcclusionUV = GetTextureUV(UV0, UV1, g_MaterialInfo.OcclusionTextureUVSelector, g_MaterialInfo.OcclusionUVScaleBias);\n"
115 " Occlusion = g_AOMap.Sample(g_AOMap_sampler, OcclusionUV).r;\n"
115 " Occlusion = g_AOMap.Sample(g_AOMap_sampler, float3(OcclusionUV, g_MaterialInfo.OcclusionSlice)).r;\n"
116116 " }\n"
117117 "#endif\n"
118118 "\n"
120120 "#if GLTF_PBR_USE_EMISSIVE\n"
121121 " {\n"
122122 " float2 EmissiveUV = GetTextureUV(UV0, UV1, g_MaterialInfo.EmissiveTextureUVSelector, g_MaterialInfo.EmissiveUVScaleBias);\n"
123 " Emissive = g_EmissiveMap.Sample(g_EmissiveMap_sampler, EmissiveUV).rgb;\n"
123 " Emissive = g_EmissiveMap.Sample(g_EmissiveMap_sampler, float3(EmissiveUV, g_MaterialInfo.EmissiveSlice)).rgb;\n"
124124 " }\n"
125125 "#endif\n"
126126 "\n"
127127 "\n"
128128 " float2 PhysicalDescUV = GetTextureUV(UV0, UV1, g_MaterialInfo.PhysicalDescriptorTextureUVSelector, g_MaterialInfo.PhysicalDescriptorUVScaleBias);\n"
129 " float4 PhysicalDesc = g_PhysicalDescriptorMap.Sample(g_PhysicalDescriptorMap_sampler, PhysicalDescUV);\n"
129 " float4 PhysicalDesc = g_PhysicalDescriptorMap.Sample(g_PhysicalDescriptorMap_sampler, float3(PhysicalDescUV, g_MaterialInfo.PhysicalDescriptorSlice));\n"
130130 " \n"
131131 " float metallic;\n"
132132 " if (g_MaterialInfo.Workflow == PBR_WORKFLOW_SPECULAR_GLOSINESS)\n"