Merge branch 'master' of https://github.com/raysan5/raylib
|
|
@ -7,6 +7,7 @@ Some people ported raylib to other languages in form of bindings or wrappers to
|
||||||
| name | raylib version | language | license | repo |
|
| name | raylib version | language | license | repo |
|
||||||
|:------------------:|:---------------:|:---------:|:----------:|-----------------------------------------------------------|
|
|:------------------:|:---------------:|:---------:|:----------:|-----------------------------------------------------------|
|
||||||
| raylib | **5.0** | [C/C++](https://en.wikipedia.org/wiki/C_(programming_language)) | Zlib | https://github.com/raysan5/raylib |
|
| raylib | **5.0** | [C/C++](https://en.wikipedia.org/wiki/C_(programming_language)) | Zlib | https://github.com/raysan5/raylib |
|
||||||
|
| raylib-beef | **5.0** | [Beef](https://www.beeflang.org/) | MIT | https://github.com/Starpelly/raylib-beef |
|
||||||
| raylib-boo | 3.7 | [Boo](http://boo-language.github.io/)| MIT | https://github.com/Rabios/raylib-boo |
|
| raylib-boo | 3.7 | [Boo](http://boo-language.github.io/)| MIT | https://github.com/Rabios/raylib-boo |
|
||||||
| Raylib-cs | **4.5** | [C#](https://en.wikipedia.org/wiki/C_Sharp_(programming_language)) | Zlib | https://github.com/ChrisDill/Raylib-cs |
|
| Raylib-cs | **4.5** | [C#](https://en.wikipedia.org/wiki/C_Sharp_(programming_language)) | Zlib | https://github.com/ChrisDill/Raylib-cs |
|
||||||
| Raylib-CsLo | 4.2 | [C#](https://en.wikipedia.org/wiki/C_Sharp_(programming_language)) | MPL-2.0 | https://github.com/NotNotTech/Raylib-CsLo |
|
| Raylib-CsLo | 4.2 | [C#](https://en.wikipedia.org/wiki/C_Sharp_(programming_language)) | MPL-2.0 | https://github.com/NotNotTech/Raylib-CsLo |
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
cmake_minimum_required(VERSION 3.0)
|
cmake_minimum_required(VERSION 3.5)
|
||||||
project(raylib)
|
project(raylib)
|
||||||
|
|
||||||
# Avoid excessive expansion of variables in conditionals. In particular, if
|
# Avoid excessive expansion of variables in conditionals. In particular, if
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
*
|
*
|
||||||
* raylib [audio] example - Music stream processing effects
|
* raylib [audio] example - Music stream processing effects
|
||||||
*
|
*
|
||||||
* Example originally created with raylib 4.2, last time updated with raylib 4.2
|
* Example originally created with raylib 4.2, last time updated with raylib 5.0
|
||||||
*
|
*
|
||||||
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
|
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
|
||||||
* BSD-like license that allows static linking with closed source software
|
* BSD-like license that allows static linking with closed source software
|
||||||
|
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
|
||||||
#include <stdlib.h> // Required for: NULL
|
#include <stdlib.h> // Required for: NULL
|
||||||
|
|
||||||
// Required delay effect variables
|
// Required delay effect variables
|
||||||
static float *delayBuffer = NULL;
|
static float *delayBuffer = NULL;
|
||||||
|
|
@ -149,13 +149,17 @@ static void AudioProcessEffectLPF(void *buffer, unsigned int frames)
|
||||||
static const float cutoff = 70.0f / 44100.0f; // 70 Hz lowpass filter
|
static const float cutoff = 70.0f / 44100.0f; // 70 Hz lowpass filter
|
||||||
const float k = cutoff / (cutoff + 0.1591549431f); // RC filter formula
|
const float k = cutoff / (cutoff + 0.1591549431f); // RC filter formula
|
||||||
|
|
||||||
|
// Converts the buffer data before using it
|
||||||
|
float *bufferData = (float *)buffer;
|
||||||
for (unsigned int i = 0; i < frames*2; i += 2)
|
for (unsigned int i = 0; i < frames*2; i += 2)
|
||||||
{
|
{
|
||||||
float l = ((float *)buffer)[i], r = ((float *)buffer)[i + 1];
|
const float l = bufferData[i];
|
||||||
|
const float r = bufferData[i + 1];
|
||||||
|
|
||||||
low[0] += k * (l - low[0]);
|
low[0] += k * (l - low[0]);
|
||||||
low[1] += k * (r - low[1]);
|
low[1] += k * (r - low[1]);
|
||||||
((float *)buffer)[i] = low[0];
|
bufferData[i] = low[0];
|
||||||
((float *)buffer)[i + 1] = low[1];
|
bufferData[i + 1] = low[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -176,4 +180,4 @@ static void AudioProcessEffectDelay(void *buffer, unsigned int frames)
|
||||||
delayBuffer[delayWriteIndex++] = ((float *)buffer)[i + 1];
|
delayBuffer[delayWriteIndex++] = ((float *)buffer)[i + 1];
|
||||||
if (delayWriteIndex == delayBufferSize) delayWriteIndex = 0;
|
if (delayWriteIndex == delayBufferSize) delayWriteIndex = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,6 @@ int main(void)
|
||||||
.vResolution = 1200, // Vertical resolution in pixels
|
.vResolution = 1200, // Vertical resolution in pixels
|
||||||
.hScreenSize = 0.133793f, // Horizontal size in meters
|
.hScreenSize = 0.133793f, // Horizontal size in meters
|
||||||
.vScreenSize = 0.0669f, // Vertical size in meters
|
.vScreenSize = 0.0669f, // Vertical size in meters
|
||||||
.vScreenCenter = 0.04678f, // Screen center in meters
|
|
||||||
.eyeToScreenDistance = 0.041f, // Distance between eye and display in meters
|
.eyeToScreenDistance = 0.041f, // Distance between eye and display in meters
|
||||||
.lensSeparationDistance = 0.07f, // Lens separation distance in meters
|
.lensSeparationDistance = 0.07f, // Lens separation distance in meters
|
||||||
.interpupillaryDistance = 0.07f, // IPD (distance between pupils) in meters
|
.interpupillaryDistance = 0.07f, // IPD (distance between pupils) in meters
|
||||||
|
|
|
||||||
BIN
examples/shaders/resources/models/old_car_new.glb
Normal file
BIN
examples/shaders/resources/models/plane.glb
Normal file
BIN
examples/shaders/resources/old_car_d.png
Normal file
|
After Width: | Height: | Size: 1.6 MiB |
BIN
examples/shaders/resources/old_car_e.png
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
examples/shaders/resources/old_car_mra.png
Normal file
|
After Width: | Height: | Size: 1.1 MiB |
BIN
examples/shaders/resources/old_car_n.png
Normal file
|
After Width: | Height: | Size: 1.2 MiB |
BIN
examples/shaders/resources/road_a.png
Normal file
|
After Width: | Height: | Size: 623 KiB |
BIN
examples/shaders/resources/road_mra.png
Normal file
|
After Width: | Height: | Size: 657 KiB |
BIN
examples/shaders/resources/road_n.png
Normal file
|
After Width: | Height: | Size: 645 KiB |
156
examples/shaders/resources/shaders/glsl100/pbr.fs
Normal file
|
|
@ -0,0 +1,156 @@
|
||||||
|
#version 100
|
||||||
|
|
||||||
|
precision mediump float;
|
||||||
|
|
||||||
|
#define MAX_LIGHTS 4
|
||||||
|
#define LIGHT_DIRECTIONAL 0
|
||||||
|
#define LIGHT_POINT 1
|
||||||
|
#define PI 3.14159265358979323846
|
||||||
|
|
||||||
|
struct Light {
|
||||||
|
int enabled;
|
||||||
|
int type;
|
||||||
|
vec3 position;
|
||||||
|
vec3 target;
|
||||||
|
vec4 color;
|
||||||
|
float intensity;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Input vertex attributes (from vertex shader)
|
||||||
|
varying in vec3 fragPosition;
|
||||||
|
varying in vec2 fragTexCoord;
|
||||||
|
varying in vec4 fragColor;
|
||||||
|
varying in vec3 fragNormal;
|
||||||
|
varying in vec4 shadowPos;
|
||||||
|
varying in mat3 TBN;
|
||||||
|
|
||||||
|
|
||||||
|
// Input uniform values
|
||||||
|
uniform int numOfLights;
|
||||||
|
uniform sampler2D albedoMap;
|
||||||
|
uniform sampler2D mraMap;
|
||||||
|
uniform sampler2D normalMap;
|
||||||
|
uniform sampler2D emissiveMap; // r: Hight g:emissive
|
||||||
|
|
||||||
|
uniform vec2 tiling;
|
||||||
|
uniform vec2 offset;
|
||||||
|
|
||||||
|
uniform int useTexAlbedo;
|
||||||
|
uniform int useTexNormal;
|
||||||
|
uniform int useTexMRA;
|
||||||
|
uniform int useTexEmissive;
|
||||||
|
|
||||||
|
uniform vec4 albedoColor;
|
||||||
|
uniform vec4 emissiveColor;
|
||||||
|
uniform float normalValue;
|
||||||
|
uniform float metallicValue;
|
||||||
|
uniform float roughnessValue;
|
||||||
|
uniform float aoValue;
|
||||||
|
uniform float emissivePower;
|
||||||
|
|
||||||
|
// Input lighting values
|
||||||
|
uniform Light lights[MAX_LIGHTS];
|
||||||
|
uniform vec3 viewPos;
|
||||||
|
|
||||||
|
uniform vec3 ambientColor;
|
||||||
|
uniform float ambient;
|
||||||
|
|
||||||
|
// refl in range 0 to 1
|
||||||
|
// returns base reflectivity to 1
|
||||||
|
// incrase reflectivity when surface view at larger angle
|
||||||
|
vec3 schlickFresnel(float hDotV,vec3 refl)
|
||||||
|
{
|
||||||
|
return refl + (1.0 - refl) * pow(1.0 - hDotV,5.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
float ggxDistribution(float nDotH,float roughness)
|
||||||
|
{
|
||||||
|
float a = roughness * roughness * roughness * roughness;
|
||||||
|
float d = nDotH * nDotH * (a - 1.0) + 1.0;
|
||||||
|
d = PI * d * d;
|
||||||
|
return a / max(d,0.0000001);
|
||||||
|
}
|
||||||
|
|
||||||
|
float geomSmith(float nDotV,float nDotL,float roughness)
|
||||||
|
{
|
||||||
|
float r = roughness + 1.0;
|
||||||
|
float k = r * r / 8.0;
|
||||||
|
float ik = 1.0 - k;
|
||||||
|
float ggx1 = nDotV / (nDotV * ik + k);
|
||||||
|
float ggx2 = nDotL / (nDotL * ik + k);
|
||||||
|
return ggx1 * ggx2;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 pbr(){
|
||||||
|
vec3 albedo = texture2D(albedoMap,vec2(fragTexCoord.x*tiling.x+offset.x,fragTexCoord.y*tiling.y+offset.y)).rgb;
|
||||||
|
albedo = vec3(albedoColor.x*albedo.x,albedoColor.y*albedo.y,albedoColor.z*albedo.z);
|
||||||
|
float metallic = clamp(metallicValue,0.0,1.0);
|
||||||
|
float roughness = clamp(roughnessValue,0.0,1.0);
|
||||||
|
float ao = clamp(aoValue,0.0,1.0);
|
||||||
|
if(useTexMRA == 1) {
|
||||||
|
vec4 mra = texture2D(mraMap, vec2(fragTexCoord.x * tiling.x + offset.x, fragTexCoord.y * tiling.y + offset.y));
|
||||||
|
metallic = clamp(mra.r+metallicValue,0.04,1.0);
|
||||||
|
roughness = clamp(mra.g+roughnessValue,0.04,1.0);
|
||||||
|
ao = (mra.b+aoValue)*0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
vec3 N = normalize(fragNormal);
|
||||||
|
if(useTexNormal == 1) {
|
||||||
|
N = texture2D(normalMap, vec2(fragTexCoord.x * tiling.x + offset.y, fragTexCoord.y * tiling.y + offset.y)).rgb;
|
||||||
|
N = normalize(N * 2.0 - 1.0);
|
||||||
|
N = normalize(N * TBN);
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 V = normalize(viewPos - fragPosition);
|
||||||
|
|
||||||
|
vec3 e = vec3(0);
|
||||||
|
e = (texture2D(emissiveMap, vec2(fragTexCoord.x*tiling.x+offset.x, fragTexCoord.y*tiling.y+offset.y)).rgb).g * emissiveColor.rgb*emissivePower * float(useTexEmissive);
|
||||||
|
|
||||||
|
//return N;//vec3(metallic,metallic,metallic);
|
||||||
|
//if dia-electric use base reflectivity of 0.04 otherwise ut is a metal use albedo as base reflectivity
|
||||||
|
vec3 baseRefl = mix(vec3(0.04),albedo.rgb,metallic);
|
||||||
|
vec3 Lo = vec3(0.0); // acumulate lighting lum
|
||||||
|
|
||||||
|
for(int i=0;i<numOfLights;++i){
|
||||||
|
|
||||||
|
vec3 L = normalize(lights[i].position - fragPosition); // calc light vector
|
||||||
|
vec3 H = normalize(V + L); // calc halfway bisecting vector
|
||||||
|
float dist = length(lights[i].position - fragPosition); // calc distance to light
|
||||||
|
float attenuation = 1.0 / (dist * dist * 0.23); // calc attenuation
|
||||||
|
vec3 radiance = lights[i].color.rgb * lights[i].intensity * attenuation; // calc input radiance,light energy comming in
|
||||||
|
|
||||||
|
//Cook-Torrance BRDF distribution function
|
||||||
|
float nDotV = max(dot(N,V),0.0000001);
|
||||||
|
float nDotL = max(dot(N,L),0.0000001);
|
||||||
|
float hDotV = max(dot(H,V),0.0);
|
||||||
|
float nDotH = max(dot(N,H),0.0);
|
||||||
|
float D = ggxDistribution(nDotH,roughness); // larger the more micro-facets aligned to H
|
||||||
|
float G = geomSmith(nDotV,nDotL,roughness); // smaller the more micro-facets shadow
|
||||||
|
vec3 F = schlickFresnel(hDotV, baseRefl); // fresnel proportion of specular reflectance
|
||||||
|
|
||||||
|
vec3 spec = (D * G * F) / (4.0 * nDotV * nDotL);
|
||||||
|
// difuse and spec light can't be above 1.0
|
||||||
|
// kD = 1.0 - kS diffuse component is equal 1.0 - spec comonent
|
||||||
|
vec3 kD = vec3(1.0) - F;
|
||||||
|
//mult kD by the inverse of metallnes , only non-metals should have diffuse light
|
||||||
|
kD *= 1.0 - metallic;
|
||||||
|
Lo += ((kD * albedo.rgb / PI + spec) * radiance * nDotL)*float(lights[i].enabled); // angle of light has impact on result
|
||||||
|
}
|
||||||
|
vec3 ambient_final = (ambientColor + albedo)* ambient * 0.5;
|
||||||
|
return ambient_final+Lo*ao+e;
|
||||||
|
}
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec3 color = pbr();
|
||||||
|
|
||||||
|
//HDR tonemapping
|
||||||
|
color = pow(color,color + vec3(1.0));
|
||||||
|
//gamma correction
|
||||||
|
color = pow(color,vec3(1.0/2.2));
|
||||||
|
|
||||||
|
gl_FragColor = vec4(color,1.0);
|
||||||
|
|
||||||
|
}
|
||||||
75
examples/shaders/resources/shaders/glsl100/pbr.vs
Normal file
|
|
@ -0,0 +1,75 @@
|
||||||
|
#version 100
|
||||||
|
|
||||||
|
// Input vertex attributes
|
||||||
|
attribute vec3 vertexPosition;
|
||||||
|
attribute vec2 vertexTexCoord;
|
||||||
|
attribute vec3 vertexNormal;
|
||||||
|
attribute vec3 vertexTangent;
|
||||||
|
attribute vec4 vertexColor;
|
||||||
|
|
||||||
|
// Input uniform values
|
||||||
|
uniform mat4 mvp;
|
||||||
|
uniform mat4 matModel;
|
||||||
|
uniform mat4 matNormal;
|
||||||
|
uniform vec3 lightPos;
|
||||||
|
uniform vec4 difColor;
|
||||||
|
|
||||||
|
// Output vertex attributes (to fragment shader)
|
||||||
|
varying vec3 fragPosition;
|
||||||
|
varying vec2 fragTexCoord;
|
||||||
|
varying vec4 fragColor;
|
||||||
|
varying vec3 fragNormal;
|
||||||
|
varying mat3 TBN;
|
||||||
|
|
||||||
|
const float normalOffset = 0.1;
|
||||||
|
|
||||||
|
// https://github.com/glslify/glsl-inverse
|
||||||
|
mat3 inverse(mat3 m)
|
||||||
|
{
|
||||||
|
float a00 = m[0][0], a01 = m[0][1], a02 = m[0][2];
|
||||||
|
float a10 = m[1][0], a11 = m[1][1], a12 = m[1][2];
|
||||||
|
float a20 = m[2][0], a21 = m[2][1], a22 = m[2][2];
|
||||||
|
|
||||||
|
float b01 = a22*a11 - a12*a21;
|
||||||
|
float b11 = -a22*a10 + a12*a20;
|
||||||
|
float b21 = a21*a10 - a11*a20;
|
||||||
|
|
||||||
|
float det = a00*b01 + a01*b11 + a02*b21;
|
||||||
|
|
||||||
|
return mat3(b01, (-a22*a01 + a02*a21), (a12*a01 - a02*a11),
|
||||||
|
b11, (a22*a00 - a02*a20), (-a12*a00 + a02*a10),
|
||||||
|
b21, (-a21*a00 + a01*a20), (a11*a00 - a01*a10))/det;
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://github.com/glslify/glsl-transpose
|
||||||
|
mat3 transpose(mat3 m)
|
||||||
|
{
|
||||||
|
return mat3(m[0][0], m[1][0], m[2][0],
|
||||||
|
m[0][1], m[1][1], m[2][1],
|
||||||
|
m[0][2], m[1][2], m[2][2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
|
||||||
|
// calc binormal from vertex normal and tangent
|
||||||
|
vec3 vertexBinormal = cross(vertexNormal, vertexTangent);
|
||||||
|
// calc fragment normal based on normal transformations
|
||||||
|
mat3 normalMatrix = transpose(inverse(mat3(matModel)));
|
||||||
|
// calc fragment position based on model transformations
|
||||||
|
|
||||||
|
fragPosition = vec3(matModel*vec4(vertexPosition, 1.0));
|
||||||
|
|
||||||
|
fragTexCoord = vertexTexCoord*2.0;
|
||||||
|
|
||||||
|
fragNormal = normalize(normalMatrix*vertexNormal);
|
||||||
|
vec3 fragTangent = normalize(normalMatrix*vertexTangent);
|
||||||
|
fragTangent = normalize(fragTangent - dot(fragTangent, fragNormal)*fragNormal);
|
||||||
|
vec3 fragBinormal = normalize(normalMatrix*vertexBinormal);
|
||||||
|
fragBinormal = cross(fragNormal, fragTangent);
|
||||||
|
|
||||||
|
TBN = transpose(mat3(fragTangent, fragBinormal, fragNormal));
|
||||||
|
|
||||||
|
// Calculate final vertex position
|
||||||
|
gl_Position = mvp * vec4(vertexPosition, 1.0);
|
||||||
|
}
|
||||||
156
examples/shaders/resources/shaders/glsl120/pbr.fs
Normal file
|
|
@ -0,0 +1,156 @@
|
||||||
|
#version 120
|
||||||
|
|
||||||
|
precision mediump float;
|
||||||
|
|
||||||
|
#define MAX_LIGHTS 4
|
||||||
|
#define LIGHT_DIRECTIONAL 0
|
||||||
|
#define LIGHT_POINT 1
|
||||||
|
#define PI 3.14159265358979323846
|
||||||
|
|
||||||
|
struct Light {
|
||||||
|
int enabled;
|
||||||
|
int type;
|
||||||
|
vec3 position;
|
||||||
|
vec3 target;
|
||||||
|
vec4 color;
|
||||||
|
float intensity;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Input vertex attributes (from vertex shader)
|
||||||
|
varying in vec3 fragPosition;
|
||||||
|
varying in vec2 fragTexCoord;
|
||||||
|
varying in vec4 fragColor;
|
||||||
|
varying in vec3 fragNormal;
|
||||||
|
varying in vec4 shadowPos;
|
||||||
|
varying in mat3 TBN;
|
||||||
|
|
||||||
|
|
||||||
|
// Input uniform values
|
||||||
|
uniform int numOfLights;
|
||||||
|
uniform sampler2D albedoMap;
|
||||||
|
uniform sampler2D mraMap;
|
||||||
|
uniform sampler2D normalMap;
|
||||||
|
uniform sampler2D emissiveMap; // r: Hight g:emissive
|
||||||
|
|
||||||
|
uniform vec2 tiling;
|
||||||
|
uniform vec2 offset;
|
||||||
|
|
||||||
|
uniform int useTexAlbedo;
|
||||||
|
uniform int useTexNormal;
|
||||||
|
uniform int useTexMRA;
|
||||||
|
uniform int useTexEmissive;
|
||||||
|
|
||||||
|
uniform vec4 albedoColor;
|
||||||
|
uniform vec4 emissiveColor;
|
||||||
|
uniform float normalValue;
|
||||||
|
uniform float metallicValue;
|
||||||
|
uniform float roughnessValue;
|
||||||
|
uniform float aoValue;
|
||||||
|
uniform float emissivePower;
|
||||||
|
|
||||||
|
// Input lighting values
|
||||||
|
uniform Light lights[MAX_LIGHTS];
|
||||||
|
uniform vec3 viewPos;
|
||||||
|
|
||||||
|
uniform vec3 ambientColor;
|
||||||
|
uniform float ambient;
|
||||||
|
|
||||||
|
// refl in range 0 to 1
|
||||||
|
// returns base reflectivity to 1
|
||||||
|
// incrase reflectivity when surface view at larger angle
|
||||||
|
vec3 schlickFresnel(float hDotV,vec3 refl)
|
||||||
|
{
|
||||||
|
return refl + (1.0 - refl) * pow(1.0 - hDotV,5.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
float ggxDistribution(float nDotH,float roughness)
|
||||||
|
{
|
||||||
|
float a = roughness * roughness * roughness * roughness;
|
||||||
|
float d = nDotH * nDotH * (a - 1.0) + 1.0;
|
||||||
|
d = PI * d * d;
|
||||||
|
return a / max(d,0.0000001);
|
||||||
|
}
|
||||||
|
|
||||||
|
float geomSmith(float nDotV,float nDotL,float roughness)
|
||||||
|
{
|
||||||
|
float r = roughness + 1.0;
|
||||||
|
float k = r * r / 8.0;
|
||||||
|
float ik = 1.0 - k;
|
||||||
|
float ggx1 = nDotV / (nDotV * ik + k);
|
||||||
|
float ggx2 = nDotL / (nDotL * ik + k);
|
||||||
|
return ggx1 * ggx2;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 pbr(){
|
||||||
|
vec3 albedo = texture2D(albedoMap,vec2(fragTexCoord.x*tiling.x+offset.x,fragTexCoord.y*tiling.y+offset.y)).rgb;
|
||||||
|
albedo = vec3(albedoColor.x*albedo.x,albedoColor.y*albedo.y,albedoColor.z*albedo.z);
|
||||||
|
float metallic = clamp(metallicValue,0.0,1.0);
|
||||||
|
float roughness = clamp(roughnessValue,0.0,1.0);
|
||||||
|
float ao = clamp(aoValue,0.0,1.0);
|
||||||
|
if(useTexMRA == 1) {
|
||||||
|
vec4 mra = texture2D(mraMap, vec2(fragTexCoord.x * tiling.x + offset.x, fragTexCoord.y * tiling.y + offset.y));
|
||||||
|
metallic = clamp(mra.r+metallicValue,0.04,1.0);
|
||||||
|
roughness = clamp(mra.g+roughnessValue,0.04,1.0);
|
||||||
|
ao = (mra.b+aoValue)*0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
vec3 N = normalize(fragNormal);
|
||||||
|
if(useTexNormal == 1) {
|
||||||
|
N = texture2D(normalMap, vec2(fragTexCoord.x * tiling.x + offset.y, fragTexCoord.y * tiling.y + offset.y)).rgb;
|
||||||
|
N = normalize(N * 2.0 - 1.0);
|
||||||
|
N = normalize(N * TBN);
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 V = normalize(viewPos - fragPosition);
|
||||||
|
|
||||||
|
vec3 e = vec3(0);
|
||||||
|
e = (texture2D(emissiveMap, vec2(fragTexCoord.x*tiling.x+offset.x, fragTexCoord.y*tiling.y+offset.y)).rgb).g * emissiveColor.rgb*emissivePower * float(useTexEmissive);
|
||||||
|
|
||||||
|
//return N;//vec3(metallic,metallic,metallic);
|
||||||
|
//if dia-electric use base reflectivity of 0.04 otherwise ut is a metal use albedo as base reflectivity
|
||||||
|
vec3 baseRefl = mix(vec3(0.04),albedo.rgb,metallic);
|
||||||
|
vec3 Lo = vec3(0.0); // acumulate lighting lum
|
||||||
|
|
||||||
|
for(int i=0;i<numOfLights;++i){
|
||||||
|
|
||||||
|
vec3 L = normalize(lights[i].position - fragPosition); // calc light vector
|
||||||
|
vec3 H = normalize(V + L); // calc halfway bisecting vector
|
||||||
|
float dist = length(lights[i].position - fragPosition); // calc distance to light
|
||||||
|
float attenuation = 1.0 / (dist * dist * 0.23); // calc attenuation
|
||||||
|
vec3 radiance = lights[i].color.rgb * lights[i].intensity * attenuation; // calc input radiance,light energy comming in
|
||||||
|
|
||||||
|
//Cook-Torrance BRDF distribution function
|
||||||
|
float nDotV = max(dot(N,V),0.0000001);
|
||||||
|
float nDotL = max(dot(N,L),0.0000001);
|
||||||
|
float hDotV = max(dot(H,V),0.0);
|
||||||
|
float nDotH = max(dot(N,H),0.0);
|
||||||
|
float D = ggxDistribution(nDotH,roughness); // larger the more micro-facets aligned to H
|
||||||
|
float G = geomSmith(nDotV,nDotL,roughness); // smaller the more micro-facets shadow
|
||||||
|
vec3 F = schlickFresnel(hDotV, baseRefl); // fresnel proportion of specular reflectance
|
||||||
|
|
||||||
|
vec3 spec = (D * G * F) / (4.0 * nDotV * nDotL);
|
||||||
|
// difuse and spec light can't be above 1.0
|
||||||
|
// kD = 1.0 - kS diffuse component is equal 1.0 - spec comonent
|
||||||
|
vec3 kD = vec3(1.0) - F;
|
||||||
|
//mult kD by the inverse of metallnes , only non-metals should have diffuse light
|
||||||
|
kD *= 1.0 - metallic;
|
||||||
|
Lo += ((kD * albedo.rgb / PI + spec) * radiance * nDotL)*float(lights[i].enabled); // angle of light has impact on result
|
||||||
|
}
|
||||||
|
vec3 ambient_final = (ambientColor + albedo)* ambient * 0.5;
|
||||||
|
return ambient_final+Lo*ao+e;
|
||||||
|
}
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec3 color = pbr();
|
||||||
|
|
||||||
|
//HDR tonemapping
|
||||||
|
color = pow(color,color + vec3(1.0));
|
||||||
|
//gamma correction
|
||||||
|
color = pow(color,vec3(1.0/2.2));
|
||||||
|
|
||||||
|
gl_FragColor = vec4(color,1.0);
|
||||||
|
|
||||||
|
}
|
||||||
75
examples/shaders/resources/shaders/glsl120/pbr.vs
Normal file
|
|
@ -0,0 +1,75 @@
|
||||||
|
#version 120
|
||||||
|
|
||||||
|
// Input vertex attributes
|
||||||
|
attribute vec3 vertexPosition;
|
||||||
|
attribute vec2 vertexTexCoord;
|
||||||
|
attribute vec3 vertexNormal;
|
||||||
|
attribute vec3 vertexTangent;
|
||||||
|
attribute vec4 vertexColor;
|
||||||
|
|
||||||
|
// Input uniform values
|
||||||
|
uniform mat4 mvp;
|
||||||
|
uniform mat4 matModel;
|
||||||
|
uniform mat4 matNormal;
|
||||||
|
uniform vec3 lightPos;
|
||||||
|
uniform vec4 difColor;
|
||||||
|
|
||||||
|
// Output vertex attributes (to fragment shader)
|
||||||
|
varying vec3 fragPosition;
|
||||||
|
varying vec2 fragTexCoord;
|
||||||
|
varying vec4 fragColor;
|
||||||
|
varying vec3 fragNormal;
|
||||||
|
varying mat3 TBN;
|
||||||
|
|
||||||
|
const float normalOffset = 0.1;
|
||||||
|
|
||||||
|
// https://github.com/glslify/glsl-inverse
|
||||||
|
mat3 inverse(mat3 m)
|
||||||
|
{
|
||||||
|
float a00 = m[0][0], a01 = m[0][1], a02 = m[0][2];
|
||||||
|
float a10 = m[1][0], a11 = m[1][1], a12 = m[1][2];
|
||||||
|
float a20 = m[2][0], a21 = m[2][1], a22 = m[2][2];
|
||||||
|
|
||||||
|
float b01 = a22*a11 - a12*a21;
|
||||||
|
float b11 = -a22*a10 + a12*a20;
|
||||||
|
float b21 = a21*a10 - a11*a20;
|
||||||
|
|
||||||
|
float det = a00*b01 + a01*b11 + a02*b21;
|
||||||
|
|
||||||
|
return mat3(b01, (-a22*a01 + a02*a21), (a12*a01 - a02*a11),
|
||||||
|
b11, (a22*a00 - a02*a20), (-a12*a00 + a02*a10),
|
||||||
|
b21, (-a21*a00 + a01*a20), (a11*a00 - a01*a10))/det;
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://github.com/glslify/glsl-transpose
|
||||||
|
mat3 transpose(mat3 m)
|
||||||
|
{
|
||||||
|
return mat3(m[0][0], m[1][0], m[2][0],
|
||||||
|
m[0][1], m[1][1], m[2][1],
|
||||||
|
m[0][2], m[1][2], m[2][2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
|
||||||
|
// calc binormal from vertex normal and tangent
|
||||||
|
vec3 vertexBinormal = cross(vertexNormal, vertexTangent);
|
||||||
|
// calc fragment normal based on normal transformations
|
||||||
|
mat3 normalMatrix = transpose(inverse(mat3(matModel)));
|
||||||
|
// calc fragment position based on model transformations
|
||||||
|
|
||||||
|
fragPosition = vec3(matModel*vec4(vertexPosition, 1.0));
|
||||||
|
|
||||||
|
fragTexCoord = vertexTexCoord*2.0;
|
||||||
|
|
||||||
|
fragNormal = normalize(normalMatrix*vertexNormal);
|
||||||
|
vec3 fragTangent = normalize(normalMatrix*vertexTangent);
|
||||||
|
fragTangent = normalize(fragTangent - dot(fragTangent, fragNormal)*fragNormal);
|
||||||
|
vec3 fragBinormal = normalize(normalMatrix*vertexBinormal);
|
||||||
|
fragBinormal = cross(fragNormal, fragTangent);
|
||||||
|
|
||||||
|
TBN = transpose(mat3(fragTangent, fragBinormal, fragNormal));
|
||||||
|
|
||||||
|
// Calculate final vertex position
|
||||||
|
gl_Position = mvp * vec4(vertexPosition, 1.0);
|
||||||
|
}
|
||||||
159
examples/shaders/resources/shaders/glsl330/pbr.fs
Normal file
|
|
@ -0,0 +1,159 @@
|
||||||
|
#version 330
|
||||||
|
|
||||||
|
#define MAX_LIGHTS 4
|
||||||
|
#define LIGHT_DIRECTIONAL 0
|
||||||
|
#define LIGHT_POINT 1
|
||||||
|
#define PI 3.14159265358979323846
|
||||||
|
|
||||||
|
struct Light {
|
||||||
|
int enabled;
|
||||||
|
int type;
|
||||||
|
vec3 position;
|
||||||
|
vec3 target;
|
||||||
|
vec4 color;
|
||||||
|
float intensity;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Input vertex attributes (from vertex shader)
|
||||||
|
in vec3 fragPosition;
|
||||||
|
in vec2 fragTexCoord;
|
||||||
|
in vec4 fragColor;
|
||||||
|
in vec3 fragNormal;
|
||||||
|
in vec4 shadowPos;
|
||||||
|
in mat3 TBN;
|
||||||
|
|
||||||
|
// Output fragment color
|
||||||
|
out vec4 finalColor;
|
||||||
|
// Input uniform values
|
||||||
|
|
||||||
|
uniform int numOfLights;
|
||||||
|
uniform sampler2D albedoMap;
|
||||||
|
uniform sampler2D mraMap;
|
||||||
|
uniform sampler2D normalMap;
|
||||||
|
uniform sampler2D emissiveMap; // r: Hight g:emissive
|
||||||
|
|
||||||
|
uniform vec2 tiling;
|
||||||
|
uniform vec2 offset;
|
||||||
|
|
||||||
|
uniform int useTexAlbedo;
|
||||||
|
uniform int useTexNormal;
|
||||||
|
uniform int useTexMRA;
|
||||||
|
uniform int useTexEmissive;
|
||||||
|
|
||||||
|
uniform vec4 albedoColor;
|
||||||
|
uniform vec4 emissiveColor;
|
||||||
|
uniform float normalValue;
|
||||||
|
uniform float metallicValue;
|
||||||
|
uniform float roughnessValue;
|
||||||
|
uniform float aoValue;
|
||||||
|
uniform float emissivePower;
|
||||||
|
|
||||||
|
// Input lighting values
|
||||||
|
uniform Light lights[MAX_LIGHTS];
|
||||||
|
uniform vec3 viewPos;
|
||||||
|
|
||||||
|
uniform vec3 ambientColor;
|
||||||
|
uniform float ambient;
|
||||||
|
|
||||||
|
// refl in range 0 to 1
|
||||||
|
// returns base reflectivity to 1
|
||||||
|
// incrase reflectivity when surface view at larger angle
|
||||||
|
vec3 schlickFresnel(float hDotV,vec3 refl)
|
||||||
|
{
|
||||||
|
return refl + (1.0 - refl) * pow(1.0 - hDotV,5.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
float ggxDistribution(float nDotH,float roughness)
|
||||||
|
{
|
||||||
|
float a = roughness * roughness * roughness * roughness;
|
||||||
|
float d = nDotH * nDotH * (a - 1.0) + 1.0;
|
||||||
|
d = PI * d * d;
|
||||||
|
return a / max(d,0.0000001);
|
||||||
|
}
|
||||||
|
|
||||||
|
float geomSmith(float nDotV,float nDotL,float roughness)
|
||||||
|
{
|
||||||
|
float r = roughness + 1.0;
|
||||||
|
float k = r * r / 8.0;
|
||||||
|
float ik = 1.0 - k;
|
||||||
|
float ggx1 = nDotV / (nDotV * ik + k);
|
||||||
|
float ggx2 = nDotL / (nDotL * ik + k);
|
||||||
|
return ggx1 * ggx2;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 pbr(){
|
||||||
|
vec3 albedo = texture(albedoMap,vec2(fragTexCoord.x*tiling.x+offset.x,fragTexCoord.y*tiling.y+offset.y)).rgb;
|
||||||
|
albedo = vec3(albedoColor.x*albedo.x,albedoColor.y*albedo.y,albedoColor.z*albedo.z);
|
||||||
|
float metallic = clamp(metallicValue,0.0,1.0);
|
||||||
|
float roughness = clamp(roughnessValue,0.0,1.0);
|
||||||
|
float ao = clamp(aoValue,0.0,1.0);
|
||||||
|
if(useTexMRA == 1) {
|
||||||
|
vec4 mra = texture(mraMap, vec2(fragTexCoord.x * tiling.x + offset.x, fragTexCoord.y * tiling.y + offset.y)) * useTexMRA;
|
||||||
|
metallic = clamp(mra.r+metallicValue,0.04,1.0);
|
||||||
|
roughness = clamp(mra.g+roughnessValue,0.04,1.0);
|
||||||
|
ao = (mra.b+aoValue)*0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
vec3 N = normalize(fragNormal);
|
||||||
|
if(useTexNormal == 1) {
|
||||||
|
N = texture(normalMap, vec2(fragTexCoord.x * tiling.x + offset.y, fragTexCoord.y * tiling.y + offset.y)).rgb;
|
||||||
|
N = normalize(N * 2.0 - 1.0);
|
||||||
|
N = normalize(N * TBN);
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 V = normalize(viewPos - fragPosition);
|
||||||
|
|
||||||
|
vec3 e = vec3(0);
|
||||||
|
e = (texture(emissiveMap, vec2(fragTexCoord.x*tiling.x+offset.x, fragTexCoord.y*tiling.y+offset.y)).rgb).g * emissiveColor.rgb*emissivePower * useTexEmissive;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//return N;//vec3(metallic,metallic,metallic);
|
||||||
|
//if dia-electric use base reflectivity of 0.04 otherwise ut is a metal use albedo as base reflectivity
|
||||||
|
vec3 baseRefl = mix(vec3(0.04),albedo.rgb,metallic);
|
||||||
|
vec3 Lo = vec3(0.0); // acumulate lighting lum
|
||||||
|
|
||||||
|
for(int i=0;i<numOfLights;++i){
|
||||||
|
|
||||||
|
vec3 L = normalize(lights[i].position - fragPosition); // calc light vector
|
||||||
|
vec3 H = normalize(V + L); // calc halfway bisecting vector
|
||||||
|
float dist = length(lights[i].position - fragPosition); // calc distance to light
|
||||||
|
float attenuation = 1.0 / (dist * dist * 0.23); // calc attenuation
|
||||||
|
vec3 radiance = lights[i].color.rgb * lights[i].intensity * attenuation; // calc input radiance,light energy comming in
|
||||||
|
|
||||||
|
//Cook-Torrance BRDF distribution function
|
||||||
|
float nDotV = max(dot(N,V),0.0000001);
|
||||||
|
float nDotL = max(dot(N,L),0.0000001);
|
||||||
|
float hDotV = max(dot(H,V),0.0);
|
||||||
|
float nDotH = max(dot(N,H),0.0);
|
||||||
|
float D = ggxDistribution(nDotH,roughness); // larger the more micro-facets aligned to H
|
||||||
|
float G = geomSmith(nDotV,nDotL,roughness); // smaller the more micro-facets shadow
|
||||||
|
vec3 F = schlickFresnel(hDotV, baseRefl); // fresnel proportion of specular reflectance
|
||||||
|
|
||||||
|
vec3 spec = (D * G * F) / (4.0 * nDotV * nDotL);
|
||||||
|
// difuse and spec light can't be above 1.0
|
||||||
|
// kD = 1.0 - kS diffuse component is equal 1.0 - spec comonent
|
||||||
|
vec3 kD = vec3(1.0) - F;
|
||||||
|
//mult kD by the inverse of metallnes , only non-metals should have diffuse light
|
||||||
|
kD *= 1.0 - metallic;
|
||||||
|
Lo += ((kD * albedo.rgb / PI + spec) * radiance * nDotL)*lights[i].enabled; // angle of light has impact on result
|
||||||
|
}
|
||||||
|
vec3 ambient_final = (ambientColor + albedo)* ambient * 0.5;
|
||||||
|
return ambient_final+Lo*ao+e;
|
||||||
|
}
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec3 color = pbr();
|
||||||
|
|
||||||
|
//HDR tonemapping
|
||||||
|
color = pow(color,color + vec3(1.0));
|
||||||
|
//gamma correction
|
||||||
|
color = pow(color,vec3(1.0/2.2));
|
||||||
|
|
||||||
|
finalColor = vec4(color,1.0);
|
||||||
|
}
|
||||||
49
examples/shaders/resources/shaders/glsl330/pbr.vs
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
#version 330
|
||||||
|
|
||||||
|
// Input vertex attributes
|
||||||
|
in vec3 vertexPosition;
|
||||||
|
in vec2 vertexTexCoord;
|
||||||
|
in vec3 vertexNormal;
|
||||||
|
in vec3 vertexTangent;
|
||||||
|
in vec4 vertexColor;
|
||||||
|
|
||||||
|
// Input uniform values
|
||||||
|
uniform mat4 mvp;
|
||||||
|
uniform mat4 matModel;
|
||||||
|
uniform mat4 matNormal;
|
||||||
|
uniform vec3 lightPos;
|
||||||
|
uniform vec4 difColor;
|
||||||
|
|
||||||
|
// Output vertex attributes (to fragment shader)
|
||||||
|
out vec3 fragPosition;
|
||||||
|
out vec2 fragTexCoord;
|
||||||
|
out vec4 fragColor;
|
||||||
|
out vec3 fragNormal;
|
||||||
|
out mat3 TBN;
|
||||||
|
|
||||||
|
const float normalOffset = 0.1;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
|
||||||
|
// calc binormal from vertex normal and tangent
|
||||||
|
vec3 vertexBinormal = cross(vertexNormal, vertexTangent);
|
||||||
|
// calc fragment normal based on normal transformations
|
||||||
|
mat3 normalMatrix = transpose(inverse(mat3(matModel)));
|
||||||
|
// calc fragment position based on model transformations
|
||||||
|
|
||||||
|
fragPosition = vec3(matModel*vec4(vertexPosition, 1.0f));
|
||||||
|
|
||||||
|
fragTexCoord = vertexTexCoord*2.0;
|
||||||
|
|
||||||
|
fragNormal = normalize(normalMatrix*vertexNormal);
|
||||||
|
vec3 fragTangent = normalize(normalMatrix*vertexTangent);
|
||||||
|
fragTangent = normalize(fragTangent - dot(fragTangent, fragNormal)*fragNormal);
|
||||||
|
vec3 fragBinormal = normalize(normalMatrix*vertexBinormal);
|
||||||
|
fragBinormal = cross(fragNormal, fragTangent);
|
||||||
|
|
||||||
|
TBN = transpose(mat3(fragTangent, fragBinormal, fragNormal));
|
||||||
|
|
||||||
|
// Calculate final vertex position
|
||||||
|
gl_Position = mvp * vec4(vertexPosition, 1.0);
|
||||||
|
}
|
||||||
466
examples/shaders/rpbr.h
Normal file
|
|
@ -0,0 +1,466 @@
|
||||||
|
/**********************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib.pbr - Some useful functions to deal with pbr materials and lights
|
||||||
|
*
|
||||||
|
* CONFIGURATION:
|
||||||
|
*
|
||||||
|
* #define RPBR_IMPLEMENTATION
|
||||||
|
* Generates the implementation of the library into the included file.
|
||||||
|
* If not defined, the library is in header only mode and can be included in other headers
|
||||||
|
* or source files without problems. But only ONE file should hold the implementation.
|
||||||
|
*
|
||||||
|
* LICENSE: zlib/libpng
|
||||||
|
*
|
||||||
|
* Copyright (c) 2023-2024 Afan OLOVCIC (@_DevDad) 2017-2020 Victor Fisac(@victorfisac),Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
* This software is provided "as-is", without any express or implied warranty. In no event
|
||||||
|
* will the authors be held liable for any damages arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose, including commercial
|
||||||
|
* applications, and to alter it and redistribute it freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not claim that you
|
||||||
|
* wrote the original software. If you use this software in a product, an acknowledgment
|
||||||
|
* in the product documentation would be appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be misrepresented
|
||||||
|
* as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source distribution.
|
||||||
|
*
|
||||||
|
**********************************************************************************************/
|
||||||
|
|
||||||
|
#ifndef RPBR_H
|
||||||
|
#define RPBR_H
|
||||||
|
#include "raylib.h"
|
||||||
|
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Defines and Macros
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
#define MAX_LIGHTS 4 // Max dynamic lights supported by shader
|
||||||
|
#define SHADER_LOC_MAP_MRA SHADER_LOC_MAP_METALNESS //METALLIC, ROUGHNESS and AO
|
||||||
|
#define SHADER_LOC_MAP_EMISSIVE SHADER_LOC_MAP_HEIGHT //EMISSIVE
|
||||||
|
#define MATERIAL_MAP_MRA MATERIAL_MAP_METALNESS
|
||||||
|
#define MATERIAL_MAP_EMISSIVE MATERIAL_MAP_HEIGHT
|
||||||
|
#define NULL 0
|
||||||
|
#define COLOR_TO_ARRAY(c)
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int enabled;
|
||||||
|
int type;
|
||||||
|
Vector3 position;
|
||||||
|
Vector3 target;
|
||||||
|
float color[4];
|
||||||
|
float intensity;
|
||||||
|
|
||||||
|
int enabledLoc;
|
||||||
|
int typeLoc;
|
||||||
|
int positionLoc;
|
||||||
|
int targetLoc;
|
||||||
|
int colorLoc;
|
||||||
|
int intensityLoc;
|
||||||
|
} PBRLight;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
LIGHT_DIRECTIONAL = 0,
|
||||||
|
LIGHT_POINT,
|
||||||
|
LIGHT_SPOT
|
||||||
|
} PBRLightType;
|
||||||
|
|
||||||
|
typedef struct{
|
||||||
|
Shader pbrShader;
|
||||||
|
Shader skyShader;
|
||||||
|
unsigned int cubemap;
|
||||||
|
unsigned int irradiance;
|
||||||
|
unsigned int prefilter;
|
||||||
|
unsigned int brdf;
|
||||||
|
int modelMatrixLoc;
|
||||||
|
int pbrViewLoc;
|
||||||
|
int skyViewLoc;
|
||||||
|
int skyResolutionLoc;
|
||||||
|
} PBREnvironment;
|
||||||
|
|
||||||
|
typedef enum{
|
||||||
|
PBR_COLOR_ALBEDO = 0,
|
||||||
|
PBR_COLOR_EMISSIVE
|
||||||
|
}PBRColorType;
|
||||||
|
|
||||||
|
typedef enum{
|
||||||
|
PBR_VEC2_TILING = 0,
|
||||||
|
PBR_VEC2_OFFSET
|
||||||
|
}PBRVec2Type;
|
||||||
|
|
||||||
|
typedef enum{
|
||||||
|
PBR_PARAM_NORMAL =0,
|
||||||
|
PBR_PARAM_METALLIC,
|
||||||
|
PBR_PARAM_ROUGHNESS,
|
||||||
|
PBR_PARAM_EMISSIVE,
|
||||||
|
PBR_PARAM_AO
|
||||||
|
}PBRFloatType;
|
||||||
|
|
||||||
|
typedef enum{
|
||||||
|
PBR_TEXTURE_ALBEDO = 0,
|
||||||
|
PBR_TEXTURE_NORMAL,
|
||||||
|
PBR_TEXTURE_MRA,
|
||||||
|
PBR_TEXTURE_EMISSIVE
|
||||||
|
}PBRTexType;
|
||||||
|
|
||||||
|
// Textures are moved to material from params to pack better and use less textures on the end
|
||||||
|
// texture MRAE 4Channel R: Metallic G: Roughness B: A: Ambient Occlusion
|
||||||
|
// texEmissive use just one channel, so we have 3 channels still to use if we need
|
||||||
|
typedef struct {
|
||||||
|
Shader pbrShader;
|
||||||
|
float albedo[4];
|
||||||
|
float normal;
|
||||||
|
float metallic;
|
||||||
|
float roughness;
|
||||||
|
float ao;
|
||||||
|
float emissive[4];
|
||||||
|
float ambient[3];
|
||||||
|
float emissivePower;
|
||||||
|
|
||||||
|
Texture2D texAlbedo;
|
||||||
|
Texture2D texNormal;
|
||||||
|
Texture2D texMRA;//r: Metallic g: Roughness b: AO a:Empty
|
||||||
|
Texture2D texEmissive; //Emissive Texture
|
||||||
|
// Using float4 to store tilling at 1st and 2nd position and offset at 3rd and 4th
|
||||||
|
float texTiling[2];
|
||||||
|
float texOffset[2];
|
||||||
|
|
||||||
|
int useTexAlbedo;
|
||||||
|
int useTexNormal;
|
||||||
|
int useTexMRA;
|
||||||
|
int useTexEmissive;
|
||||||
|
|
||||||
|
int albedoLoc;
|
||||||
|
int normalLoc;
|
||||||
|
int metallicLoc;
|
||||||
|
int roughnessLoc;
|
||||||
|
int aoLoc;
|
||||||
|
int emissiveColorLoc;
|
||||||
|
int emissivePowerLoc;
|
||||||
|
|
||||||
|
int texTilingLoc;
|
||||||
|
int texOffsetLoc;
|
||||||
|
|
||||||
|
int useTexAlbedoLoc;
|
||||||
|
int useTexNormalLoc;
|
||||||
|
int useTexMRAELoc;
|
||||||
|
int useTexEmissiveLoc;
|
||||||
|
} PBRMaterial;
|
||||||
|
|
||||||
|
typedef struct{
|
||||||
|
Model model;
|
||||||
|
PBRMaterial pbrMat;
|
||||||
|
}PBRModel;
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Module Functions Declaration
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Create a light and get shader locations
|
||||||
|
PBRLight PBRLightCreate(int type, Vector3 position, Vector3 target, Color color,float intensity, Shader shader);
|
||||||
|
// Send light properties to shader
|
||||||
|
void PBRLightUpdate(Shader shader, PBRLight light);
|
||||||
|
|
||||||
|
//For now until we do real skylight
|
||||||
|
void PBRSetAmbient(Shader shader, Color color, float intensity);
|
||||||
|
|
||||||
|
PBRModel PBRModelLoad(const char *fileName);
|
||||||
|
PBRModel PBRModelLoadFromMesh(Mesh mesh);
|
||||||
|
|
||||||
|
void PBRLoadTextures(PBRMaterial *pbrMat,PBRTexType pbrTexType,const char *fileName);
|
||||||
|
void UnloadPBRMaterial(PBRMaterial pbrMat);
|
||||||
|
void PBRSetColor(PBRMaterial *pbrMat,PBRColorType pbrColorType,Color color);
|
||||||
|
void PBRSetVec2(PBRMaterial *pbrMat,PBRVec2Type type,Vector2 value);
|
||||||
|
void PBRSetFloat(PBRMaterial *pbrMat, PBRFloatType pbrParamType, float value);
|
||||||
|
|
||||||
|
void PBRMaterialSetup( PBRMaterial *pbrMat,Shader pbrShader, PBREnvironment* environment);
|
||||||
|
void PBRSetMaterial(PBRModel* model,PBRMaterial* pbrMat,int matIndex);
|
||||||
|
void PBRDrawModel(PBRModel pbrModel, Vector3 position, float scale);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif //RPBR_H
|
||||||
|
|
||||||
|
/***********************************************************************************
|
||||||
|
*
|
||||||
|
* RPBR IMPLEMENTATION
|
||||||
|
*
|
||||||
|
************************************************************************************/
|
||||||
|
|
||||||
|
#if defined(RPBR_IMPLEMENTATION)
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Global Variables Definition
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
static int lightsCount = 0; // Current amount of created lights
|
||||||
|
|
||||||
|
// Create a light and get shader locations
|
||||||
|
PBRLight PBRLightCreate(int type, Vector3 position, Vector3 target, Color color,float intensity, Shader shader)
|
||||||
|
{
|
||||||
|
PBRLight light = { 0 };
|
||||||
|
|
||||||
|
if (lightsCount < MAX_LIGHTS)
|
||||||
|
{
|
||||||
|
light.enabled = 1;
|
||||||
|
light.type = type;
|
||||||
|
light.position = position;
|
||||||
|
light.target = target;
|
||||||
|
light.color[0] = (float)color.r/(float)255;
|
||||||
|
light.color[1] = (float)color.g/(float)255;
|
||||||
|
light.color[2] = (float)color.b/(float)255;
|
||||||
|
light.color[3] = (float)color.a/(float)255;
|
||||||
|
light.intensity = intensity;
|
||||||
|
// NOTE: Lighting shader naming must be the provided ones
|
||||||
|
light.enabledLoc = GetShaderLocation(shader, TextFormat("lights[%i].enabled", lightsCount));
|
||||||
|
light.typeLoc = GetShaderLocation(shader, TextFormat("lights[%i].type", lightsCount));
|
||||||
|
light.positionLoc = GetShaderLocation(shader, TextFormat("lights[%i].position", lightsCount));
|
||||||
|
light.targetLoc = GetShaderLocation(shader, TextFormat("lights[%i].target", lightsCount));
|
||||||
|
light.colorLoc = GetShaderLocation(shader, TextFormat("lights[%i].color", lightsCount));
|
||||||
|
light.intensityLoc = GetShaderLocation(shader, TextFormat("lights[%i].intensity", lightsCount));
|
||||||
|
PBRLightUpdate(shader, light);
|
||||||
|
|
||||||
|
lightsCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return light;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send light properties to shader
|
||||||
|
// NOTE: Light shader locations should be available
|
||||||
|
void PBRLightUpdate(Shader shader, PBRLight light)
|
||||||
|
{
|
||||||
|
SetShaderValue(shader, light.enabledLoc, &light.enabled, SHADER_UNIFORM_INT);
|
||||||
|
SetShaderValue(shader, light.typeLoc, &light.type, SHADER_UNIFORM_INT);
|
||||||
|
// Send to shader light position values
|
||||||
|
float position[3] = { light.position.x, light.position.y, light.position.z };
|
||||||
|
SetShaderValue(shader, light.positionLoc, position, SHADER_UNIFORM_VEC3);
|
||||||
|
|
||||||
|
// Send to shader light target position values
|
||||||
|
float target[3] = { light.target.x, light.target.y, light.target.z };
|
||||||
|
SetShaderValue(shader, light.targetLoc, target, SHADER_UNIFORM_VEC3);
|
||||||
|
SetShaderValue(shader, light.colorLoc, light.color, SHADER_UNIFORM_VEC4);
|
||||||
|
SetShaderValue(shader, light.intensityLoc, &light.intensity, SHADER_UNIFORM_FLOAT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PBRSetAmbient(Shader shader, Color color, float intensity){
|
||||||
|
float col[3] = {color.r/255,color.g/255,color.b/255};
|
||||||
|
SetShaderValue(shader, GetShaderLocation(shader, "ambientColor"), col, SHADER_UNIFORM_VEC3);
|
||||||
|
SetShaderValue(shader, GetShaderLocation(shader, "ambient"), &intensity, SHADER_UNIFORM_FLOAT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PBRMaterialSetup(PBRMaterial *pbrMat, Shader pbrShader, PBREnvironment* environment){
|
||||||
|
pbrMat->pbrShader = pbrShader;
|
||||||
|
|
||||||
|
pbrMat->texAlbedo = (Texture2D){0};
|
||||||
|
pbrMat->texNormal = (Texture2D){0};
|
||||||
|
pbrMat->texMRA = (Texture2D){0};
|
||||||
|
pbrMat->texEmissive = (Texture2D){0};
|
||||||
|
|
||||||
|
//PBRParam
|
||||||
|
pbrMat->albedo[0] = 1.0;
|
||||||
|
pbrMat->albedo[1] = 1.0;
|
||||||
|
pbrMat->albedo[2] = 1.0;
|
||||||
|
pbrMat->albedo[3] = 1.0;
|
||||||
|
pbrMat->metallic = 0;
|
||||||
|
pbrMat->roughness = 0;
|
||||||
|
pbrMat->ao = 1.0;
|
||||||
|
pbrMat->normal = 1;
|
||||||
|
pbrMat->emissive[0] = 0;
|
||||||
|
pbrMat->emissive[1] = 0;
|
||||||
|
pbrMat->emissive[2] = 0;
|
||||||
|
pbrMat->emissive[3] = 0;
|
||||||
|
|
||||||
|
pbrMat->texTiling[0] = 1.0;
|
||||||
|
pbrMat->texTiling[1] = 1.0;
|
||||||
|
pbrMat->texOffset[0] = 0.0;
|
||||||
|
pbrMat->texOffset[1] = 0.0;
|
||||||
|
pbrMat->emissivePower = 1.0;
|
||||||
|
// Set up PBR shader material locations
|
||||||
|
|
||||||
|
pbrMat->albedoLoc = GetShaderLocation(pbrMat->pbrShader, "albedoColor");
|
||||||
|
pbrMat->normalLoc = GetShaderLocation(pbrMat->pbrShader, "normalValue");
|
||||||
|
pbrMat->metallicLoc = GetShaderLocation(pbrMat->pbrShader, "metallicValue");
|
||||||
|
pbrMat->roughnessLoc = GetShaderLocation(pbrMat->pbrShader, "roughnessValue");
|
||||||
|
pbrMat->aoLoc = GetShaderLocation(pbrMat->pbrShader, "aoValue");
|
||||||
|
pbrMat->emissiveColorLoc = GetShaderLocation(pbrMat->pbrShader, "emissiveColor");
|
||||||
|
pbrMat->emissivePowerLoc = GetShaderLocation(pbrMat->pbrShader, "emissivePower");
|
||||||
|
|
||||||
|
pbrMat->texTilingLoc = GetShaderLocation(pbrMat->pbrShader, "tiling");
|
||||||
|
pbrMat->texOffsetLoc = GetShaderLocation(pbrMat->pbrShader, "offset");
|
||||||
|
|
||||||
|
pbrMat->useTexAlbedoLoc = GetShaderLocation(pbrMat->pbrShader, "useTexAlbedo");
|
||||||
|
pbrMat->useTexNormalLoc = GetShaderLocation(pbrMat->pbrShader, "useTexNormal");
|
||||||
|
pbrMat->useTexMRAELoc = GetShaderLocation(pbrMat->pbrShader, "useTexMRA");
|
||||||
|
pbrMat->useTexEmissiveLoc = GetShaderLocation(pbrMat->pbrShader, "useTexEmissive");
|
||||||
|
|
||||||
|
SetShaderValue(pbrMat->pbrShader,pbrMat->albedoLoc,pbrMat->albedo,SHADER_UNIFORM_VEC4);
|
||||||
|
SetShaderValue(pbrMat->pbrShader, pbrMat->emissiveColorLoc, pbrMat->emissive, SHADER_UNIFORM_VEC4);
|
||||||
|
SetShaderValue(pbrMat->pbrShader, pbrMat->emissivePowerLoc, &pbrMat->emissivePower, SHADER_UNIFORM_FLOAT);
|
||||||
|
SetShaderValue(pbrMat->pbrShader,pbrMat->metallicLoc,&pbrMat->metallic,SHADER_UNIFORM_FLOAT);
|
||||||
|
SetShaderValue(pbrMat->pbrShader,pbrMat->roughnessLoc,&pbrMat->roughness,SHADER_UNIFORM_FLOAT);
|
||||||
|
SetShaderValue(pbrMat->pbrShader,pbrMat->aoLoc,&pbrMat->ao,SHADER_UNIFORM_FLOAT);
|
||||||
|
SetShaderValue(pbrMat->pbrShader,pbrMat->normalLoc,&pbrMat->normal,SHADER_UNIFORM_FLOAT);
|
||||||
|
SetShaderValue(pbrMat->pbrShader,pbrMat->texTilingLoc,pbrMat->texTiling,SHADER_UNIFORM_VEC2);
|
||||||
|
SetShaderValue(pbrMat->pbrShader,pbrMat->texOffsetLoc,pbrMat->texOffset,SHADER_UNIFORM_VEC2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PBRLoadTextures(PBRMaterial *pbrMat,PBRTexType pbrTexType,const char *fileName){
|
||||||
|
if(pbrMat == NULL) return;
|
||||||
|
switch(pbrTexType){
|
||||||
|
case PBR_TEXTURE_ALBEDO:
|
||||||
|
pbrMat->texAlbedo = LoadTexture(fileName);
|
||||||
|
pbrMat->useTexAlbedo = 1;
|
||||||
|
break;
|
||||||
|
case PBR_TEXTURE_MRA:
|
||||||
|
pbrMat->texMRA = LoadTexture(fileName);
|
||||||
|
pbrMat->useTexMRA = 1;
|
||||||
|
break;
|
||||||
|
case PBR_TEXTURE_NORMAL:
|
||||||
|
pbrMat->texNormal = LoadTexture(fileName);
|
||||||
|
pbrMat->useTexNormal = 1;
|
||||||
|
break;
|
||||||
|
case PBR_TEXTURE_EMISSIVE:
|
||||||
|
pbrMat->texEmissive = LoadTexture(fileName);
|
||||||
|
pbrMat->useTexEmissive = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UnloadPBRMaterial(PBRMaterial pbrMat){
|
||||||
|
if(pbrMat.useTexAlbedo == 1) UnloadTexture(pbrMat.texAlbedo);
|
||||||
|
if(pbrMat.useTexNormal == 1) UnloadTexture(pbrMat.texNormal);
|
||||||
|
if(pbrMat.useTexMRA == 1) UnloadTexture(pbrMat.texMRA);
|
||||||
|
if(pbrMat.useTexEmissive == 1) UnloadTexture(pbrMat.texEmissive);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PBRSetColor(PBRMaterial *pbrMat,PBRColorType pbrColorType,Color color){
|
||||||
|
if(pbrMat == NULL) return;
|
||||||
|
switch(pbrColorType){
|
||||||
|
case PBR_COLOR_ALBEDO:
|
||||||
|
pbrMat->albedo[0] = (float) color.r / 255;
|
||||||
|
pbrMat->albedo[1] = (float) color.g / 255;
|
||||||
|
pbrMat->albedo[2] = (float) color.b / 255;
|
||||||
|
pbrMat->albedo[3] = (float) color.a / 255;
|
||||||
|
SetShaderValue(pbrMat->pbrShader,pbrMat->albedoLoc,pbrMat->albedo,SHADER_UNIFORM_VEC4);
|
||||||
|
break;
|
||||||
|
case PBR_COLOR_EMISSIVE:
|
||||||
|
pbrMat->emissive[0] = (float) color.r / 255;
|
||||||
|
pbrMat->emissive[1] = (float) color.g / 255;
|
||||||
|
pbrMat->emissive[2] = (float) color.b / 255;
|
||||||
|
pbrMat->emissive[3] = (float) color.a / 255;
|
||||||
|
SetShaderValue(pbrMat->pbrShader, pbrMat->emissiveColorLoc, pbrMat->emissive, SHADER_UNIFORM_VEC4);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PBRSetFloat(PBRMaterial *pbrMat, PBRFloatType pbrParamType, float value){
|
||||||
|
if(pbrMat == NULL) return;
|
||||||
|
switch(pbrParamType){
|
||||||
|
case PBR_PARAM_METALLIC:
|
||||||
|
pbrMat->metallic = value;
|
||||||
|
SetShaderValue(pbrMat->pbrShader,pbrMat->metallicLoc,&pbrMat->metallic,SHADER_UNIFORM_FLOAT);
|
||||||
|
break;
|
||||||
|
case PBR_PARAM_ROUGHNESS:
|
||||||
|
pbrMat->roughness = value;
|
||||||
|
SetShaderValue(pbrMat->pbrShader,pbrMat->roughnessLoc,&pbrMat->roughness,SHADER_UNIFORM_FLOAT);
|
||||||
|
break;
|
||||||
|
case PBR_PARAM_NORMAL:
|
||||||
|
pbrMat->normal = value;
|
||||||
|
SetShaderValue(pbrMat->pbrShader,pbrMat->normalLoc,&pbrMat->normal,SHADER_UNIFORM_FLOAT);
|
||||||
|
break;
|
||||||
|
case PBR_PARAM_AO:
|
||||||
|
pbrMat->ao = value;
|
||||||
|
SetShaderValue(pbrMat->pbrShader,pbrMat->aoLoc,&pbrMat->ao,SHADER_UNIFORM_FLOAT);
|
||||||
|
break;
|
||||||
|
case PBR_PARAM_EMISSIVE:
|
||||||
|
pbrMat->emissivePower = value;
|
||||||
|
SetShaderValue(pbrMat->pbrShader,pbrMat->emissivePowerLoc,&pbrMat->emissivePower,SHADER_UNIFORM_FLOAT);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PBRSetVec2(PBRMaterial *pbrMat,PBRVec2Type type,Vector2 value){
|
||||||
|
switch(type){
|
||||||
|
case PBR_VEC2_TILING:
|
||||||
|
pbrMat->texTiling[0] = value.x;
|
||||||
|
pbrMat->texTiling[1] = value.y;
|
||||||
|
SetShaderValue(pbrMat->pbrShader,pbrMat->texTilingLoc,&pbrMat->texTiling,SHADER_UNIFORM_VEC2);
|
||||||
|
break;
|
||||||
|
case PBR_VEC2_OFFSET:
|
||||||
|
pbrMat->texOffset[0] = value.x;
|
||||||
|
pbrMat->texOffset[1] = value.y;
|
||||||
|
SetShaderValue(pbrMat->pbrShader,pbrMat->texOffsetLoc,&pbrMat->texOffset,SHADER_UNIFORM_VEC2);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PBRSetMaterial(PBRModel* model,PBRMaterial* pbrMat,int matIndex){
|
||||||
|
|
||||||
|
|
||||||
|
model->pbrMat = *pbrMat;
|
||||||
|
model->model.materials[matIndex].shader = model->pbrMat.pbrShader;
|
||||||
|
pbrMat->pbrShader.locs[SHADER_LOC_MAP_MRA] = GetShaderLocation(pbrMat->pbrShader, "mraMap");
|
||||||
|
pbrMat->pbrShader.locs[SHADER_LOC_MAP_EMISSIVE] = GetShaderLocation(pbrMat->pbrShader, "emissiveMap");
|
||||||
|
pbrMat->pbrShader.locs[SHADER_LOC_MAP_NORMAL] = GetShaderLocation(pbrMat->pbrShader, "normalMap");
|
||||||
|
|
||||||
|
if(pbrMat->useTexAlbedo) {
|
||||||
|
model->model.materials[matIndex].maps[MATERIAL_MAP_ALBEDO].texture = pbrMat->texAlbedo;
|
||||||
|
}
|
||||||
|
if(pbrMat->useTexMRA) {
|
||||||
|
model->model.materials[matIndex].maps[MATERIAL_MAP_MRA].texture = pbrMat->texMRA;
|
||||||
|
}
|
||||||
|
if(pbrMat->useTexNormal) {
|
||||||
|
model->model.materials[matIndex].maps[MATERIAL_MAP_NORMAL].texture = pbrMat->texNormal;
|
||||||
|
}
|
||||||
|
if(pbrMat->useTexEmissive) {
|
||||||
|
model->model.materials[matIndex].maps[MATERIAL_MAP_EMISSIVE].texture = pbrMat->texEmissive;
|
||||||
|
}
|
||||||
|
|
||||||
|
SetShaderValue(pbrMat->pbrShader,pbrMat->useTexAlbedoLoc,&pbrMat->useTexAlbedo,SHADER_UNIFORM_INT);
|
||||||
|
SetShaderValue(pbrMat->pbrShader,pbrMat->useTexNormalLoc,&pbrMat->useTexNormal,SHADER_UNIFORM_INT);
|
||||||
|
SetShaderValue(pbrMat->pbrShader, pbrMat->useTexMRAELoc, &pbrMat->useTexMRA, SHADER_UNIFORM_INT);
|
||||||
|
SetShaderValue(pbrMat->pbrShader, pbrMat->useTexEmissiveLoc, &pbrMat->useTexEmissive, SHADER_UNIFORM_INT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PBRDrawModel(PBRModel pbrModel, Vector3 position, float scale){
|
||||||
|
PBRMaterial *pbrMat = &pbrModel.pbrMat;
|
||||||
|
SetShaderValue(pbrMat->pbrShader,pbrMat->albedoLoc,pbrMat->albedo,SHADER_UNIFORM_VEC4);
|
||||||
|
SetShaderValue(pbrMat->pbrShader, pbrMat->emissiveColorLoc, pbrMat->emissive, SHADER_UNIFORM_VEC4);
|
||||||
|
SetShaderValue(pbrMat->pbrShader,pbrMat->metallicLoc,&pbrMat->metallic,SHADER_UNIFORM_FLOAT);
|
||||||
|
SetShaderValue(pbrMat->pbrShader,pbrMat->roughnessLoc,&pbrMat->roughness,SHADER_UNIFORM_FLOAT);
|
||||||
|
SetShaderValue(pbrMat->pbrShader,pbrMat->aoLoc,&pbrMat->ao,SHADER_UNIFORM_FLOAT);
|
||||||
|
SetShaderValue(pbrMat->pbrShader,pbrMat->normalLoc,&pbrMat->normal,SHADER_UNIFORM_FLOAT);
|
||||||
|
SetShaderValue(pbrMat->pbrShader,pbrMat->texTilingLoc,pbrMat->texTiling,SHADER_UNIFORM_VEC2);
|
||||||
|
SetShaderValue(pbrMat->pbrShader,pbrMat->texOffsetLoc,pbrMat->texOffset,SHADER_UNIFORM_VEC2);
|
||||||
|
|
||||||
|
SetShaderValue(pbrMat->pbrShader,pbrMat->useTexAlbedoLoc,&pbrMat->useTexAlbedo,SHADER_UNIFORM_INT);
|
||||||
|
SetShaderValue(pbrMat->pbrShader,pbrMat->useTexNormalLoc,&pbrMat->useTexNormal,SHADER_UNIFORM_INT);
|
||||||
|
SetShaderValue(pbrMat->pbrShader, pbrMat->useTexMRAELoc, &pbrMat->useTexMRA, SHADER_UNIFORM_INT);
|
||||||
|
SetShaderValue(pbrMat->pbrShader, pbrMat->useTexEmissiveLoc, &pbrMat->useTexEmissive, SHADER_UNIFORM_INT);
|
||||||
|
|
||||||
|
DrawModel(pbrModel.model,position,scale,WHITE);
|
||||||
|
}
|
||||||
|
|
||||||
|
PBRModel PBRModelLoad(const char *fileName){
|
||||||
|
PBRModel pbrModel = (PBRModel){0};
|
||||||
|
pbrModel.model = LoadModel(fileName);
|
||||||
|
return pbrModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
PBRModel PBRModelLoadFromMesh(Mesh mesh){
|
||||||
|
PBRModel pbrModel = (PBRModel){0};
|
||||||
|
pbrModel.model = LoadModelFromMesh(mesh);
|
||||||
|
return pbrModel;
|
||||||
|
}
|
||||||
|
#endif // RPBR_IMPLEMENTATION
|
||||||