11package engine .render ;
22
3+ import engine .resources .Texture ;
34import math .Color ;
45import workspace .ui .Graphics ;
56
@@ -67,6 +68,10 @@ public class Material {
6768 /** Shininess factor for specular highlights. */
6869 private final float shininess ;
6970
71+ private Texture normalTexture ;
72+
73+ private Texture diffuseTexture ;
74+
7075 /**
7176 * Constructor to set the base color of the material.
7277 *
@@ -83,11 +88,13 @@ private Material(Builder builder) {
8388 this .diffuse = builder .diffuse ;
8489 this .specular = builder .specular ;
8590 this .shininess = builder .shininess ;
91+ this .normalTexture = builder .normalTexture ;
92+ this .diffuseTexture = builder .diffuseTexture ;
8693 }
8794
8895 /**
89- * Builder class to facilitate the creation of custom materials with specific lighting and shader
90- * properties.
96+ * Builder class to facilitate the creation of custom materials with specific lighting, shader and
97+ * texture properties.
9198 */
9299 public static class Builder {
93100
@@ -103,6 +110,10 @@ public static class Builder {
103110
104111 private float shininess = 10.0f ;
105112
113+ private Texture diffuseTexture = null ;
114+
115+ private Texture normalTexture = null ;
116+
106117 /**
107118 * Sets the base color of the material.
108119 *
@@ -163,6 +174,28 @@ public Builder setUseLighting(boolean useLighting) {
163174 return this ;
164175 }
165176
177+ /**
178+ * Sets the normal texture of the material.
179+ *
180+ * @param normalTexture The normal texture, can be null
181+ * @return The builder instance for chaining
182+ */
183+ public Builder setNormalTexture (Texture normalTexture ) {
184+ this .normalTexture = normalTexture ;
185+ return this ;
186+ }
187+
188+ /**
189+ * Sets the diffuse texture of the material.
190+ *
191+ * @param diffuseTexture The diffuse texture, can be null.
192+ * @return The builder instance for chaining
193+ */
194+ public Builder setDiffuseTexture (Texture diffuseTexture ) {
195+ this .diffuseTexture = diffuseTexture ;
196+ return this ;
197+ }
198+
166199 /**
167200 * Builds and returns the Material instance with the set properties.
168201 *
@@ -180,6 +213,13 @@ public Material build() {
180213 */
181214 public void apply (Graphics g ) {
182215 g .setMaterial (this );
216+
217+ if (diffuseTexture != null ) {
218+ g .bindTexture (diffuseTexture , 0 ); // Bind to texture unit 0
219+ }
220+ if (normalTexture != null ) {
221+ g .bindTexture (normalTexture , 1 ); // Bind to texture unit 1
222+ }
183223 }
184224
185225 /**
@@ -240,4 +280,12 @@ public float[] getSpecular() {
240280 public float getShininess () {
241281 return shininess ;
242282 }
283+
284+ public Texture getDiffuseTexture () {
285+ return diffuseTexture ;
286+ }
287+
288+ public Texture getNormalTexture () {
289+ return normalTexture ;
290+ }
243291}
0 commit comments