From 2e26ce235d00fdc633559f9404ddd8ec70c96df7 Mon Sep 17 00:00:00 2001 From: victorfisac Date: Mon, 30 May 2016 19:18:11 +0200 Subject: Add Draw3DCircle function and update raylib and rlgl header Draw3DCircle is useful to draw point lights radius. --- src/models.c | 19 +++++++++++++++++++ src/raylib.h | 3 ++- src/rlgl.h | 2 +- 3 files changed, 22 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/models.c b/src/models.c index 07dee720..6ffb561e 100644 --- a/src/models.c +++ b/src/models.c @@ -75,6 +75,25 @@ void Draw3DLine(Vector3 startPos, Vector3 endPos, Color color) rlEnd(); } +// Draw a circle in 3D world space +void Draw3DCircle(Vector3 center, float radius, float rotationAngle, Vector3 rotation, Color color) +{ + rlPushMatrix(); + rlTranslatef(center.x, center.y, center.z); + rlRotatef(rotationAngle, rotation.x, rotation.y, rotation.z); + + rlBegin(RL_LINES); + for (int i = 0; i < 360; i += 10) + { + rlColor4ub(color.r, color.g, color.b, color.a); + + rlVertex3f(sin(DEG2RAD*i)*radius, cos(DEG2RAD*i)*radius, 0.0f); + rlVertex3f(sin(DEG2RAD*(i + 10)) * radius, cos(DEG2RAD*(i + 10)) * radius, 0.0f); + } + rlEnd(); + rlPopMatrix(); +} + // Draw cube // NOTE: Cube position is the center position void DrawCube(Vector3 position, float width, float height, float length, Color color) diff --git a/src/raylib.h b/src/raylib.h index d0231be2..0af7ef31 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -437,7 +437,7 @@ typedef struct LightData { Vector3 position; Vector3 target; // Used on LIGHT_DIRECTIONAL and LIGHT_SPOT (cone direction target) - float attenuation; // Lost of light intensity with distance (world distance) + float radius; // Lost of light intensity with distance (world distance) Color diffuse; // Light color float intensity; // Light intensity level @@ -803,6 +803,7 @@ const char *SubText(const char *text, int position, int length); // Basic 3d Shapes Drawing Functions (Module: models) //------------------------------------------------------------------------------------ void Draw3DLine(Vector3 startPos, Vector3 endPos, Color color); // Draw a line in 3D world space +void Draw3DCircle(Vector3 center, float radius, float rotationAngle, Vector3 rotation, Color color); // Draw a circle in 3D world space void DrawCube(Vector3 position, float width, float height, float lenght, Color color); // Draw cube void DrawCubeV(Vector3 position, Vector3 size, Color color); // Draw cube (Vector version) void DrawCubeWires(Vector3 position, float width, float height, float lenght, Color color); // Draw cube wires diff --git a/src/rlgl.h b/src/rlgl.h index a3ba6cd5..d4a2dabe 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -218,7 +218,7 @@ typedef enum { OPENGL_11 = 1, OPENGL_33, OPENGL_ES_20 } GlVersion; Vector3 position; Vector3 target; // Used on LIGHT_DIRECTIONAL and LIGHT_SPOT (cone direction target) - float attenuation; // Lost of light intensity with distance (world distance) + float radius; // Lost of light intensity with distance (world distance) Color diffuse; // Use Vector3 diffuse float intensity; -- cgit v1.2.3 From 64f6c74c9aafc00b727c0f959a64d43f7e6bfab0 Mon Sep 17 00:00:00 2001 From: victorfisac Date: Mon, 30 May 2016 19:18:55 +0200 Subject: Add normal and specular maps to draw model process --- src/rlgl.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/rlgl.c b/src/rlgl.c index cc4c4c2f..d781b755 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -204,8 +204,8 @@ static bool texCompPVRTSupported = false; // PVR texture compression support static bool texCompASTCSupported = false; // ASTC texture compression support // Lighting data -static Light lights[MAX_LIGHTS]; // Lights pool -static int lightsCount; // Counts current enabled physic objects +static Light lights[MAX_LIGHTS]; // Lights pool +static int lightsCount; // Counts current enabled physic objects #endif // Compressed textures support flags @@ -1810,6 +1810,9 @@ void rlglDrawMesh(Mesh mesh, Material material, Matrix transform) if ((material.texNormal.id != 0) && (material.shader.mapTexture1Loc != -1)) { + // Upload to shader specular map flag + glUniform1i(glGetUniformLocation(material.shader.id, "useNormal"), 1); + glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, material.texNormal.id); glUniform1i(material.shader.mapTexture1Loc, 1); // Normal texture fits in active texture unit 1 @@ -1820,6 +1823,9 @@ void rlglDrawMesh(Mesh mesh, Material material, Matrix transform) if ((material.texSpecular.id != 0) && (material.shader.mapTexture2Loc != -1)) { + // Upload to shader specular map flag + glUniform1i(glGetUniformLocation(material.shader.id, "useSpecular"), 1); + glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, material.texSpecular.id); glUniform1i(material.shader.mapTexture2Loc, 2); // Specular texture fits in active texture unit 2 @@ -2293,7 +2299,13 @@ void DrawLights(void) { switch (lights[i]->type) { - case LIGHT_POINT: DrawSphereWires(lights[i]->position, 0.3f*lights[i]->intensity, 4, 8, (lights[i]->enabled ? lights[i]->diffuse : BLACK)); break; + case LIGHT_POINT: + { + DrawSphereWires(lights[i]->position, 0.3f*lights[i]->intensity, 4, 8, (lights[i]->enabled ? lights[i]->diffuse : BLACK)); + Draw3DCircle(lights[i]->position, lights[i]->radius, 0.0f, (Vector3){ 0, 0, 0 }, (lights[i]->enabled ? lights[i]->diffuse : BLACK)); + Draw3DCircle(lights[i]->position, lights[i]->radius, 90.0f, (Vector3){ 1, 0, 0 }, (lights[i]->enabled ? lights[i]->diffuse : BLACK)); + Draw3DCircle(lights[i]->position, lights[i]->radius, 90.0f, (Vector3){ 0, 1, 0 }, (lights[i]->enabled ? lights[i]->diffuse : BLACK)); + } break; case LIGHT_DIRECTIONAL: { Draw3DLine(lights[i]->position, lights[i]->target, (lights[i]->enabled ? lights[i]->diffuse : BLACK)); @@ -3105,9 +3117,9 @@ static void SetShaderLights(Shader shader) locPoint = GetShaderLocation(shader, locName); glUniform3f(locPoint, lights[i]->position.x, lights[i]->position.y, lights[i]->position.z); - memcpy(&locName[10], "attenuation\0", strlen("attenuation\0")); + memcpy(&locName[10], "radius\0", strlen("radius\0") + 2); locPoint = GetShaderLocation(shader, locName); - glUniform1f(locPoint, lights[i]->attenuation); + glUniform1f(locPoint, lights[i]->radius); } break; case LIGHT_DIRECTIONAL: { -- cgit v1.2.3 From f2d61d4043850e89b2d2cb7bacffe628aef0b981 Mon Sep 17 00:00:00 2001 From: victorfisac Date: Mon, 30 May 2016 19:43:35 +0200 Subject: Remove normal depth Scaling normal depth (y axis) makes disappear the specular of fragments... So I think it can be removed, it is not a very useful/important attribute. --- src/models.c | 1 - src/raylib.h | 1 - src/rlgl.c | 5 +---- src/rlgl.h | 1 - 4 files changed, 1 insertion(+), 7 deletions(-) (limited to 'src') diff --git a/src/models.c b/src/models.c index 6ffb561e..90b752fd 100644 --- a/src/models.c +++ b/src/models.c @@ -756,7 +756,6 @@ Material LoadDefaultMaterial(void) material.colSpecular = WHITE; // Specular color material.glossiness = 100.0f; // Glossiness level - material.normalDepth = 1.0f; // Normal map depth return material; } diff --git a/src/raylib.h b/src/raylib.h index 0af7ef31..73a36a16 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -419,7 +419,6 @@ typedef struct Material { Color colSpecular; // Specular color float glossiness; // Glossiness level (Ranges from 0 to 1000) - float normalDepth; // Normal map depth } Material; // Model type diff --git a/src/rlgl.c b/src/rlgl.c index d781b755..b4569207 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -1816,9 +1816,6 @@ void rlglDrawMesh(Mesh mesh, Material material, Matrix transform) glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, material.texNormal.id); glUniform1i(material.shader.mapTexture1Loc, 1); // Normal texture fits in active texture unit 1 - - // TODO: Upload to shader normalDepth - //glUniform1f(???, material.normalDepth); } if ((material.texSpecular.id != 0) && (material.shader.mapTexture2Loc != -1)) @@ -2565,7 +2562,7 @@ static Shader LoadDefaultShader(void) // Load standard shader // NOTE: This shader supports: // - Up to 3 different maps: diffuse, normal, specular -// - Material properties: colAmbient, colDiffuse, colSpecular, glossiness, normalDepth +// - Material properties: colAmbient, colDiffuse, colSpecular, glossiness // - Up to 8 lights: Point, Directional or Spot static Shader LoadStandardShader(void) { diff --git a/src/rlgl.h b/src/rlgl.h index d4a2dabe..dc16e807 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -207,7 +207,6 @@ typedef enum { OPENGL_11 = 1, OPENGL_33, OPENGL_ES_20 } GlVersion; Color colSpecular; // Specular color float glossiness; // Glossiness level (Ranges from 0 to 1000) - float normalDepth; // Normal map depth } Material; // Light type -- cgit v1.2.3 From b0a0c5d4312d05d460cdd12f6af12321b0a55e66 Mon Sep 17 00:00:00 2001 From: victorfisac Date: Mon, 30 May 2016 19:55:13 +0200 Subject: Added tint color attribute to material data type It tints all fragments, ignores lighting. Useful for some features like feedback (damage color, ...). --- src/models.c | 3 ++- src/raylib.h | 1 + src/rlgl.c | 3 +++ src/rlgl.h | 1 + 4 files changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/models.c b/src/models.c index 90b752fd..092a43fc 100644 --- a/src/models.c +++ b/src/models.c @@ -751,6 +751,7 @@ Material LoadDefaultMaterial(void) //material.texNormal; // NOTE: By default, not set //material.texSpecular; // NOTE: By default, not set + material.colTint = WHITE; // Tint color material.colDiffuse = WHITE; // Diffuse color material.colAmbient = WHITE; // Ambient color material.colSpecular = WHITE; // Specular color @@ -1268,7 +1269,7 @@ void DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis, float rota //Matrix matModel = MatrixMultiply(model.transform, matTransform); // Transform to world-space coordinates model.transform = MatrixMultiply(MatrixMultiply(matScale, matRotation), matTranslation); - // model.material.colDiffuse = tint; + model.material.colTint = tint; rlglDrawMesh(model.mesh, model.material, model.transform); } diff --git a/src/raylib.h b/src/raylib.h index 73a36a16..dfec956d 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -414,6 +414,7 @@ typedef struct Material { Texture2D texNormal; // Normal texture (binded to shader mapTexture1Loc) Texture2D texSpecular; // Specular texture (binded to shader mapTexture2Loc) + Color colTint; // Tint color Color colDiffuse; // Diffuse color Color colAmbient; // Ambient color Color colSpecular; // Specular color diff --git a/src/rlgl.c b/src/rlgl.c index b4569207..0f68953e 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -1793,6 +1793,9 @@ void rlglDrawMesh(Mesh mesh, Material material, Matrix transform) // Setup shader uniforms for lights SetShaderLights(material.shader); + // Upload to shader material.colSpecular + glUniform4f(glGetUniformLocation(material.shader.id, "colTint"), (float)material.colTint.r/255, (float)material.colTint.g/255, (float)material.colTint.b/255, (float)material.colTint.a/255); + // Upload to shader material.colAmbient glUniform4f(glGetUniformLocation(material.shader.id, "colAmbient"), (float)material.colAmbient.r/255, (float)material.colAmbient.g/255, (float)material.colAmbient.b/255, (float)material.colAmbient.a/255); diff --git a/src/rlgl.h b/src/rlgl.h index dc16e807..23ad29fb 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -202,6 +202,7 @@ typedef enum { OPENGL_11 = 1, OPENGL_33, OPENGL_ES_20 } GlVersion; Texture2D texNormal; // Normal texture Texture2D texSpecular; // Specular texture + Color colTint; // Tint color Color colDiffuse; // Diffuse color Color colAmbient; // Ambient color Color colSpecular; // Specular color -- cgit v1.2.3