@@ -51,7 +51,7 @@ option MaxLightCount: u32 = 3;
5151const HasNormal = (VertexNormalLoc != InvalidLoc);
5252const HasVertexColor = (VertexColorLoc != InvalidLoc);
5353const HasColor = (HasVertexColor || Billboard);
54- const HasTangent = (VertexTangentLoc != InvalidLoc);
54+ const HasTangent = (VertexTangentLoc != InvalidLoc && false );
5555const HasUV = (VertexUvLoc != InvalidLoc);
5656const HasNormalMapping = HasNormalTexture && HasNormal && HasTangent && !DepthPass;
5757const HasSkinning = (VertexJointIndicesLoc != InvalidLoc && VertexJointWeightsLoc != InvalidLoc);
@@ -141,10 +141,30 @@ fn ComputeColor(input: VertOut) -> vec4[f32]
141141 color *= input.color;
142142
143143 const if (HasBaseColorTexture)
144- color *= MaterialBaseColorMap.Sample(input.uv);
144+ {
145+ // Triplanar mapping
146+ let x = MaterialBaseColorMap.Sample(vec3[f32](input.worldPos.yz, input.uv.z));
147+ let y = MaterialBaseColorMap.Sample(vec3[f32](input.worldPos.zx, input.uv.z));
148+ let z = MaterialBaseColorMap.Sample(vec3[f32](input.worldPos.xy, input.uv.z));
149+
150+ let m = pow(abs(input.normal), (4.0).xxx);
151+ let textureColor = (x*m.x + y*m.y + z*m.z) / (m.x + m.y + m.z);
152+
153+ color *= textureColor;
154+ }
145155
146156 const if (HasAlphaTexture)
147- color.w *= MaterialAlphaMap.Sample(input.uv).x;
157+ {
158+ // Triplanar mapping
159+ let x = MaterialAlphaMap.Sample(vec3[f32](input.worldPos.yz, input.uv.z));
160+ let y = MaterialAlphaMap.Sample(vec3[f32](input.worldPos.zx, input.uv.z));
161+ let z = MaterialAlphaMap.Sample(vec3[f32](input.worldPos.xy, input.uv.z));
162+
163+ let m = pow(abs(input.normal), (4.0).xxx);
164+ let textureColor = (x*m.x + y*m.y + z*m.z) / (m.x + m.y + m.z);
165+
166+ color.w *= textureColor.x;
167+ }
148168
149169 const if (AlphaTest)
150170 {
@@ -162,6 +182,8 @@ fn ComputeLighting(color: vec3[f32], input: VertOut) -> vec3[f32]
162182
163183 let eyeVec = normalize(viewerData.eyePosition - input.worldPos);
164184
185+ let uv = input.uv;
186+
165187 let normal: vec3[f32];
166188 const if (HasNormalMapping)
167189 {
@@ -170,7 +192,7 @@ fn ComputeLighting(color: vec3[f32], input: VertOut) -> vec3[f32]
170192 let B = cross(N, T);
171193 let tbnMatrix = mat3[f32](T, B, N);
172194
173- normal = (MaterialNormalMap.Sample(input. uv).xyz * 2.0 - (1.0).rrr);
195+ normal = (MaterialNormalMap.Sample(uv).xyz * 2.0 - (1.0).rrr);
174196 normal = normalize(tbnMatrix * normal);
175197 }
176198 else
@@ -182,16 +204,16 @@ fn ComputeLighting(color: vec3[f32], input: VertOut) -> vec3[f32]
182204
183205 const if (HasDetailTexture)
184206 {
185- let detail = MaterialDetailMap.Sample(input. uv).rgb;
207+ let detail = MaterialDetailMap.Sample(uv).rgb;
186208 roughness = 1.0 - detail.r;
187209 metallic = detail.y;
188210 }
189211
190212 const if (HasMetallicTexture)
191- metallic = MaterialMetallicMap.Sample(input. uv).x;
213+ metallic = MaterialMetallicMap.Sample(uv).x;
192214
193215 const if (HasRoughnessTexture)
194- roughness = MaterialRoughnessMap.Sample(input. uv).x;
216+ roughness = MaterialRoughnessMap.Sample(uv).x;
195217
196218 let F0 = vec3[f32](0.04, 0.04, 0.04);
197219 F0 = albedo * metallic + F0 * (1.0 - metallic);
0 commit comments