[DEV] set render of low poly start to work better

This commit is contained in:
Edouard DUPIN 2021-05-29 00:52:58 +02:00
parent 822d0357da
commit 4e0fa632c8
26 changed files with 666 additions and 375 deletions

View File

@ -5,14 +5,83 @@ precision mediump float;
precision mediump int; precision mediump int;
#endif #endif
in vec2 io_textureCoords; struct Light {
vec3 color;
vec3 position;
vec3 attenuation;
};
const int MAX_LIGHT_NUMBER = 8;
in vec2 io_textureCoords;
in vec3 io_surfaceNormal;
in vec3 io_toCameraVector;
in vec3 io_toLightVector[MAX_LIGHT_NUMBER];
// FOW: Fog Of War result calculation
in float io_fowVisibility;
// texture properties
uniform sampler2D in_textureBase; uniform sampler2D in_textureBase;
// Material
//uniform Material in_material;
// 2 light for suns and other for locals ...
uniform Light in_lights[MAX_LIGHT_NUMBER];
// global color of the sky ... needed to have a better color for the FOW
//uniform vec3 in_sky_color;
const vec3 in_sky_color = vec3(1.0,1.0,1.0);
// output: // output:
out vec4 out_Color; out vec4 out_Color;
void main(void) { void main(void) {
out_Color = texture(in_textureBase, io_textureCoords); // disable transparency elements in the texture ...
//out_Color = vec4(1,0,0,1); // Can be set at the start of the shader ...
/*
vec4 textureColour = texture(in_textureBase, io_textureCoords);
if (textureColour.a < 0.5) {
discard;
}
*/
//vec4 textureColour = vec4(1.0,1.0,1.0,1.0);
// keep material:
vec3 tex_ambientFactor = texture(in_textureBase, vec2(io_textureCoords.x, 4.5/8.0)).xyz;
//vec3 tex_diffuseFactor = texture(in_textureBase, vec2(io_textureCoords.x, 0.5/8.0)).xyz;
//vec4 textureColour = texture(in_textureBase, vec2(io_textureCoords.x, 0.5/8.0));
vec4 textureColour = texture(in_textureBase, io_textureCoords);
vec3 tex_specularFactor = texture(in_textureBase, vec2(io_textureCoords.x, 2.5/8.0)).xyz;
float tex_shininess = texture(in_textureBase, vec2(io_textureCoords.x, 6.5/8.0)).x;
vec3 unitNormal = normalize(io_surfaceNormal);
vec3 unitVectorToCamera = normalize(io_toCameraVector);
vec3 totalDiffuse = vec3(0.0);
vec3 totalSpecular = vec3(0.0);
for(int iii=0; iii<MAX_LIGHT_NUMBER; iii++) {
float distance = length(io_toLightVector[iii]);
float attenuationFactor = in_lights[iii].attenuation.x + (in_lights[iii].attenuation.y * distance) + (in_lights[iii].attenuation.z * distance * distance);
vec3 unitLightVector = normalize(io_toLightVector[iii]);
float nDot1 = dot(unitNormal, unitLightVector);
float brightness = max(nDot1, 0.0);
vec3 lightDirection = -unitLightVector;
vec3 reflectedLightDirection = reflect(lightDirection, unitNormal);
float specularFactor = dot(reflectedLightDirection, unitVectorToCamera);
specularFactor = max(specularFactor, 0.0);
float damperFactor = pow(specularFactor, tex_shininess);
vec3 diffuse = (brightness * in_lights[iii].color) / attenuationFactor;
vec3 finalSpecular = (damperFactor * tex_specularFactor.x * in_lights[iii].color) / attenuationFactor; // TODO: Remove the x ....
totalDiffuse = totalDiffuse + diffuse;
totalSpecular = totalSpecular + finalSpecular;
}
// the 0.2 represent the ambiant lightning ==> maybe set an uniform for this
//totalDiffuse = max(totalDiffuse, 1.0);
//totalDiffuse = min(totalDiffuse, 0.4);
//////out_Color = vec4(totalDiffuse,1.0) * textureColour + vec4(totalSpecular, 1.0);
out_Color = (vec4(totalDiffuse,1.0)*0.5+0.5) * textureColour;
/////out_Color = mix(vec4(in_sky_color,1.0), out_Color, io_fowVisibility);
} }

View File

@ -5,17 +5,55 @@ precision mediump float;
precision mediump int; precision mediump int;
#endif #endif
struct Light {
vec3 color;
vec3 position;
vec3 attenuation;
};
const int MAX_LIGHT_NUMBER = 8;
// Input: // Input:
layout (location = 0) in vec3 in_position; layout (location = 0) in vec3 in_position;
layout (location = 1) in vec2 in_textureCoords; layout (location = 1) in vec2 in_textureCoords;
layout (location = 2) in vec3 in_normal;
// 2 light for suns and other for locals ...
uniform Light in_lights[MAX_LIGHT_NUMBER];
uniform mat4 in_matrixTransformation; uniform mat4 in_matrixTransformation;
uniform mat4 in_matrixProjection; uniform mat4 in_matrixProjection;
uniform mat4 in_matrixView; uniform mat4 in_matrixView;
//uniform float in_numberOfRows;
//uniform vec2 in_offset;
const float in_numberOfRows = 1;
const vec2 in_offset = vec2(0.0,0.0);
// Configuration of the FOV ==> TODO: Set it in parameter uniform ...
const float c_density = 0.007;
const float c_gradient = 1.5;
// output: // output:
out vec2 io_textureCoords; out vec2 io_textureCoords;
out vec3 io_surfaceNormal;
out vec3 io_toCameraVector;
out vec3 io_toLightVector[MAX_LIGHT_NUMBER];
// FOW: Fog Of War result calculation
out float io_fowVisibility;
void main(void) { void main(void) {
gl_Position = in_matrixProjection * in_matrixView * in_matrixTransformation * vec4(in_position, 1.0); vec4 worldPosition = in_matrixTransformation * vec4(in_position, 1.0);
io_textureCoords = in_textureCoords; vec4 positionRelativeToCam = in_matrixView * worldPosition;
gl_Position = in_matrixProjection * positionRelativeToCam;
io_textureCoords = (in_textureCoords/in_numberOfRows) + in_offset;
io_surfaceNormal = (in_matrixTransformation * vec4(in_normal, 0.0)).xyz;
for(int iii=0;iii<MAX_LIGHT_NUMBER;iii++) {
io_toLightVector[iii] = in_lights[iii].position - worldPosition.xyz;
}
io_toCameraVector = (inverse(in_matrixView) * vec4(0.0,0.0,0.0,1.0)).xyz - worldPosition.xyz;
float distance = length(positionRelativeToCam.xyz);
io_fowVisibility = exp(-pow((distance*c_density),c_gradient));
io_fowVisibility = clamp(io_fowVisibility, 0.0, 1.0);
} }

View File

@ -20,6 +20,9 @@
"Kd":"0.800000 0.800000 0.800000" "Kd":"0.800000 0.800000 0.800000"
}, },
"trunk_1":{ "trunk_1":{
"Kd":"0.25 0.13 0.07"
},
"trunk_2":{
"Kd":"0.057805 0.039546 0.013702" "Kd":"0.057805 0.039546 0.013702"
} }
} }

View File

@ -0,0 +1,43 @@
EMF(STRING)
# Blender v2.92.0 EMF File: 'tree2.blend'
Mesh:Arbre_Normal_Mesh
Vertex:72
0.164861 0.283095 -0.182282|0.296594 0.102843 -0.182282|0.262285 -0.117765 -0.182282|0.082033 -0.249498 -0.182282|-0.140442 -0.257426 1.112208|-0.138575 -0.215189 -0.182282|-0.270308 -0.034936 -0.182282|-0.235999 0.185671 -0.182282|-0.055746 0.317404 -0.182282|0.004174 0.104880 0.626072|-0.070307 0.050448 0.626072|-0.084483 -0.040707 0.626072|-0.030051 -0.115188 0.626072|0.061105 -0.129365 0.626072|0.135585 -0.074932 0.626072|0.149762 0.016223 0.626072|0.095330 0.090704 0.626072|0.131783 0.228776 0.144384|0.234794 0.087823 0.144384|0.207966 -0.084686 0.144384|0.067013 -0.187698 0.144384|-0.105496 -0.160870 0.144384|-0.208508 -0.019917 0.144384|-0.181680 0.152592 0.144384|-0.040727 0.255604 0.144384|-0.233253 -0.213791 1.276952|0.796562 0.093071 2.045288|-0.079560 -0.072400 0.472328|0.263731 -0.671928 1.484988|-0.492027 -0.430949 1.858150|-0.464678 0.219195 1.688762|0.196689 0.558278 1.845816|0.752521 -0.090017 2.031457|0.039375 -0.591035 2.826299|-0.381645 -0.167964 3.106963|-0.175674 0.320591 3.129268|0.318578 0.203395 3.129268|0.522390 -0.403724 2.780408|0.049018 -0.132857 3.844571|-0.436419 -0.336556 1.061941|0.052607 -0.355632 0.624801|-0.185480 -0.768599 1.658063|0.534482 -0.253957 0.971040|0.397067 -0.064053 0.643590|-0.400966 0.185825 0.678289|-0.685105 -0.210238 2.072247|0.090083 0.282084 0.508441|-0.230477 0.532597 1.676011|0.554104 0.309080 1.745713|0.542760 -0.541603 2.117762|0.662662 -0.260909 2.386214|-0.201184 -0.545764 2.506993|0.173347 -0.652987 2.237929|-0.534110 -0.021396 2.510209|-0.465882 -0.318980 2.510209|-0.037923 0.443776 2.522092|-0.361786 0.320313 2.510694|0.640551 0.128032 2.510694|0.308340 0.396739 2.522089|0.385339 -0.589000 2.655612|-0.261979 -0.400722 3.209551|-0.303237 0.082070 3.212219|0.037654 0.366781 3.252412|0.460448 -0.099796 3.202400|0.057823 -0.406951 3.435973|0.341217 -0.296551 3.410657|-0.204117 -0.153493 3.645294|-0.097317 0.147076 3.663867|0.193195 0.078191 3.663867|0.499957 -1.411272 1.359687|0.317072 0.229824 1.921540|0.054495 0.984295 1.927069|
Normal(face):118
0.000000 -0.000000 -1.000000|-0.152617 -0.981339 0.116970|0.794618 0.580726 0.177029|0.972515 -0.151245 0.177029|0.580726 -0.794618 0.177030|-0.151245 -0.972515 0.177029|-0.794618 -0.580726 0.177030|-0.972515 0.151245 0.177029|0.151245 0.972515 0.177029|-0.580726 0.794618 0.177030|0.147398 0.947778 0.282827|0.976960 -0.151937 0.149879|0.586819 -0.802955 0.104437|-0.794264 -0.580467 0.179453|-0.956081 0.148689 0.252589|-0.563962 0.771680 0.294035|0.786787 0.575003 0.224362|-0.152618 -0.981339 0.116970|0.972515 -0.151245 0.177030|0.580726 -0.794618 0.177029|-0.151245 -0.972515 0.177030|-0.972515 0.151245 0.177030|-0.580726 0.794618 0.177029|0.976961 -0.151936 0.149879|-0.555364 -0.579988 -0.595974|0.457226 -0.792485 -0.403623|-0.698585 -0.392144 -0.598500|-0.361098 0.263925 -0.894400|0.338436 -0.066338 -0.938648|0.713955 -0.677917 -0.175204|-0.674831 -0.716762 0.175659|-0.857664 0.508498 0.076439|-0.110363 0.985539 0.128578|0.893993 0.448052 0.005014|0.306181 -0.950039 0.060654|-0.641707 -0.751181 0.154721|-0.891502 0.449505 0.056301|0.131612 0.968867 0.209701|0.971478 -0.020385 0.236253|0.144704 -0.948441 0.281992|-0.895095 -0.326221 0.303949|-0.799039 0.527619 0.288365|0.576149 0.755431 0.312051|0.922569 -0.235898 0.305319|-0.770834 -0.624081 -0.127823|-0.405608 -0.812724 -0.418286|0.062587 -0.931647 -0.357934|0.933424 0.271984 -0.233976|0.544543 -0.605934 -0.579928|0.324692 -0.326377 -0.887724|-0.911698 0.404706 -0.070849|-0.968964 -0.100206 -0.225981|-0.803705 -0.581730 -0.125098|0.022211 0.978740 -0.203900|-0.275219 0.921710 -0.273324|-0.800436 0.595302 -0.070128|0.926984 0.294829 -0.231899|0.768782 0.564439 -0.300637|0.518155 0.828492 -0.212404|0.861560 -0.491080 0.128665|0.943484 -0.319788 -0.087027|0.808719 -0.583250 -0.076115|-0.243949 -0.968675 0.046448|-0.095389 -0.963255 0.251080|0.229197 -0.971992 0.051965|-0.956844 -0.219379 0.190583|-0.894652 -0.205120 0.396892|-0.666071 -0.730216 0.152097|-0.357453 0.927766 0.107131|-0.356011 0.917500 0.177341|-0.800245 0.599089 0.026474|0.616860 0.752916 0.229350|0.627266 0.770777 0.111535|0.587125 0.803892 0.095090|0.064549 -0.990791 0.119021|0.288718 -0.957414 0.000133|0.739582 -0.654059 0.158827|-0.903564 -0.367352 0.220508|-0.646653 -0.756180 0.100155|-0.378320 -0.912496 0.155646|-0.816738 0.522177 0.245500|-0.870792 0.438826 0.221705|-0.942523 0.175999 0.284032|0.564843 0.789002 0.241718|0.134056 0.986863 0.090168|-0.280573 0.951083 0.129303|0.945324 -0.182563 0.270246|0.969312 -0.023224 0.244736|0.807100 0.465318 0.363411|0.348922 -0.774768 0.527246|0.366741 -0.860105 0.354572|0.655280 -0.690710 0.305823|-0.343921 -0.783210 0.517978|-0.366167 -0.787647 0.495513|-0.222040 -0.931538 0.287986|-0.617951 0.172171 0.767133|-0.885349 0.292244 0.361594|-0.937867 0.165784 0.304829|0.139289 0.587426 0.797201|0.198256 0.836106 0.511490|-0.380275 0.861884 0.335479|0.816006 -0.065729 0.574295|0.866067 0.004307 0.499910|0.832741 0.462919 0.303724|
Face:118
palette:trunk_1
3/0 6/0 8/0| 20/1 12/1 21/1| 17/2 1/2 0/2| 18/3 2/3 1/3| 19/4 3/4 2/4| 20/5 5/5 3/5| 21/6 6/6 5/6| 22/7 7/7 6/7| 24/8 0/8 8/8| 23/9 8/9 7/9| 17/10 9/10 16/10| 19/11 15/11 14/11| 20/12 14/12 13/12| 21/13 11/13 22/13| 22/14 10/14 23/14| 23/15 9/15 24/15| 18/16 16/16 15/16| 8/0 0/0 3/0| 0/0 1/0 3/0| 1/0 2/0 3/0| 3/0 5/0 6/0| 6/0 7/0 8/0| 20/17 13/17 12/17| 17/2 18/2 1/2| 18/18 19/18 2/18| 19/19 20/19 3/19| 20/20 21/20 5/20| 21/6 22/6 6/6| 22/21 23/21 7/21| 24/8 17/8 0/8| 23/22 24/22 8/22| 17/10 24/10 9/10| 19/23 18/23 15/23| 20/12 19/12 14/12| 21/13 12/13 11/13| 22/14 11/14 10/14| 23/15 10/15 9/15| 18/16 17/16 16/16|
palette:leaf_1
27/24 40/24 39/24| 28/25 40/25 42/25| 27/26 39/26 44/26| 27/27 44/27 46/27| 27/28 46/28 43/28| 28/29 42/29 49/29| 29/30 41/30 51/30| 30/31 45/31 53/31| 31/32 47/32 55/32| 32/33 48/33 57/33| 28/34 49/34 52/34| 29/35 51/35 54/35| 30/36 53/36 56/36| 31/37 55/37 58/37| 32/38 57/38 50/38| 33/39 59/39 64/39| 34/40 60/40 66/40| 35/41 61/41 67/41| 36/42 62/42 68/42| 37/43 63/43 65/43| 39/44 41/44 29/44| 39/45 40/45 41/45| 40/46 28/46 41/46| 42/47 43/47 32/47| 42/48 40/48 43/48| 40/49 27/49 43/49| 44/50 45/50 30/50| 44/51 39/51 45/51| 39/52 29/52 45/52| 46/53 47/53 31/53| 46/54 44/54 47/54| 44/55 30/55 47/55| 43/56 48/56 32/56| 43/57 46/57 48/57| 46/58 31/58 48/58| 49/59 50/59 37/59| 49/60 42/60 50/60| 42/61 32/61 50/61| 51/62 52/62 33/62| 51/63 41/63 52/63| 41/64 28/64 52/64| 53/65 54/65 34/65| 53/66 45/66 54/66| 45/67 29/67 54/67| 55/68 56/68 35/68| 55/69 47/69 56/69| 47/70 30/70 56/70| 57/71 58/71 36/71| 57/72 48/72 58/72| 48/73 31/73 58/73| 52/74 59/74 33/74| 52/75 49/75 59/75| 49/76 37/76 59/76| 54/77 60/77 34/77| 54/78 51/78 60/78| 51/79 33/79 60/79| 56/80 61/80 35/80| 56/81 53/81 61/81| 53/82 34/82 61/82| 58/83 62/83 36/83| 58/84 55/84 62/84| 55/85 35/85 62/85| 50/86 63/86 37/86| 50/87 57/87 63/87| 57/88 36/88 63/88| 64/89 65/89 38/89| 64/90 59/90 65/90| 59/91 37/91 65/91| 66/92 64/92 38/92| 66/93 60/93 64/93| 60/94 33/94 64/94| 67/95 66/95 38/95| 67/96 61/96 66/96| 61/97 34/97 66/97| 68/98 67/98 38/98| 68/99 62/99 67/99| 62/100 35/100 67/100| 65/101 68/101 38/101| 65/102 63/102 68/102| 63/103 36/103 68/103|
Physics:
Cylinder
radius:0.25
size:2.0
origin:0.0117903 0.0311268 0.962411
mass:6.25
Sphere
radius:1.3350000381469727
origin:-0.093534 -0.0233787 2.81849
mass:237.92705789594712
# Just for information:
Palettes:leaf_1
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.346704 0.558341 0.090842
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
vNi 1.000000
d 1.000000
illum 2
# Just for information:
Palettes:trunk_1
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.057805 0.039546 0.013702
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
vNi 1.000000
d 1.000000
illum 2

Binary file not shown.

View File

@ -9,12 +9,10 @@ import org.atriasoft.ege.Material;
import org.atriasoft.ege.camera.Camera; import org.atriasoft.ege.camera.Camera;
import org.atriasoft.ege.components.ComponentLight; import org.atriasoft.ege.components.ComponentLight;
import org.atriasoft.ege.components.ComponentLightSun; import org.atriasoft.ege.components.ComponentLightSun;
import org.atriasoft.ege.components.ComponentMaterial;
import org.atriasoft.ege.components.ComponentMesh; import org.atriasoft.ege.components.ComponentMesh;
import org.atriasoft.ege.components.ComponentPosition; import org.atriasoft.ege.components.ComponentPosition;
import org.atriasoft.ege.components.ComponentRenderColoredStaticMesh; import org.atriasoft.ege.components.ComponentRenderColoredStaticMesh;
import org.atriasoft.ege.components.ComponentRenderMeshPalette; import org.atriasoft.ege.components.ComponentRenderMeshPalette;
import org.atriasoft.ege.components.ComponentRenderTexturedMaterialsStaticMesh;
import org.atriasoft.ege.components.ComponentRenderTexturedStaticMesh; import org.atriasoft.ege.components.ComponentRenderTexturedStaticMesh;
import org.atriasoft.ege.components.ComponentStaticMesh; import org.atriasoft.ege.components.ComponentStaticMesh;
import org.atriasoft.ege.components.ComponentTexture; import org.atriasoft.ege.components.ComponentTexture;
@ -64,7 +62,7 @@ public class LowPolyApplication extends GaleApplication {
// simple sun to have a global light ... // simple sun to have a global light ...
final Entity sun = new Entity(this.env); final Entity sun = new Entity(this.env);
sun.addComponent(new ComponentPosition(new Transform3D(new Vector3f(1000, 1000, 1000)))); sun.addComponent(new ComponentPosition(new Transform3D(new Vector3f(1000, 1000, 1000))));
sun.addComponent(new ComponentLightSun(new Light(new Vector3f(0.4f, 0.4f, 0.4f), new Vector3f(0, 0, 0), new Vector3f(0.8f, 0, 0)))); sun.addComponent(new ComponentLightSun(new Light(new Color(1.0f, 1.0f, 1.0f), new Vector3f(0, 0, 0), new Vector3f(1.0f, 0, 0))));
this.env.addEntity(sun); this.env.addEntity(sun);
// add a cube to show where in the light ... // add a cube to show where in the light ...
@ -73,7 +71,7 @@ public class LowPolyApplication extends GaleApplication {
localLight.addComponent(this.lightPosition); localLight.addComponent(this.lightPosition);
localLight.addComponent(new ComponentStaticMesh(new Uri("DATA", "cube-one.obj"))); localLight.addComponent(new ComponentStaticMesh(new Uri("DATA", "cube-one.obj")));
localLight.addComponent(new ComponentTexture(new Uri("DATA", "grass.png"))); localLight.addComponent(new ComponentTexture(new Uri("DATA", "grass.png")));
localLight.addComponent(new ComponentLight(new Light(new Vector3f(0, 2, 0), new Vector3f(0, 0, 0), new Vector3f(0.8f, 0.01f, 0.002f)))); localLight.addComponent(new ComponentLight(new Light(new Color(0.0f, 0.0f, 2.0f), new Vector3f(0, 0, 0), new Vector3f(0.8f, 0.01f, 0.002f))));
localLight.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "loxelEngine"), new Uri("DATA", "basic.frag", "loxelEngine"))); localLight.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "loxelEngine"), new Uri("DATA", "basic.frag", "loxelEngine")));
this.env.addEntity(localLight); this.env.addEntity(localLight);
@ -85,19 +83,31 @@ public class LowPolyApplication extends GaleApplication {
this.env.addEntity(gird); this.env.addEntity(gird);
// test entity // test entity
final Entity basicTree = new Entity(this.env); Entity basicTree = new Entity(this.env);
this.objectPosition = new ComponentPosition(new Transform3D(new Vector3f(0, 0, 0))); this.objectPosition = new ComponentPosition(new Transform3D(new Vector3f(0, 0, 0)));
basicTree.addComponent(this.objectPosition); basicTree.addComponent(this.objectPosition);
//this.materialCube = new Material(); //this.materialCube = new Material();
//basicTree.addComponent(new ComponentMaterial(this.materialCube)); //basicTree.addComponent(new ComponentMaterial(this.materialCube));
basicTree.addComponent(new ComponentMesh(new Uri("DATA", "tree1.emf"))); basicTree.addComponent(new ComponentMesh(new Uri("DATA", "tree1.emf")));
//basicTree.addComponent(new ComponentMesh(new Uri("DATA", "simple3D.emf")));
//basicTree.addComponent(new ComponentTexture(new Uri("RES", "mud.png")));
basicTree.addComponent(new ComponentTexturePalette(new Uri("DATA", "palette_1.json"))); basicTree.addComponent(new ComponentTexturePalette(new Uri("DATA", "palette_1.json")));
//basicTree.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "loxelEngine"), new Uri("DATA", "basic.frag", "loxelEngine"))); //basicTree.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "loxelEngine"), new Uri("DATA", "basic.frag", "loxelEngine")));
basicTree.addComponent(new ComponentRenderMeshPalette(new Uri("DATA", "basicPalette.vert"), new Uri("DATA", "basicPalette.frag"))); basicTree.addComponent(new ComponentRenderMeshPalette(new Uri("DATA", "basicPalette.vert"), new Uri("DATA", "basicPalette.frag"),
(EngineLight) this.env.getEngine(EngineLight.ENGINE_NAME)));
this.env.addEntity(basicTree); this.env.addEntity(basicTree);
basicTree = new Entity(this.env);
this.objectPosition = new ComponentPosition(new Transform3D(new Vector3f(3, 2, 0)));
basicTree.addComponent(this.objectPosition);
//this.materialCube = new Material();
//basicTree.addComponent(new ComponentMaterial(this.materialCube));
basicTree.addComponent(new ComponentMesh(new Uri("DATA", "tree2.emf")));
basicTree.addComponent(new ComponentTexturePalette(new Uri("DATA", "palette_1.json")));
//basicTree.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "loxelEngine"), new Uri("DATA", "basic.frag", "loxelEngine")));
basicTree.addComponent(new ComponentRenderMeshPalette(new Uri("DATA", "basicPalette.vert"), new Uri("DATA", "basicPalette.frag"),
(EngineLight) this.env.getEngine(EngineLight.ENGINE_NAME)));
this.env.addEntity(basicTree);
// for (int xxx = -10; xxx < 10; xxx++) { // for (int xxx = -10; xxx < 10; xxx++) {
// for (int yyy = -10; yyy < 10; yyy++) { // for (int yyy = -10; yyy < 10; yyy++) {
// final Entity superGrass = new Entity(this.env); // final Entity superGrass = new Entity(this.env);

View File

@ -1,38 +1,44 @@
package org.atriasoft.ege; package org.atriasoft.ege;
import org.atriasoft.etk.Color;
import org.atriasoft.etk.math.Vector3f; import org.atriasoft.etk.math.Vector3f;
public class Light { public class Light {
private Vector3f color; private Color color;
// A light is linked with an entity, then the entity position the object and the light have a relative position with the entity // A light is linked with an entity, then the entity position the object and the light have a relative position with the entity
private Vector3f positionDelta; private Vector3f positionDelta;
private Vector3f attenuation; private Vector3f attenuation;
public Light(Vector3f color, Vector3f positionDelta, Vector3f attenuation) { public Light(final Color color, final Vector3f positionDelta, final Vector3f attenuation) {
this.color = color; this.color = color;
this.positionDelta = positionDelta; this.positionDelta = positionDelta;
this.attenuation = attenuation; this.attenuation = attenuation;
} }
public Light() { public Light() {
this.color = new Vector3f(1.0f,1.0f,1.0f); this.color = Color.WHITE;
this.positionDelta = new Vector3f(0.0f,0.0f,0.0f); this.positionDelta = Vector3f.ZERO;
this.attenuation = new Vector3f(0.0f,0.0f,0.0f);; this.attenuation = Vector3f.ZERO;
} }
public Vector3f getColor() { public Color getColor() {
return color; return this.color;
} }
public void setColor(Vector3f color) { public void setColor(final Color color) {
this.color = color; this.color = color;
} }
public Vector3f getPositionDelta() { public Vector3f getPositionDelta() {
return positionDelta; return this.positionDelta;
} }
public void setPositionDelta(Vector3f positionDelta) { public void setPositionDelta(final Vector3f positionDelta) {
this.positionDelta = positionDelta; this.positionDelta = positionDelta;
} }
public Vector3f getAttenuation() { public Vector3f getAttenuation() {
return attenuation; return this.attenuation;
} }
public void setAttenuation(Vector3f attenuation) { public void setAttenuation(final Vector3f attenuation) {
this.attenuation = attenuation; this.attenuation = attenuation;
} }
@Override
public String toString() {
return "Light [color=" + this.color + ", positionDelta=" + this.positionDelta + ", attenuation=" + this.attenuation + "]";
}
} }

View File

@ -2,31 +2,26 @@ package org.atriasoft.ege.components;
import org.atriasoft.ege.Component; import org.atriasoft.ege.Component;
import org.atriasoft.ege.Light; import org.atriasoft.ege.Light;
import org.atriasoft.ege.components.part.PositionningInterface;
import org.atriasoft.etk.math.Vector3f; import org.atriasoft.etk.math.Vector3f;
public class ComponentLight extends Component { public class ComponentLight extends Component {
// the material is not a resource, it can change in time... with AI or selection... // the material is not a resource, it can change in time... with AI or selection...
private final Light light; private final Light light;
private ComponentPosition position; private PositionningInterface position = null;
private ComponentPhysics playerPhysics = null;
public ComponentLight() { public ComponentLight() {
super();
this.light = new Light(); this.light = new Light();
} }
public ComponentLight(final Light light) { public ComponentLight(final Light light) {
super();
this.light = light; this.light = light;
} }
@Override @Override
public void addFriendComponent(final Component component) { public void addFriendComponent(final Component component) {
if (component.getType().contentEquals("position")) { if (component.getType().contentEquals("position") || component.getType().contentEquals("physics")) {
this.position = (ComponentPosition) component; this.position = (PositionningInterface)component;
}
if (component.getType().contentEquals("physics")) {
this.playerPhysics = (ComponentPhysics) component;
} }
} }
@ -37,8 +32,6 @@ public class ComponentLight extends Component {
public Vector3f getPosition() { public Vector3f getPosition() {
if (this.position != null) { if (this.position != null) {
return this.position.getTransform().getPosition().add(this.light.getPositionDelta()); return this.position.getTransform().getPosition().add(this.light.getPositionDelta());
} else if (this.playerPhysics != null) {
return this.playerPhysics.getTransform().getPosition().add(this.light.getPositionDelta());
} }
return null; return null;
} }

View File

@ -1,20 +1,20 @@
package org.atriasoft.ege.components; package org.atriasoft.ege.components;
import org.atriasoft.ege.Light; import org.atriasoft.ege.Light;
import org.atriasoft.ege.engines.EngineLight;
public class ComponentLightSun extends ComponentLight{ public class ComponentLightSun extends ComponentLight {
public ComponentLightSun() { public ComponentLightSun() {
super();
} }
public ComponentLightSun(Light light) { public ComponentLightSun(final Light light) {
super(light); super(light);
} }
// @Override @Override
// public String getType() { public String getType() {
// return "sun"; return EngineLight.ENGINE_NAME;
// } }
} }

View File

@ -2,10 +2,11 @@ package org.atriasoft.ege.components;
import org.atriasoft.ege.Component; import org.atriasoft.ege.Component;
import org.atriasoft.ege.Signal; import org.atriasoft.ege.Signal;
import org.atriasoft.ege.components.part.PositionningInterface;
import org.atriasoft.ege.internal.Log; import org.atriasoft.ege.internal.Log;
import org.atriasoft.etk.math.Transform3D; import org.atriasoft.etk.math.Transform3D;
public class ComponentPosition extends Component { public class ComponentPosition extends Component implements PositionningInterface {
public final Signal<Transform3D> signalPosition = new Signal<Transform3D>(); public final Signal<Transform3D> signalPosition = new Signal<Transform3D>();
protected Transform3D transform; protected Transform3D transform;
@ -35,6 +36,7 @@ public class ComponentPosition extends Component {
* set a new transformation * set a new transformation
* @return Transformation of the position * @return Transformation of the position
*/ */
@Override
public Transform3D getTransform() { public Transform3D getTransform() {
return this.transform; return this.transform;
} }

View File

@ -2,65 +2,56 @@
package org.atriasoft.ege.components; package org.atriasoft.ege.components;
import org.atriasoft.ege.Component; import org.atriasoft.ege.Component;
import org.atriasoft.ege.components.part.PositionningInterface;
import org.atriasoft.ege.components.part.TransformRender;
import org.atriasoft.etk.Uri; import org.atriasoft.etk.Uri;
import org.atriasoft.etk.math.Matrix4f;
import org.atriasoft.gale.backend3d.OpenGL; import org.atriasoft.gale.backend3d.OpenGL;
import org.atriasoft.gale.resource.ResourceProgram; import org.atriasoft.gale.resource.ResourceProgram;
public class ComponentRenderColoredStaticMesh extends ComponentRender { public class ComponentRenderColoredStaticMesh extends ComponentRender {
ComponentStaticMesh mesh = null; ComponentStaticMesh mesh = null;
private int oGLMatrixProjection;
private int oGLMatrixTransformation;
private int oGLMatrixView;
ComponentPosition position = null;
ResourceProgram program = null; ResourceProgram program = null;
TransformRender renderTransform = null;
public ComponentRenderColoredStaticMesh(Uri vertexShader, Uri fragmentShader) { public ComponentRenderColoredStaticMesh(final Uri vertexShader, final Uri fragmentShader) {
this.renderTransform = new TransformRender();
this.program = ResourceProgram.create(vertexShader, fragmentShader); this.program = ResourceProgram.create(vertexShader, fragmentShader);
if (this.program != null) { if (this.program != null) {
this.oGLMatrixTransformation = this.program.getUniform("in_matrixTransformation"); this.renderTransform.init(this.program);
this.oGLMatrixProjection = this.program.getUniform("in_matrixProjection");
this.oGLMatrixView = this.program.getUniform("in_matrixView");
} }
} }
@Override @Override
public void addFriendComponent(Component component) { public void addFriendComponent(final Component component) {
if (component.getType().contentEquals("static-mesh")) { if (component instanceof ComponentStaticMesh refTyped) {
this.mesh = (ComponentStaticMesh) component; this.mesh = refTyped;
} }
if (component.getType().contentEquals("position")) { if (component instanceof PositionningInterface refTyped) {
this.position = (ComponentPosition) component; this.renderTransform.setPositionning(refTyped);
} }
} }
@Override @Override
public void removeFriendComponent(Component component) { public void removeFriendComponent(final Component component) {
// nothing to do. // nothing to do.
} }
@Override @Override
public void render() { public void render() {
// Select the program:
this.program.use(); this.program.use();
// Bind all the element for the rendering:
final Matrix4f projectionMatrix = OpenGL.getMatrix(); this.renderTransform.bindForRendering(this.program);
final Matrix4f viewMatrix = OpenGL.getCameraMatrix();
//Log.warning("position 22 " + this.position.getTransform());
final Matrix4f transformationMatrix = this.position.getTransform().getOpenGLMatrix();
this.mesh.bindForRendering(); this.mesh.bindForRendering();
this.program.uniformMatrix(this.oGLMatrixView, viewMatrix);
this.program.uniformMatrix(this.oGLMatrixProjection, projectionMatrix);
// Change the position for each element with the same pipeline you need to render ...
this.program.uniformMatrix(this.oGLMatrixTransformation, transformationMatrix);
// update of flags is done asyncronously ==> need update befor drawing... // update of flags is done asyncronously ==> need update befor drawing...
OpenGL.updateAllFlags(); OpenGL.updateAllFlags();
// Request the draw od the elements: // Request the draw od the elements:
this.mesh.render(); this.mesh.render();
// remove all element to render:
this.renderTransform.unBindForRendering();
this.mesh.unBindForRendering(); this.mesh.unBindForRendering();
// Disable program:
this.program.unUse(); this.program.unUse();
} }
} }

View File

@ -1,44 +1,50 @@
package org.atriasoft.ege.components; package org.atriasoft.ege.components;
import org.atriasoft.ege.Component; import org.atriasoft.ege.Component;
import org.atriasoft.ege.components.part.LightRender;
import org.atriasoft.ege.components.part.PositionningInterface;
import org.atriasoft.ege.components.part.TransformRender;
import org.atriasoft.ege.engines.EngineLight;
import org.atriasoft.etk.Uri; import org.atriasoft.etk.Uri;
import org.atriasoft.etk.math.Matrix4f;
import org.atriasoft.gale.backend3d.OpenGL; import org.atriasoft.gale.backend3d.OpenGL;
import org.atriasoft.gale.resource.ResourceProgram; import org.atriasoft.gale.resource.ResourceProgram;
public class ComponentRenderMeshPalette extends ComponentRender { public class ComponentRenderMeshPalette extends ComponentRender {
private int GLMatrixProjection;
private int GLMatrixTransformation;
private int GLMatrixView;
ComponentMesh mesh = null; ComponentMesh mesh = null;
private ComponentPhysics playerPhysics = null;
ComponentPosition position = null;
ResourceProgram program = null; ResourceProgram program = null;
ComponentTexturePalette texture = null; ComponentTexturePalette texture = null;
public ComponentRenderMeshPalette(final Uri vertexShader, final Uri fragmentShader) { LightRender renderLight = null;
TransformRender renderTransform = null;
public ComponentRenderMeshPalette(final Uri vertexShader, final Uri fragmentShader, final EngineLight lightEngine) {
if (lightEngine != null) {
this.renderLight = new LightRender(lightEngine);
}
this.renderTransform = new TransformRender();
this.program = ResourceProgram.create(vertexShader, fragmentShader); this.program = ResourceProgram.create(vertexShader, fragmentShader);
if (this.program != null) { if (this.program != null) {
this.GLMatrixTransformation = this.program.getUniform("in_matrixTransformation"); this.renderTransform.init(this.program);
this.GLMatrixProjection = this.program.getUniform("in_matrixProjection"); if (this.renderLight != null) {
this.GLMatrixView = this.program.getUniform("in_matrixView"); this.renderLight.init(this.program);
}
} }
} }
@Override @Override
public void addFriendComponent(final Component component) { public void addFriendComponent(final Component component) {
if (component.getType().contentEquals("mesh")) { if (component instanceof ComponentMesh refTyped) {
this.mesh = (ComponentMesh) component; this.mesh = refTyped;
} }
if (component.getType().contentEquals("texture")) { if (component instanceof ComponentTexturePalette refTyped) {
this.texture = (ComponentTexturePalette) component; this.texture = refTyped;
} }
if (component.getType().contentEquals("position")) { if (component instanceof PositionningInterface refTyped) {
this.position = (ComponentPosition) component; this.renderTransform.setPositionning(refTyped);
} if (this.renderLight != null) {
if (component.getType().contentEquals("physics")) { this.renderLight.setPositionning(refTyped);
this.playerPhysics = (ComponentPhysics) component; }
} }
} }
@ -49,30 +55,27 @@ public class ComponentRenderMeshPalette extends ComponentRender {
@Override @Override
public void render() { public void render() {
// Select the program:
this.program.use(); this.program.use();
final Matrix4f projectionMatrix = OpenGL.getMatrix(); // Bind all the element for the rendering:
final Matrix4f viewMatrix = OpenGL.getCameraMatrix();
Matrix4f transformationMatrix = null;
if (this.position != null) {
//Log.warning("position " + this.position.getTransform());
transformationMatrix = this.position.getTransform().getOpenGLMatrix();
} else if (this.playerPhysics != null) {
//Log.warning("playerPosition " + this.playerPhysics.getTransform());
transformationMatrix = this.playerPhysics.getTransform().getOpenGLMatrix();
}
this.mesh.bindForRendering(); this.mesh.bindForRendering();
this.texture.bindForRendering(); this.texture.bindForRendering();
this.program.uniformMatrix(this.GLMatrixView, viewMatrix); if (this.renderLight != null) {
this.program.uniformMatrix(this.GLMatrixProjection, projectionMatrix); this.renderLight.bindForRendering(this.program);
// Change the position for each element with the same pipeline you need to render ... }
this.program.uniformMatrix(this.GLMatrixTransformation, transformationMatrix); this.renderTransform.bindForRendering(this.program);
// update of flags is done asynchronously ==> need update before drawing... // update of flags is done asynchronously ==> need update before drawing...
OpenGL.updateAllFlags(); OpenGL.updateAllFlags();
// Request the draw all the elements: // Request the draw all the elements:
this.mesh.renderArrays(); this.mesh.renderArrays();
// remove all element to render:
this.renderTransform.unBindForRendering();
if (this.renderLight != null) {
this.renderLight.unBindForRendering();
}
this.texture.unBindForRendering(); this.texture.unBindForRendering();
this.mesh.unBindForRendering(); this.mesh.unBindForRendering();
// Disable program:
this.program.unUse(); this.program.unUse();
} }
} }

View File

@ -2,107 +2,79 @@ package org.atriasoft.ege.components;
import java.util.Set; import java.util.Set;
import org.atriasoft.ege.internal.Log;
import org.atriasoft.ege.Component; import org.atriasoft.ege.Component;
import org.atriasoft.ege.Light; import org.atriasoft.ege.components.part.LightRender;
import org.atriasoft.ege.Material; import org.atriasoft.ege.components.part.MaterialsRender;
import org.atriasoft.ege.components.part.PositionningInterface;
import org.atriasoft.ege.components.part.TransformRender;
import org.atriasoft.ege.engines.EngineLight;
import org.atriasoft.etk.Uri; import org.atriasoft.etk.Uri;
import org.atriasoft.etk.math.Matrix4f;
import org.atriasoft.etk.math.Vector3f;
import org.atriasoft.gale.backend3d.OpenGL; import org.atriasoft.gale.backend3d.OpenGL;
import org.atriasoft.gale.resource.ResourceProgram; import org.atriasoft.gale.resource.ResourceProgram;
import org.atriasoft.ege.engines.EngineLight;
public class ComponentRenderTexturedMaterialsDynamicMeshs extends ComponentRender { public class ComponentRenderTexturedMaterialsDynamicMeshs extends ComponentRender {
private static final int numberOfLight = 8;
ComponentDynamicMeshs meshs = null; ComponentDynamicMeshs meshs = null;
ComponentTextures textures = null; ComponentTextures textures = null;
ComponentMaterials materials = null;
ComponentPosition position = null; ComponentPosition position = null;
ResourceProgram program = null; ResourceProgram program = null;
EngineLight lightEngine;
private int GLMatrixTransformation; LightRender renderLight = null;
private int GLMatrixProjection; MaterialsRender renderMaterials = null;
private int GLMatrixView; TransformRender renderTransform = null;
private int GLambientFactor;
private int GLdiffuseFactor;
private int GLspecularFactor;
private int GLshininess;
private GlLightIndex[] GLlights;
public ComponentRenderTexturedMaterialsDynamicMeshs(Uri vertexShader, Uri fragmentShader, EngineLight lightEngine) { public ComponentRenderTexturedMaterialsDynamicMeshs(final Uri vertexShader, final Uri fragmentShader, final EngineLight lightEngine) {
this.lightEngine = lightEngine; if (lightEngine != null) {
this.renderLight = new LightRender(lightEngine);
}
this.renderTransform = new TransformRender();
this.renderMaterials = new MaterialsRender();
this.program = ResourceProgram.create(vertexShader, fragmentShader); this.program = ResourceProgram.create(vertexShader, fragmentShader);
if (this.program != null) { if (this.program != null) {
this.GLMatrixTransformation = this.program.getUniform("in_matrixTransformation"); this.renderTransform.init(this.program);
this.GLMatrixProjection = this.program.getUniform("in_matrixProjection"); if (this.renderLight != null) {
this.GLMatrixView = this.program.getUniform("in_matrixView"); this.renderLight.init(this.program);
this.GLambientFactor = this.program.getUniform("in_material.ambientFactor");
this.GLdiffuseFactor = this.program.getUniform("in_material.diffuseFactor");
this.GLspecularFactor = this.program.getUniform("in_material.specularFactor");
this.GLshininess = this.program.getUniform("in_material.shininess");
this.GLlights = new GlLightIndex[numberOfLight];
for (int iii=0; iii<numberOfLight; iii++) {
int color = this.program.getUniform("in_lights[" + iii + "].color");
int position = this.program.getUniform("in_lights[" + iii + "].position");
int attenuation = this.program.getUniform("in_lights[" + iii + "].attenuation");
this.GLlights[iii] = new GlLightIndex(color, position, attenuation);
} }
this.renderMaterials.init(this.program);
} }
} }
@Override @Override
public void addFriendComponent(Component component) { public void addFriendComponent(final Component component) {
if (component.getType().contentEquals("dynamic-meshs")) { if (component instanceof ComponentDynamicMeshs refTyped) {
meshs = (ComponentDynamicMeshs)component; this.meshs = refTyped;
} }
if (component.getType().contentEquals("textures")) { if (component instanceof ComponentTextures refTyped) {
textures = (ComponentTextures)component; this.textures = refTyped;
} }
if (component.getType().contentEquals("materials")) { if (component instanceof ComponentMaterials refTyped) {
materials = (ComponentMaterials)component; this.renderMaterials.setMaterial(refTyped);
} }
if (component.getType().contentEquals("position")) { if (component instanceof PositionningInterface refTyped) {
position = (ComponentPosition)component; this.renderTransform.setPositionning(refTyped);
if (this.renderLight != null) {
this.renderLight.setPositionning(refTyped);
}
} }
} }
@Override @Override
public void removeFriendComponent(Component component) { public void removeFriendComponent(final Component component) {
// nothing to do. // nothing to do.
} }
@Override @Override
public void render() { public void render() {
// Select the program:
this.program.use(); this.program.use();
Light[] lights = this.lightEngine.getNearest(position.getTransform().getPosition()); // Bind all the element for the rendering:
Matrix4f projectionMatrix = OpenGL.getMatrix(); if (this.renderLight != null) {
Matrix4f viewMatrix = OpenGL.getCameraMatrix(); this.renderLight.bindForRendering(this.program);
Matrix4f transformationMatrix = position.getTransform().getOpenGLMatrix();
Set<String> keys = this.meshs.getKeys();
for (int iii=0; iii<numberOfLight; iii++) {
if (lights[iii] != null) {
this.program.uniformVector(this.GLlights[iii].oGLposition, lights[iii].getPositionDelta());
this.program.uniformVector(this.GLlights[iii].oGLcolor, lights[iii].getColor());
this.program.uniformVector(this.GLlights[iii].oGLattenuation, lights[iii].getAttenuation());
} else {
this.program.uniformVector(this.GLlights[iii].oGLposition, new Vector3f(0,0,0));
this.program.uniformVector(this.GLlights[iii].oGLcolor, new Vector3f(0,0,0));
this.program.uniformVector(this.GLlights[iii].oGLattenuation, new Vector3f(1,0,0));
}
} }
this.program.uniformMatrix(this.GLMatrixView, viewMatrix); this.renderTransform.bindForRendering(this.program);
this.program.uniformMatrix(this.GLMatrixProjection, projectionMatrix); Set<String> keys = this.meshs.getKeys();
// Change the position for each element with the same pipeline you need to render ...
this.program.uniformMatrix(this.GLMatrixTransformation, transformationMatrix);
for (String key : keys) { for (String key : keys) {
this.meshs.bindForRendering(key); this.meshs.bindForRendering(key);
this.textures.bindForRendering(key); this.textures.bindForRendering(key);
Material mat = this.materials.getMaterial(key); this.renderMaterials.bindForRendering(this.program, key);
this.program.uniformVector(GLambientFactor, mat.getAmbientFactor());
this.program.uniformVector(GLdiffuseFactor, mat.getDiffuseFactor());
this.program.uniformVector(GLspecularFactor, mat.getSpecularFactor());
this.program.uniformFloat(GLshininess, mat.getShininess());
// update of flags is done asynchronously ==> need update before drawing... // update of flags is done asynchronously ==> need update before drawing...
OpenGL.updateAllFlags(); OpenGL.updateAllFlags();
// Request the draw all the elements: // Request the draw all the elements:
@ -110,6 +82,11 @@ public class ComponentRenderTexturedMaterialsDynamicMeshs extends ComponentRende
this.textures.unBindForRendering(key); this.textures.unBindForRendering(key);
this.meshs.unBindForRendering(key); this.meshs.unBindForRendering(key);
} }
// remove all element to render:
this.renderTransform.unBindForRendering();
if (this.renderLight != null) {
this.renderLight.unBindForRendering();
}
this.program.unUse(); this.program.unUse();
} }
} }

View File

@ -1,71 +1,62 @@
package org.atriasoft.ege.components; package org.atriasoft.ege.components;
import org.atriasoft.ege.Component; import org.atriasoft.ege.Component;
import org.atriasoft.ege.Light; import org.atriasoft.ege.components.part.LightRender;
import org.atriasoft.ege.Material; import org.atriasoft.ege.components.part.MaterialRender;
import org.atriasoft.ege.components.part.PositionningInterface;
import org.atriasoft.ege.components.part.TransformRender;
import org.atriasoft.ege.engines.EngineLight; import org.atriasoft.ege.engines.EngineLight;
import org.atriasoft.etk.Uri; import org.atriasoft.etk.Uri;
import org.atriasoft.etk.math.Matrix4f;
import org.atriasoft.etk.math.Vector3f;
import org.atriasoft.gale.backend3d.OpenGL; import org.atriasoft.gale.backend3d.OpenGL;
import org.atriasoft.gale.resource.ResourceProgram; import org.atriasoft.gale.resource.ResourceProgram;
public class ComponentRenderTexturedMaterialsStaticMesh extends ComponentRender { public class ComponentRenderTexturedMaterialsStaticMesh extends ComponentRender {
private static final int numberOfLight = 8;
private int GLambientFactor;
private int GLdiffuseFactor;
private GlLightIndex[] GLlights;
private int GLMatrixProjection;
private int GLMatrixTransformation;
private int GLMatrixView;
private int GLshininess;
private int GLspecularFactor;
EngineLight lightEngine;
ComponentMaterial material = null;
ComponentStaticMesh mesh = null; ComponentStaticMesh mesh = null;
private ComponentPhysics playerPhysics = null;
ComponentPosition position = null;
ResourceProgram program = null; ResourceProgram program = null;
ComponentTexture texture = null; ComponentTexture texture = null;
LightRender renderLight = null;
MaterialRender renderMaterial = null;
TransformRender renderTransform = null;
public ComponentRenderTexturedMaterialsStaticMesh(final Uri vertexShader, final Uri fragmentShader) {
this(vertexShader, fragmentShader, null);
}
public ComponentRenderTexturedMaterialsStaticMesh(final Uri vertexShader, final Uri fragmentShader, final EngineLight lightEngine) { public ComponentRenderTexturedMaterialsStaticMesh(final Uri vertexShader, final Uri fragmentShader, final EngineLight lightEngine) {
this.lightEngine = lightEngine; if (lightEngine != null) {
this.renderLight = new LightRender(lightEngine);
}
this.renderTransform = new TransformRender();
this.renderMaterial = new MaterialRender();
this.program = ResourceProgram.create(vertexShader, fragmentShader); this.program = ResourceProgram.create(vertexShader, fragmentShader);
if (this.program != null) { if (this.program != null) {
this.GLMatrixTransformation = this.program.getUniform("in_matrixTransformation"); this.renderTransform.init(this.program);
this.GLMatrixProjection = this.program.getUniform("in_matrixProjection"); if (this.renderLight != null) {
this.GLMatrixView = this.program.getUniform("in_matrixView"); this.renderLight.init(this.program);
this.GLambientFactor = this.program.getUniform("in_material.ambientFactor");
this.GLdiffuseFactor = this.program.getUniform("in_material.diffuseFactor");
this.GLspecularFactor = this.program.getUniform("in_material.specularFactor");
this.GLshininess = this.program.getUniform("in_material.shininess");
this.GLlights = new GlLightIndex[ComponentRenderTexturedMaterialsStaticMesh.numberOfLight];
for (int iii = 0; iii < ComponentRenderTexturedMaterialsStaticMesh.numberOfLight; iii++) {
final int color = this.program.getUniform("in_lights[" + iii + "].color");
final int position = this.program.getUniform("in_lights[" + iii + "].position");
final int attenuation = this.program.getUniform("in_lights[" + iii + "].attenuation");
this.GLlights[iii] = new GlLightIndex(color, position, attenuation);
} }
this.renderMaterial.init(this.program);
} }
} }
@Override @Override
public void addFriendComponent(final Component component) { public void addFriendComponent(final Component component) {
if (component.getType().contentEquals("static-mesh")) { if (component instanceof ComponentStaticMesh refTyped) {
this.mesh = (ComponentStaticMesh) component; this.mesh = refTyped;
} }
if (component.getType().contentEquals("texture")) { if (component instanceof ComponentTexture refTyped) {
this.texture = (ComponentTexture) component; this.texture = refTyped;
} }
if (component.getType().contentEquals("material")) { if (component instanceof ComponentMaterial refTyped) {
this.material = (ComponentMaterial) component; this.renderMaterial.setMaterial(refTyped);
} }
if (component.getType().contentEquals("position")) { if (component instanceof PositionningInterface refTyped) {
this.position = (ComponentPosition) component; this.renderTransform.setPositionning(refTyped);
} if (this.renderLight != null) {
if (component.getType().contentEquals("physics")) { this.renderLight.setPositionning(refTyped);
this.playerPhysics = (ComponentPhysics) component; }
} }
} }
@ -76,49 +67,29 @@ public class ComponentRenderTexturedMaterialsStaticMesh extends ComponentRender
@Override @Override
public void render() { public void render() {
// Select the program:
this.program.use(); this.program.use();
Light[] lights = null; // Bind all the element for the rendering:
Matrix4f transformationMatrix = null;
if (this.position != null) {
//Log.warning("position " + this.position.getTransform());
lights = this.lightEngine.getNearest(this.position.getTransform().getPosition());
transformationMatrix = this.position.getTransform().getOpenGLMatrix();
} else if (this.playerPhysics != null) {
//Log.warning("playerPosition " + this.playerPhysics.getTransform());
lights = this.lightEngine.getNearest(this.playerPhysics.getTransform().getPosition());
transformationMatrix = this.playerPhysics.getTransform().getOpenGLMatrix();
}
final Matrix4f projectionMatrix = OpenGL.getMatrix();
final Matrix4f viewMatrix = OpenGL.getCameraMatrix();
this.mesh.bindForRendering(); this.mesh.bindForRendering();
this.texture.bindForRendering(); this.texture.bindForRendering();
this.renderMaterial.bindForRendering(this.program);
final Material mat = this.material.getMaterial(); if (this.renderLight != null) {
this.program.uniformVector(this.GLambientFactor, mat.getAmbientFactor()); this.renderLight.bindForRendering(this.program);
this.program.uniformVector(this.GLdiffuseFactor, mat.getDiffuseFactor());
this.program.uniformVector(this.GLspecularFactor, mat.getSpecularFactor());
this.program.uniformFloat(this.GLshininess, mat.getShininess());
for (int iii = 0; iii < ComponentRenderTexturedMaterialsStaticMesh.numberOfLight; iii++) {
if (lights[iii] != null) {
this.program.uniformVector(this.GLlights[iii].oGLposition, lights[iii].getPositionDelta());
this.program.uniformVector(this.GLlights[iii].oGLcolor, lights[iii].getColor());
this.program.uniformVector(this.GLlights[iii].oGLattenuation, lights[iii].getAttenuation());
} else {
this.program.uniformVector(this.GLlights[iii].oGLposition, Vector3f.ZERO);
this.program.uniformVector(this.GLlights[iii].oGLcolor, Vector3f.ZERO);
this.program.uniformVector(this.GLlights[iii].oGLattenuation, new Vector3f(1, 0, 0));
}
} }
this.program.uniformMatrix(this.GLMatrixView, viewMatrix); this.renderTransform.bindForRendering(this.program);
this.program.uniformMatrix(this.GLMatrixProjection, projectionMatrix);
// Change the position for each element with the same pipeline you need to render ...
this.program.uniformMatrix(this.GLMatrixTransformation, transformationMatrix);
// update of flags is done asynchronously ==> need update before drawing... // update of flags is done asynchronously ==> need update before drawing...
OpenGL.updateAllFlags(); OpenGL.updateAllFlags();
// Request the draw all the elements: // Request the draw all the elements:
this.mesh.render(); this.mesh.render();
// remove all element to render:
this.renderTransform.unBindForRendering();
if (this.renderLight != null) {
this.renderLight.unBindForRendering();
}
this.renderMaterial.unBindForRendering();
this.texture.unBindForRendering(); this.texture.unBindForRendering();
this.mesh.unBindForRendering(); this.mesh.unBindForRendering();
// Disable program:
this.program.unUse(); this.program.unUse();
} }
} }

View File

@ -3,112 +3,91 @@ package org.atriasoft.ege.components;
import java.util.Set; import java.util.Set;
import org.atriasoft.ege.Component; import org.atriasoft.ege.Component;
import org.atriasoft.ege.Light; import org.atriasoft.ege.components.part.LightRender;
import org.atriasoft.ege.Material; import org.atriasoft.ege.components.part.MaterialsRender;
import org.atriasoft.ege.components.part.PositionningInterface;
import org.atriasoft.ege.components.part.TransformRender;
import org.atriasoft.ege.engines.EngineLight;
import org.atriasoft.etk.Uri; import org.atriasoft.etk.Uri;
import org.atriasoft.etk.math.Matrix4f;
import org.atriasoft.etk.math.Vector3f;
import org.atriasoft.gale.backend3d.OpenGL; import org.atriasoft.gale.backend3d.OpenGL;
import org.atriasoft.gale.resource.ResourceProgram; import org.atriasoft.gale.resource.ResourceProgram;
import org.atriasoft.ege.engines.EngineLight;
public class ComponentRenderTexturedMaterialsStaticMeshs extends ComponentRender { public class ComponentRenderTexturedMaterialsStaticMeshs extends ComponentRender {
private static final int numberOfLight = 8;
ComponentStaticMeshs meshs = null; ComponentStaticMeshs meshs = null;
ComponentTextures textures = null; ComponentTextures textures = null;
ComponentMaterials materials = null; ComponentMaterials materials = null;
ComponentPosition position = null;
ResourceProgram program = null; ResourceProgram program = null;
EngineLight lightEngine; LightRender renderLight = null;
private int GLMatrixTransformation; MaterialsRender renderMaterials = null;
private int GLMatrixProjection; TransformRender renderTransform = null;
private int GLMatrixView;
private int GLambientFactor;
private int GLdiffuseFactor;
private int GLspecularFactor;
private int GLshininess;
private GlLightIndex[] GLlights;
public ComponentRenderTexturedMaterialsStaticMeshs(Uri vertexShader, Uri fragmentShader, EngineLight lightEngine) { public ComponentRenderTexturedMaterialsStaticMeshs(final Uri vertexShader, final Uri fragmentShader, final EngineLight lightEngine) {
this.lightEngine = lightEngine; if (lightEngine != null) {
this.renderLight = new LightRender(lightEngine);
}
this.renderTransform = new TransformRender();
this.renderMaterials = new MaterialsRender();
this.program = ResourceProgram.create(vertexShader, fragmentShader); this.program = ResourceProgram.create(vertexShader, fragmentShader);
if (this.program != null) { if (this.program != null) {
this.GLMatrixTransformation = this.program.getUniform("in_matrixTransformation"); this.renderTransform.init(this.program);
this.GLMatrixProjection = this.program.getUniform("in_matrixProjection"); if (this.renderLight != null) {
this.GLMatrixView = this.program.getUniform("in_matrixView"); this.renderLight.init(this.program);
this.GLambientFactor = this.program.getUniform("in_material.ambientFactor");
this.GLdiffuseFactor = this.program.getUniform("in_material.diffuseFactor");
this.GLspecularFactor = this.program.getUniform("in_material.specularFactor");
this.GLshininess = this.program.getUniform("in_material.shininess");
this.GLlights = new GlLightIndex[numberOfLight];
for (int iii=0; iii<numberOfLight; iii++) {
int color = this.program.getUniform("in_lights[" + iii + "].color");
int position = this.program.getUniform("in_lights[" + iii + "].position");
int attenuation = this.program.getUniform("in_lights[" + iii + "].attenuation");
this.GLlights[iii] = new GlLightIndex(color, position, attenuation);
} }
this.renderMaterials.init(this.program);
} }
} }
@Override @Override
public void addFriendComponent(Component component) { public void addFriendComponent(final Component component) {
if (component.getType().contentEquals("static-meshs")) { if (component instanceof ComponentStaticMeshs refTyped) {
meshs = (ComponentStaticMeshs)component; this.meshs = refTyped;
} }
if (component.getType().contentEquals("textures")) { if (component instanceof ComponentTextures refTyped) {
textures = (ComponentTextures)component; this.textures = refTyped;
} }
if (component.getType().contentEquals("materials")) { if (component instanceof ComponentMaterials refTyped) {
materials = (ComponentMaterials)component; this.renderMaterials.setMaterial(refTyped);
} }
if (component.getType().contentEquals("position")) { if (component instanceof PositionningInterface refTyped) {
position = (ComponentPosition)component; this.renderTransform.setPositionning(refTyped);
if (this.renderLight != null) {
this.renderLight.setPositionning(refTyped);
}
} }
} }
@Override @Override
public void removeFriendComponent(Component component) { public void removeFriendComponent(final Component component) {
// nothing to do. // nothing to do.
} }
@Override @Override
public void render() { public void render() {
// Select the program:
this.program.use(); this.program.use();
Light[] lights = this.lightEngine.getNearest(position.getTransform().getPosition()); // Bind all the element for the rendering:
Matrix4f projectionMatrix = OpenGL.getMatrix(); if (this.renderLight != null) {
Matrix4f viewMatrix = OpenGL.getCameraMatrix(); this.renderLight.bindForRendering(this.program);
Matrix4f transformationMatrix = position.getTransform().getOpenGLMatrix();
Set<String> keys = this.meshs.getKeys();
for (int iii=0; iii<numberOfLight; iii++) {
if (lights[iii] != null) {
this.program.uniformVector(this.GLlights[iii].oGLposition, lights[iii].getPositionDelta());
this.program.uniformVector(this.GLlights[iii].oGLcolor, lights[iii].getColor());
this.program.uniformVector(this.GLlights[iii].oGLattenuation, lights[iii].getAttenuation());
} else {
this.program.uniformVector(this.GLlights[iii].oGLposition, new Vector3f(0,0,0));
this.program.uniformVector(this.GLlights[iii].oGLcolor, new Vector3f(0,0,0));
this.program.uniformVector(this.GLlights[iii].oGLattenuation, new Vector3f(1,0,0));
}
} }
this.program.uniformMatrix(this.GLMatrixView, viewMatrix); this.renderTransform.bindForRendering(this.program);
this.program.uniformMatrix(this.GLMatrixProjection, projectionMatrix); Set<String> keys = this.meshs.getKeys();
// Change the position for each element with the same pipeline you need to render ...
this.program.uniformMatrix(this.GLMatrixTransformation, transformationMatrix);
for (String key : keys) { for (String key : keys) {
this.meshs.bindForRendering(key); this.meshs.bindForRendering(key);
this.textures.bindForRendering(key); this.textures.bindForRendering(key);
Material mat = this.materials.getMaterial(key); this.renderMaterials.bindForRendering(this.program, key);
this.program.uniformVector(GLambientFactor, mat.getAmbientFactor());
this.program.uniformVector(GLdiffuseFactor, mat.getDiffuseFactor());
this.program.uniformVector(GLspecularFactor, mat.getSpecularFactor());
this.program.uniformFloat(GLshininess, mat.getShininess());
// update of flags is done asynchronously ==> need update before drawing... // update of flags is done asynchronously ==> need update before drawing...
OpenGL.updateAllFlags(); OpenGL.updateAllFlags();
// Request the draw all the elements: // Request the draw all the elements:
this.meshs.render(key); this.meshs.render(key);
// remove all element to render:
this.renderMaterials.unBindForRendering();
this.textures.unBindForRendering(key); this.textures.unBindForRendering(key);
this.meshs.unBindForRendering(key); this.meshs.unBindForRendering(key);
} }
// remove all element to render:
this.renderTransform.unBindForRendering();
if (this.renderLight != null) {
this.renderLight.unBindForRendering();
}
this.program.unUse(); this.program.unUse();
} }
} }

View File

@ -1,44 +1,40 @@
package org.atriasoft.ege.components; package org.atriasoft.ege.components;
import org.atriasoft.ege.Component; import org.atriasoft.ege.Component;
import org.atriasoft.ege.components.part.PositionningInterface;
import org.atriasoft.ege.components.part.TransformRender;
import org.atriasoft.etk.Uri; import org.atriasoft.etk.Uri;
import org.atriasoft.etk.math.Matrix4f;
import org.atriasoft.gale.backend3d.OpenGL; import org.atriasoft.gale.backend3d.OpenGL;
import org.atriasoft.gale.resource.ResourceProgram; import org.atriasoft.gale.resource.ResourceProgram;
public class ComponentRenderTexturedStaticMesh extends ComponentRender { public class ComponentRenderTexturedStaticMesh extends ComponentRender {
private int GLMatrixProjection;
private int GLMatrixTransformation;
private int GLMatrixView;
ComponentStaticMesh mesh = null; ComponentStaticMesh mesh = null;
private ComponentPhysics playerPhysics = null; private final ComponentPhysics playerPhysics = null;
ComponentPosition position = null; ComponentPosition position = null;
ResourceProgram program = null; ResourceProgram program = null;
ComponentTexture texture = null; ComponentTexture texture = null;
TransformRender renderTransform = null;
public ComponentRenderTexturedStaticMesh(final Uri vertexShader, final Uri fragmentShader) { public ComponentRenderTexturedStaticMesh(final Uri vertexShader, final Uri fragmentShader) {
this.renderTransform = new TransformRender();
this.program = ResourceProgram.create(vertexShader, fragmentShader); this.program = ResourceProgram.create(vertexShader, fragmentShader);
if (this.program != null) { if (this.program != null) {
this.GLMatrixTransformation = this.program.getUniform("in_matrixTransformation"); this.renderTransform.init(this.program);
this.GLMatrixProjection = this.program.getUniform("in_matrixProjection");
this.GLMatrixView = this.program.getUniform("in_matrixView");
} }
} }
@Override @Override
public void addFriendComponent(final Component component) { public void addFriendComponent(final Component component) {
if (component.getType().contentEquals("static-mesh")) { if (component instanceof ComponentStaticMesh refTyped) {
this.mesh = (ComponentStaticMesh) component; this.mesh = refTyped;
} }
if (component.getType().contentEquals("texture")) { if (component instanceof ComponentTexture refTyped) {
this.texture = (ComponentTexture) component; this.texture = refTyped;
} }
if (component.getType().contentEquals("position")) { if (component instanceof PositionningInterface refTyped) {
this.position = (ComponentPosition) component; this.renderTransform.setPositionning(refTyped);
}
if (component.getType().contentEquals("physics")) {
this.playerPhysics = (ComponentPhysics) component;
} }
} }
@ -49,27 +45,18 @@ public class ComponentRenderTexturedStaticMesh extends ComponentRender {
@Override @Override
public void render() { public void render() {
// Select the program:
this.program.use(); this.program.use();
final Matrix4f projectionMatrix = OpenGL.getMatrix(); // Bind all the element for the rendering:
final Matrix4f viewMatrix = OpenGL.getCameraMatrix();
Matrix4f transformationMatrix = null;
if (this.position != null) {
//Log.warning("position " + this.position.getTransform());
transformationMatrix = this.position.getTransform().getOpenGLMatrix();
} else if (this.playerPhysics != null) {
//Log.warning("playerPosition " + this.playerPhysics.getTransform());
transformationMatrix = this.playerPhysics.getTransform().getOpenGLMatrix();
}
this.mesh.bindForRendering(); this.mesh.bindForRendering();
this.texture.bindForRendering(); this.texture.bindForRendering();
this.program.uniformMatrix(this.GLMatrixView, viewMatrix); this.renderTransform.bindForRendering(this.program);
this.program.uniformMatrix(this.GLMatrixProjection, projectionMatrix);
// Change the position for each element with the same pipeline you need to render ...
this.program.uniformMatrix(this.GLMatrixTransformation, transformationMatrix);
// update of flags is done asynchronously ==> need update before drawing... // update of flags is done asynchronously ==> need update before drawing...
OpenGL.updateAllFlags(); OpenGL.updateAllFlags();
// Request the draw all the elements: // Request the draw all the elements:
this.mesh.render(); this.mesh.render();
// remove all element to render:
this.renderTransform.unBindForRendering();
this.texture.unBindForRendering(); this.texture.unBindForRendering();
this.mesh.unBindForRendering(); this.mesh.unBindForRendering();
this.program.unUse(); this.program.unUse();

View File

@ -1,14 +1,10 @@
package org.atriasoft.ege.components; package org.atriasoft.ege.components;
import java.awt.Image;
import org.atriasoft.egami.ImageByte; import org.atriasoft.egami.ImageByte;
import org.atriasoft.egami.ToolImage;
import org.atriasoft.ege.Component; import org.atriasoft.ege.Component;
import org.atriasoft.ege.internal.Log; import org.atriasoft.ege.internal.Log;
import org.atriasoft.etk.Uri; import org.atriasoft.etk.Uri;
import org.atriasoft.gale.resource.ResourceTexture2; import org.atriasoft.gale.resource.ResourceTexture2;
import org.atriasoft.iogami.IOgami;
import org.atriasoft.loader3d.resources.ResourcePaletteFile; import org.atriasoft.loader3d.resources.ResourcePaletteFile;
public class ComponentTexturePalette extends Component { public class ComponentTexturePalette extends Component {
@ -16,7 +12,7 @@ public class ComponentTexturePalette extends Component {
private final ResourcePaletteFile palette; private final ResourcePaletteFile palette;
private final ResourceTexture2 texture; private final ResourceTexture2 texture;
public ComponentTexturePalette(Uri paletteName) { public ComponentTexturePalette(final Uri paletteName) {
this.palette = ResourcePaletteFile.create(paletteName); this.palette = ResourcePaletteFile.create(paletteName);
this.texture = ResourceTexture2.createNamed("TEXTURE_OF_PALETTE:" + paletteName.toString()); this.texture = ResourceTexture2.createNamed("TEXTURE_OF_PALETTE:" + paletteName.toString());
if (this.texture == null) { if (this.texture == null) {
@ -33,7 +29,7 @@ public class ComponentTexturePalette extends Component {
public void updateFromPalette() { public void updateFromPalette() {
Log.warning("update palet environnement"); Log.warning("update palet environnement");
final ImageByte img = this.palette.getImageByte(); final ImageByte img = this.palette.getImageByte();
IOgami.storePNG(new Uri("/home/heero/000000000aaaaplopppp.png"), img); //IOgami.storePNG(new Uri("/home/heero/000000000aaaaplopppp.png"), img);
this.texture.set(img); this.texture.set(img);
} }

View File

@ -1,9 +1,9 @@
package org.atriasoft.ege.components; package org.atriasoft.ege.components;
public class GlLightIndex { public class GlLightIndex {
int oGLcolor; public int oGLcolor;
int oGLposition; public int oGLposition;
int oGLattenuation; public int oGLattenuation;
public GlLightIndex(int gLcolor, int gLposition, int gLattenuation) { public GlLightIndex(int gLcolor, int gLposition, int gLattenuation) {
oGLcolor = gLcolor; oGLcolor = gLcolor;
oGLposition = gLposition; oGLposition = gLposition;

View File

@ -0,0 +1,59 @@
package org.atriasoft.ege.components.part;
import org.atriasoft.ege.Light;
import org.atriasoft.ege.components.GlLightIndex;
import org.atriasoft.ege.engines.EngineLight;
import org.atriasoft.etk.math.Vector3f;
import org.atriasoft.gale.resource.ResourceProgram;
public class LightRender implements PartRenderInterface {
private static final int numberOfLight = 8;
private GlLightIndex[] GLlights;
EngineLight lightEngine;
PositionningInterface position = null;
public LightRender(final EngineLight lightEngine) {
this.lightEngine = lightEngine;
}
@Override
public void init(final ResourceProgram program) {
this.GLlights = new GlLightIndex[LightRender.numberOfLight];
for (int iii = 0; iii < LightRender.numberOfLight; iii++) {
final int color = program.getUniform("in_lights[" + iii + "].color");
final int position = program.getUniform("in_lights[" + iii + "].position");
final int attenuation = program.getUniform("in_lights[" + iii + "].attenuation");
this.GLlights[iii] = new GlLightIndex(color, position, attenuation);
}
}
@Override
public void bindForRendering(final ResourceProgram program) {
// preparing stage
Vector3f positionObject = this.position.getTransform().getPosition();
Light[] lights = this.lightEngine.getNearest(positionObject);
// injection stage
for (int iii = 0; iii < LightRender.numberOfLight; iii++) {
if (lights[iii] != null) {
//Log.warning("Set light : [" + iii + "] " + lights[iii]);
program.uniformVector(this.GLlights[iii].oGLposition, lights[iii].getPositionDelta());
program.uniformColorRGB(this.GLlights[iii].oGLcolor, lights[iii].getColor());
program.uniformVector(this.GLlights[iii].oGLattenuation, lights[iii].getAttenuation());
} else {
program.uniformVector(this.GLlights[iii].oGLposition, Vector3f.ZERO);
program.uniformVector(this.GLlights[iii].oGLcolor, Vector3f.ZERO);
//program.uniformColorRGB(this.GLlights[iii].oGLcolor, Color.NONE);
program.uniformVector(this.GLlights[iii].oGLattenuation, new Vector3f(1, 0, 0));
}
}
}
@Override
public void unBindForRendering() {
}
public void setPositionning(final PositionningInterface component) {
this.position = component;
}
}

View File

@ -0,0 +1,19 @@
package org.atriasoft.ege.components.part;
import org.atriasoft.ege.components.ComponentMaterial;
import org.atriasoft.gale.resource.ResourceProgram;
public class MaterialRender extends MaterialRenderBase {
ComponentMaterial material = null;
@Override
public void bindForRendering(final ResourceProgram program) {
bindForRendering(program, this.material.getMaterial());
}
public void setMaterial(final ComponentMaterial component) {
this.material = component;
}
}

View File

@ -0,0 +1,36 @@
package org.atriasoft.ege.components.part;
import org.atriasoft.ege.Material;
import org.atriasoft.gale.resource.ResourceProgram;
public abstract class MaterialRenderBase implements PartRenderInterface {
protected int GLambientFactor;
protected int GLdiffuseFactor;
protected int GLshininess;
protected int GLspecularFactor;
public MaterialRenderBase() {
}
@Override
public void init(final ResourceProgram program) {
this.GLambientFactor = program.getUniform("in_material.ambientFactor");
this.GLdiffuseFactor = program.getUniform("in_material.diffuseFactor");
this.GLspecularFactor = program.getUniform("in_material.specularFactor");
this.GLshininess = program.getUniform("in_material.shininess");
}
public void bindForRendering(final ResourceProgram program, final Material mat) {
program.uniformVector(this.GLambientFactor, mat.getAmbientFactor());
program.uniformVector(this.GLdiffuseFactor, mat.getDiffuseFactor());
program.uniformVector(this.GLspecularFactor, mat.getSpecularFactor());
program.uniformFloat(this.GLshininess, mat.getShininess());
}
@Override
public void unBindForRendering() {
}
}

View File

@ -0,0 +1,23 @@
package org.atriasoft.ege.components.part;
import org.atriasoft.ege.components.ComponentMaterials;
import org.atriasoft.gale.resource.ResourceProgram;
public class MaterialsRender extends MaterialRenderBase {
ComponentMaterials material = null;
public void bindForRendering(final ResourceProgram program, final String type) {
bindForRendering(program, this.material.getMaterial(type));
}
@Override
public void bindForRendering(final ResourceProgram program) {
bindForRendering(program, this.material.getMaterial("default"));
}
public void setMaterial(final ComponentMaterials component) {
this.material = component;
}
}

View File

@ -0,0 +1,24 @@
package org.atriasoft.ege.components.part;
import org.atriasoft.gale.resource.ResourceProgram;
/**
* Element that permit to add prat element on the Shader rendering (permit to reduce code and normalize IO naming of the shader
*/
public interface PartRenderInterface {
/**
* Initialize the render part with the program elements
* @param program Open GL program
*/
void init(final ResourceProgram program);
/**
* Bing this part in the shader
* @param program Program that manage the rendering
*/
void bindForRendering(final ResourceProgram program);
/**
* Remove element from the shader.
*/
void unBindForRendering();
}

View File

@ -0,0 +1,11 @@
package org.atriasoft.ege.components.part;
import org.atriasoft.etk.math.Transform3D;
public interface PositionningInterface {
/**
* Get the current positionning on an object
* @return
*/
Transform3D getTransform();
}

View File

@ -0,0 +1,47 @@
package org.atriasoft.ege.components.part;
import org.atriasoft.etk.math.Matrix4f;
import org.atriasoft.gale.backend3d.OpenGL;
import org.atriasoft.gale.resource.ResourceProgram;
public class TransformRender implements PartRenderInterface {
private int GLMatrixProjection;
private int GLMatrixTransformation;
private int GLMatrixView;
private PositionningInterface position = null;
public TransformRender() {
}
@Override
public void init(final ResourceProgram program) {
this.GLMatrixTransformation = program.getUniform("in_matrixTransformation");
this.GLMatrixProjection = program.getUniform("in_matrixProjection");
this.GLMatrixView = program.getUniform("in_matrixView");
}
@Override
public void bindForRendering(final ResourceProgram program) {
// preparing stage
final Matrix4f projectionMatrix = OpenGL.getMatrix();
final Matrix4f viewMatrix = OpenGL.getCameraMatrix();
Matrix4f transformationMatrix = this.position.getTransform().getOpenGLMatrix();
// injection stage
program.uniformMatrix(this.GLMatrixView, viewMatrix);
program.uniformMatrix(this.GLMatrixProjection, projectionMatrix);
// Change the position for each element with the same pipeline you need to render ...
program.uniformMatrix(this.GLMatrixTransformation, transformationMatrix);
}
@Override
public void unBindForRendering() {
}
public void setPositionning(final PositionningInterface component) {
this.position = component;
}
}

View File

@ -6,70 +6,73 @@ import org.atriasoft.ege.Component;
import org.atriasoft.ege.Engine; import org.atriasoft.ege.Engine;
import org.atriasoft.ege.Environement; import org.atriasoft.ege.Environement;
import org.atriasoft.ege.Light; import org.atriasoft.ege.Light;
import org.atriasoft.etk.math.Vector3f;
import org.atriasoft.ege.internal.Log;
import org.atriasoft.ege.camera.Camera; import org.atriasoft.ege.camera.Camera;
import org.atriasoft.ege.components.ComponentAI;
import org.atriasoft.ege.components.ComponentLight; import org.atriasoft.ege.components.ComponentLight;
import org.atriasoft.ege.components.ComponentLightSun; import org.atriasoft.ege.components.ComponentLightSun;
import org.atriasoft.ege.internal.Log;
import org.atriasoft.etk.math.Vector3f;
public class EngineLight extends Engine { public class EngineLight extends Engine {
public static final String ENGINE_NAME = "light"; public static final String ENGINE_NAME = "light";
private Vector<ComponentLight> componentLights = new Vector<ComponentLight>(); private final Vector<ComponentLight> componentLights = new Vector<ComponentLight>();
private Vector<ComponentLightSun> componentSuns = new Vector<ComponentLightSun>(); private final Vector<ComponentLightSun> componentSuns = new Vector<ComponentLightSun>();
public EngineLight(Environement env) { public EngineLight(final Environement env) {
super(env); super(env);
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
} }
@Override @Override
public void componentRemove(Component ref) { public void componentRemove(final Component ref) {
componentLights.remove(ref); this.componentLights.remove(ref);
componentSuns.remove(ref); this.componentSuns.remove(ref);
} }
@Override @Override
public void componentAdd(Component ref) { public void componentAdd(final Component ref) {
if (ref instanceof ComponentLightSun == true) { if (ref instanceof ComponentLightSun refTyped) {
componentSuns.add((ComponentLightSun)ref); this.componentSuns.add(refTyped);
return; return;
} }
if (ref instanceof ComponentLight == true) { if (ref instanceof ComponentLight refTyped) {
componentLights.add((ComponentLight)ref); this.componentLights.add(refTyped);
return;
} }
} }
@Override @Override
public void update(long deltaMili) { public void update(final long deltaMili) {
// nothing to do ... // nothing to do ...
} }
@Override @Override
public void render(long deltaMili, Camera camera) { public void render(final long deltaMili, final Camera camera) {
// nothing to do ... // nothing to do ...
} }
@Override @Override
public void renderDebug(long deltaMili, Camera camera) { public void renderDebug(final long deltaMili, final Camera camera) {
// nothing to do ... // nothing to do ...
} }
@Override @Override
public String getType() { public String getType() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return ENGINE_NAME; return EngineLight.ENGINE_NAME;
} }
public Light[] getNearest(Vector3f position) { public Light[] getNearest(final Vector3f position) {
Light[] out = new Light[8]; Light[] out = new Light[8];
int count = 0; int count = 0;
for (ComponentLightSun elem: componentSuns) { for (ComponentLightSun elem: this.componentSuns) {
out[count] = new Light(elem.getLight().getColor(), elem.getPosition(), elem.getLight().getAttenuation()); out[count] = new Light(elem.getLight().getColor(), elem.getPosition(), elem.getLight().getAttenuation());
if (count>=8) {
Log.error("need to update ligth count");
return out;
}
count++; count++;
} }
//Log.warning("Get " + count + "/" + out.length + " lights (SUN) ...");
float maxDistance = 50*50; float maxDistance = 50*50;
for (ComponentLight elem: componentLights) { for (ComponentLight elem: this.componentLights) {
Vector3f pos = elem.getPosition(); Vector3f pos = elem.getPosition();
if (count>=8) { if (count>=8) {
Log.error("need to update ligth count"); Log.error("need to update ligth count");
@ -80,6 +83,7 @@ public class EngineLight extends Engine {
count++; count++;
} }
} }
//Log.warning("Get " + count + "/" + out.length + " lights...");
return out; return out;
} }