@@ -48,91 +48,147 @@ namespace MitsubaLoader
48
48
using shape_ass_type = core::smart_refctd_ptr<asset::ICPUMesh>;
49
49
core::map<const CElementShape*, shape_ass_type> shapeCache;
50
50
// image, sampler
51
- using tex_ass_type = std::tuple<core::smart_refctd_ptr<asset::ICPUImageView>, core::smart_refctd_ptr<asset::ICPUSampler>>;
51
+ using tex_ass_type = std::tuple<core::smart_refctd_ptr<asset::ICPUImageView>,core::smart_refctd_ptr<asset::ICPUSampler>>;
52
52
// image, scale
53
- core::map<core::smart_refctd_ptr<asset::ICPUImage>, float > derivMapCache;
53
+ core::map<core::smart_refctd_ptr<asset::ICPUImage>,float > derivMapCache;
54
54
55
- static std::string blendWeightImageCacheKey (const CElementTexture* bitmap)
56
- {
57
- using namespace std ::string_literals;
58
- return bitmap->bitmap .filename .svalue + " ?blend" s;
59
- }
60
-
61
- static std::string imageViewCacheKey (const std::string& imageCacheKey)
55
+ //
56
+ enum E_IMAGE_VIEW_SEMANTIC : uint8_t
62
57
{
63
- return imageCacheKey + " ?view" ;
64
- }
65
-
66
- static std::string derivMapCacheKey (const CElementTexture* bitmap, bool wasNormal)
58
+ EIVS_IDENTITIY,
59
+ EIVS_BLEND_WEIGHT,
60
+ EIVS_NORMAL_MAP,
61
+ EIVS_BUMP_MAP,
62
+ EIVS_COUNT
63
+ };
64
+ static std::string imageViewCacheKey (const CElementTexture::Bitmap& bitmap, const E_IMAGE_VIEW_SEMANTIC semantic)
67
65
{
68
- using namespace std ::string_literals ;
69
- static const char * wrap[ 5 ]
66
+ std::string key = bitmap. filename . svalue ;
67
+ switch (bitmap. channel )
70
68
{
71
- " ?repeat" ,
72
- " ?mirror" ,
73
- " ?clamp" ,
74
- " ?zero" ,
75
- " ?one"
76
- };
77
-
78
- std::string key = bitmap->bitmap .filename .svalue + " ?deriv" s;
79
- key += wasNormal ? " ?n" s:" ?h" s;
80
- key += wrap[bitmap->bitmap .wrapModeU ];
81
- key += wrap[bitmap->bitmap .wrapModeV ];
82
-
69
+ case CElementTexture::Bitmap::CHANNEL::R:
70
+ key += " ?rrrr" ;
71
+ break ;
72
+ case CElementTexture::Bitmap::CHANNEL::G:
73
+ key += " ?gggg" ;
74
+ break ;
75
+ case CElementTexture::Bitmap::CHANNEL::B:
76
+ key += " ?bbbb" ;
77
+ break ;
78
+ case CElementTexture::Bitmap::CHANNEL::A:
79
+ key += " ?aaaa" ;
80
+ break ;
81
+ default :
82
+ break ;
83
+ }
84
+ switch (semantic)
85
+ {
86
+ case EIVS_BLEND_WEIGHT:
87
+ key += " ?blend" ;
88
+ break ;
89
+ case EIVS_NORMAL_MAP:
90
+ key += " ?deriv?n" ;
91
+ break ;
92
+ case EIVS_BUMP_MAP:
93
+ key += " ?deriv?h" ;
94
+ {
95
+ static const char * wrap[5 ]
96
+ {
97
+ " ?repeat" ,
98
+ " ?mirror" ,
99
+ " ?clamp" ,
100
+ " ?zero" ,
101
+ " ?one"
102
+ };
103
+ key += wrap[bitmap.wrapModeU ];
104
+ key += wrap[bitmap.wrapModeV ];
105
+ }
106
+ break ;
107
+ default :
108
+ break ;
109
+ }
110
+ key += " ?view" ;
83
111
return key;
84
112
}
85
113
86
- static std::string derivMapViewCacheKey (const CElementTexture* bitmap, bool wasNormal )
114
+ static auto computeSamplerParameters (const CElementTexture::Bitmap& bitmap)
87
115
{
88
- return imageViewCacheKey (derivMapCacheKey (bitmap,wasNormal));
89
- }
90
-
91
- static std::string blendWeightViewCacheKey (const CElementTexture* bitmap)
92
- {
93
- return imageViewCacheKey (blendWeightImageCacheKey (bitmap));
116
+ asset::ICPUSampler::SParams params;
117
+ auto getWrapMode = [](CElementTexture::Bitmap::WRAP_MODE mode)
118
+ {
119
+ switch (mode)
120
+ {
121
+ case CElementTexture::Bitmap::WRAP_MODE::CLAMP:
122
+ return asset::ISampler::ETC_CLAMP_TO_EDGE;
123
+ break ;
124
+ case CElementTexture::Bitmap::WRAP_MODE::MIRROR:
125
+ return asset::ISampler::ETC_MIRROR;
126
+ break ;
127
+ case CElementTexture::Bitmap::WRAP_MODE::ONE:
128
+ _NBL_DEBUG_BREAK_IF (true ); // TODO : replace whole texture?
129
+ break ;
130
+ case CElementTexture::Bitmap::WRAP_MODE::ZERO:
131
+ _NBL_DEBUG_BREAK_IF (true ); // TODO : replace whole texture?
132
+ break ;
133
+ default :
134
+ break ;
135
+ }
136
+ return asset::ISampler::ETC_REPEAT;
137
+ };
138
+ params.TextureWrapU = getWrapMode (bitmap.wrapModeU );
139
+ params.TextureWrapV = getWrapMode (bitmap.wrapModeV );
140
+ params.TextureWrapW = asset::ISampler::ETC_REPEAT;
141
+ params.BorderColor = asset::ISampler::ETBC_FLOAT_OPAQUE_BLACK;
142
+ switch (bitmap.filterType )
143
+ {
144
+ case CElementTexture::Bitmap::FILTER_TYPE::EWA:
145
+ [[fallthrough]]; // we dont support this fancy stuff
146
+ case CElementTexture::Bitmap::FILTER_TYPE::TRILINEAR:
147
+ params.MinFilter = asset::ISampler::ETF_LINEAR;
148
+ params.MaxFilter = asset::ISampler::ETF_LINEAR;
149
+ params.MipmapMode = asset::ISampler::ESMM_LINEAR;
150
+ break ;
151
+ default :
152
+ params.MinFilter = asset::ISampler::ETF_NEAREST;
153
+ params.MaxFilter = asset::ISampler::ETF_NEAREST;
154
+ params.MipmapMode = asset::ISampler::ESMM_NEAREST;
155
+ break ;
156
+ }
157
+ params.AnisotropicFilter = core::max (core::findMSB<uint32_t >(bitmap.maxAnisotropy ),1u );
158
+ params.CompareEnable = false ;
159
+ params.CompareFunc = asset::ISampler::ECO_NEVER;
160
+ params.LodBias = 0 .f ;
161
+ params.MaxLod = 10000 .f ;
162
+ params.MinLod = 0 .f ;
163
+ return params;
94
164
}
95
-
96
- static std::string samplerCacheKey (const std::string& base, const CElementTexture* tex )
165
+ // TODO: commonalize this to all loaders
166
+ static std::string samplerCacheKey (const std::string& base, const asset::ICPUSampler::SParams& samplerParams )
97
167
{
98
168
std::string samplerCacheKey = base;
99
169
100
- switch (tex->bitmap .filterType )
101
- {
102
- case CElementTexture::Bitmap::FILTER_TYPE::EWA:
103
- [[fallthrough]]; // not supported
104
- case CElementTexture::Bitmap::FILTER_TYPE::TRILINEAR:
170
+ if (samplerParams.MinFilter ==asset::ISampler::ETF_LINEAR)
105
171
samplerCacheKey += " ?trilinear" ;
106
- break ;
107
- default :
172
+ else
108
173
samplerCacheKey += " ?nearest" ;
109
- break ;
110
- }
111
174
112
- auto perWrapMode = [](CElementTexture::Bitmap::WRAP_MODE mode)
175
+ static const char * wrapModeName[] =
113
176
{
114
- switch (mode)
115
- {
116
- case CElementTexture::Bitmap::WRAP_MODE::CLAMP:
117
- return " ?clamp" ;
118
- case CElementTexture::Bitmap::WRAP_MODE::MIRROR:
119
- return " ?clamp" ;
120
- case CElementTexture::Bitmap::WRAP_MODE::ONE:
121
- return " ?one" ;
122
- case CElementTexture::Bitmap::WRAP_MODE::ZERO:
123
- return " ?zero" ;
124
- default :
125
- return " ?repeat" ;
126
- }
177
+ " ?repeat" ,
178
+ " ?clamp_to_edge" ,
179
+ " ?clamp_to_border" ,
180
+ " ?mirror" ,
181
+ " ?mirror_clamp_to_edge" ,
182
+ " ?mirror_clamp_to_border"
127
183
};
128
- samplerCacheKey += perWrapMode (tex-> bitmap . wrapModeU ) ;
129
- samplerCacheKey += perWrapMode (tex-> bitmap . wrapModeV ) ;
184
+ samplerCacheKey += wrapModeName[samplerParams. TextureWrapU ] ;
185
+ samplerCacheKey += wrapModeName[samplerParams. TextureWrapV ] ;
130
186
131
187
return samplerCacheKey;
132
188
}
133
- std::string samplerCacheKey (const CElementTexture* tex ) const
189
+ std::string samplerCacheKey (const asset::ICPUSampler::SParams& samplerParams ) const
134
190
{
135
- return samplerCacheKey (samplerCacheKeyBase, tex );
191
+ return samplerCacheKey (samplerCacheKeyBase,samplerParams );
136
192
}
137
193
138
194
// index of root node in IR
0 commit comments