mirror of
https://github.com/raysan5/raylib.git
synced 2025-09-10 21:38:15 +00:00
Allow custom distortion shader - IN PROGRESS -
This commit is contained in:
@@ -1095,10 +1095,11 @@ RLAPI void BeginBlendMode(int mode); // Beg
|
|||||||
RLAPI void EndBlendMode(void); // End blending mode (reset to default: alpha blending)
|
RLAPI void EndBlendMode(void); // End blending mode (reset to default: alpha blending)
|
||||||
|
|
||||||
// VR control functions
|
// VR control functions
|
||||||
VrDeviceInfo GetVrDeviceInfo(int vrDeviceType); // Get VR device information for some standard devices
|
RLAPI VrDeviceInfo GetVrDeviceInfo(int vrDeviceType); // Get VR device information for some standard devices
|
||||||
void InitVrSimulator(VrDeviceInfo info); // Init VR simulator for selected device parameters
|
RLAPI void InitVrSimulator(VrDeviceInfo info); // Init VR simulator for selected device parameters
|
||||||
RLAPI void CloseVrSimulator(void); // Close VR simulator for current device
|
RLAPI void CloseVrSimulator(void); // Close VR simulator for current device
|
||||||
RLAPI bool IsVrSimulatorReady(void); // Detect if VR simulator is ready
|
RLAPI bool IsVrSimulatorReady(void); // Detect if VR simulator is ready
|
||||||
|
RLAPI void SetVrDistortionShader(Shader shader); // Set VR distortion shader for stereoscopic rendering
|
||||||
RLAPI void UpdateVrTracking(Camera *camera); // Update VR tracking (position and orientation) and camera
|
RLAPI void UpdateVrTracking(Camera *camera); // Update VR tracking (position and orientation) and camera
|
||||||
RLAPI void ToggleVrMode(void); // Enable/Disable VR experience
|
RLAPI void ToggleVrMode(void); // Enable/Disable VR experience
|
||||||
RLAPI void BeginVrDrawing(void); // Begin VR simulator stereo rendering
|
RLAPI void BeginVrDrawing(void); // Begin VR simulator stereo rendering
|
||||||
|
30
src/rlgl.c
30
src/rlgl.c
@@ -232,7 +232,7 @@ typedef struct DrawCall {
|
|||||||
typedef struct VrStereoConfig {
|
typedef struct VrStereoConfig {
|
||||||
RenderTexture2D stereoFbo; // VR stereo rendering framebuffer
|
RenderTexture2D stereoFbo; // VR stereo rendering framebuffer
|
||||||
Shader distortionShader; // VR stereo rendering distortion shader
|
Shader distortionShader; // VR stereo rendering distortion shader
|
||||||
//Rectangle eyesViewport[2]; // VR stereo rendering eyes viewports
|
Rectangle eyesViewport[2]; // VR stereo rendering eyes viewports
|
||||||
Matrix eyesProjection[2]; // VR stereo rendering eyes projection matrices
|
Matrix eyesProjection[2]; // VR stereo rendering eyes projection matrices
|
||||||
Matrix eyesViewOffset[2]; // VR stereo rendering eyes view offset matrices
|
Matrix eyesViewOffset[2]; // VR stereo rendering eyes view offset matrices
|
||||||
} VrStereoConfig;
|
} VrStereoConfig;
|
||||||
@@ -2926,7 +2926,7 @@ void InitVrSimulator(VrDeviceInfo info)
|
|||||||
vrConfig.stereoFbo = rlLoadRenderTexture(screenWidth, screenHeight);
|
vrConfig.stereoFbo = rlLoadRenderTexture(screenWidth, screenHeight);
|
||||||
|
|
||||||
#if defined(SUPPORT_DISTORTION_SHADER)
|
#if defined(SUPPORT_DISTORTION_SHADER)
|
||||||
// Load distortion shader (initialized by default with Oculus Rift CV1 parameters)
|
// Load distortion shader
|
||||||
unsigned int vertexShaderId = CompileShader(distortionVShaderStr, GL_VERTEX_SHADER);
|
unsigned int vertexShaderId = CompileShader(distortionVShaderStr, GL_VERTEX_SHADER);
|
||||||
unsigned int fragmentShaderId = CompileShader(distortionFShaderStr, GL_FRAGMENT_SHADER);
|
unsigned int fragmentShaderId = CompileShader(distortionFShaderStr, GL_FRAGMENT_SHADER);
|
||||||
|
|
||||||
@@ -2934,6 +2934,7 @@ void InitVrSimulator(VrDeviceInfo info)
|
|||||||
if (vrConfig.distortionShader.id > 0) SetShaderDefaultLocations(&vrConfig.distortionShader);
|
if (vrConfig.distortionShader.id > 0) SetShaderDefaultLocations(&vrConfig.distortionShader);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Set VR configutarion parameters, including distortion shader
|
||||||
SetStereoConfig(info);
|
SetStereoConfig(info);
|
||||||
|
|
||||||
vrSimulatorReady = true;
|
vrSimulatorReady = true;
|
||||||
@@ -2958,18 +2959,6 @@ void CloseVrSimulator(void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Review VR system to be more flexible,
|
|
||||||
// move distortion shader to user side,
|
|
||||||
// SetStereoConfig() must be reviewed...
|
|
||||||
/*
|
|
||||||
// Set VR view distortion shader
|
|
||||||
void SetVrDistortionShader(Shader shader)
|
|
||||||
{
|
|
||||||
vrConfig.distortionShader = shader;
|
|
||||||
SetStereoConfig(info);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Detect if VR simulator is running
|
// Detect if VR simulator is running
|
||||||
bool IsVrSimulatorReady(void)
|
bool IsVrSimulatorReady(void)
|
||||||
{
|
{
|
||||||
@@ -2980,6 +2969,15 @@ bool IsVrSimulatorReady(void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set VR distortion shader for stereoscopic rendering
|
||||||
|
// TODO: Review VR system to be more flexible, move distortion shader to user side
|
||||||
|
void SetVrDistortionShader(Shader shader)
|
||||||
|
{
|
||||||
|
vrConfig.distortionShader = shader;
|
||||||
|
|
||||||
|
//SetStereoConfig(info); // TODO: Must be reviewed to set new distortion shader uniform values...
|
||||||
|
}
|
||||||
|
|
||||||
// Enable/Disable VR experience (device or simulator)
|
// Enable/Disable VR experience (device or simulator)
|
||||||
void ToggleVrMode(void)
|
void ToggleVrMode(void)
|
||||||
{
|
{
|
||||||
@@ -4026,8 +4024,8 @@ static void SetStereoConfig(VrDeviceInfo hmd)
|
|||||||
vrConfig.eyesViewOffset[1] = MatrixTranslate(hmd.interpupillaryDistance*0.5f, 0.075f, 0.045f);
|
vrConfig.eyesViewOffset[1] = MatrixTranslate(hmd.interpupillaryDistance*0.5f, 0.075f, 0.045f);
|
||||||
|
|
||||||
// Compute eyes Viewports
|
// Compute eyes Viewports
|
||||||
//vrConfig.eyesViewport[0] = (Rectangle){ 0, 0, hmd.hResolution/2, hmd.vResolution };
|
vrConfig.eyesViewport[0] = (Rectangle){ 0, 0, hmd.hResolution/2, hmd.vResolution };
|
||||||
//vrConfig.eyesViewport[1] = (Rectangle){ hmd.hResolution/2, 0, hmd.hResolution/2, hmd.vResolution };
|
vrConfig.eyesViewport[1] = (Rectangle){ hmd.hResolution/2, 0, hmd.hResolution/2, hmd.vResolution };
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set internal projection and modelview matrix depending on eyes tracking data
|
// Set internal projection and modelview matrix depending on eyes tracking data
|
||||||
|
108
src/rlgl.h
108
src/rlgl.h
@@ -146,56 +146,6 @@ typedef unsigned char byte;
|
|||||||
typedef enum { false, true } bool;
|
typedef enum { false, true } bool;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Shader location point type
|
|
||||||
typedef enum {
|
|
||||||
LOC_VERTEX_POSITION = 0,
|
|
||||||
LOC_VERTEX_TEXCOORD01,
|
|
||||||
LOC_VERTEX_TEXCOORD02,
|
|
||||||
LOC_VERTEX_NORMAL,
|
|
||||||
LOC_VERTEX_TANGENT,
|
|
||||||
LOC_VERTEX_COLOR,
|
|
||||||
LOC_MATRIX_MVP,
|
|
||||||
LOC_MATRIX_MODEL,
|
|
||||||
LOC_MATRIX_VIEW,
|
|
||||||
LOC_MATRIX_PROJECTION,
|
|
||||||
LOC_VECTOR_VIEW,
|
|
||||||
LOC_COLOR_DIFFUSE,
|
|
||||||
LOC_COLOR_SPECULAR,
|
|
||||||
LOC_COLOR_AMBIENT,
|
|
||||||
LOC_MAP_ALBEDO, // LOC_MAP_DIFFUSE
|
|
||||||
LOC_MAP_METALNESS, // LOC_MAP_SPECULAR
|
|
||||||
LOC_MAP_NORMAL,
|
|
||||||
LOC_MAP_ROUGHNESS,
|
|
||||||
LOC_MAP_OCCUSION,
|
|
||||||
LOC_MAP_EMISSION,
|
|
||||||
LOC_MAP_HEIGHT,
|
|
||||||
LOC_MAP_CUBEMAP,
|
|
||||||
LOC_MAP_IRRADIANCE,
|
|
||||||
LOC_MAP_PREFILTER,
|
|
||||||
LOC_MAP_BRDF
|
|
||||||
} ShaderLocationIndex;
|
|
||||||
|
|
||||||
#define LOC_MAP_DIFFUSE LOC_MAP_ALBEDO
|
|
||||||
#define LOC_MAP_SPECULAR LOC_MAP_METALNESS
|
|
||||||
|
|
||||||
// Material map type
|
|
||||||
typedef enum {
|
|
||||||
MAP_ALBEDO = 0, // MAP_DIFFUSE
|
|
||||||
MAP_METALNESS = 1, // MAP_SPECULAR
|
|
||||||
MAP_NORMAL = 2,
|
|
||||||
MAP_ROUGHNESS = 3,
|
|
||||||
MAP_OCCLUSION,
|
|
||||||
MAP_EMISSION,
|
|
||||||
MAP_HEIGHT,
|
|
||||||
MAP_CUBEMAP, // NOTE: Uses GL_TEXTURE_CUBE_MAP
|
|
||||||
MAP_IRRADIANCE, // NOTE: Uses GL_TEXTURE_CUBE_MAP
|
|
||||||
MAP_PREFILTER, // NOTE: Uses GL_TEXTURE_CUBE_MAP
|
|
||||||
MAP_BRDF
|
|
||||||
} TexmapIndex;
|
|
||||||
|
|
||||||
#define MAP_DIFFUSE MAP_ALBEDO
|
|
||||||
#define MAP_SPECULAR MAP_METALNESS
|
|
||||||
|
|
||||||
// Color type, RGBA (32bit)
|
// Color type, RGBA (32bit)
|
||||||
typedef struct Color {
|
typedef struct Color {
|
||||||
unsigned char r;
|
unsigned char r;
|
||||||
@@ -204,6 +154,14 @@ typedef unsigned char byte;
|
|||||||
unsigned char a;
|
unsigned char a;
|
||||||
} Color;
|
} Color;
|
||||||
|
|
||||||
|
// Rectangle type
|
||||||
|
typedef struct Rectangle {
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
} Rectangle;
|
||||||
|
|
||||||
// Texture2D type
|
// Texture2D type
|
||||||
// NOTE: Data stored in GPU memory
|
// NOTE: Data stored in GPU memory
|
||||||
typedef struct Texture2D {
|
typedef struct Texture2D {
|
||||||
@@ -341,6 +299,56 @@ typedef unsigned char byte;
|
|||||||
BLEND_MULTIPLIED
|
BLEND_MULTIPLIED
|
||||||
} BlendMode;
|
} BlendMode;
|
||||||
|
|
||||||
|
// Shader location point type
|
||||||
|
typedef enum {
|
||||||
|
LOC_VERTEX_POSITION = 0,
|
||||||
|
LOC_VERTEX_TEXCOORD01,
|
||||||
|
LOC_VERTEX_TEXCOORD02,
|
||||||
|
LOC_VERTEX_NORMAL,
|
||||||
|
LOC_VERTEX_TANGENT,
|
||||||
|
LOC_VERTEX_COLOR,
|
||||||
|
LOC_MATRIX_MVP,
|
||||||
|
LOC_MATRIX_MODEL,
|
||||||
|
LOC_MATRIX_VIEW,
|
||||||
|
LOC_MATRIX_PROJECTION,
|
||||||
|
LOC_VECTOR_VIEW,
|
||||||
|
LOC_COLOR_DIFFUSE,
|
||||||
|
LOC_COLOR_SPECULAR,
|
||||||
|
LOC_COLOR_AMBIENT,
|
||||||
|
LOC_MAP_ALBEDO, // LOC_MAP_DIFFUSE
|
||||||
|
LOC_MAP_METALNESS, // LOC_MAP_SPECULAR
|
||||||
|
LOC_MAP_NORMAL,
|
||||||
|
LOC_MAP_ROUGHNESS,
|
||||||
|
LOC_MAP_OCCUSION,
|
||||||
|
LOC_MAP_EMISSION,
|
||||||
|
LOC_MAP_HEIGHT,
|
||||||
|
LOC_MAP_CUBEMAP,
|
||||||
|
LOC_MAP_IRRADIANCE,
|
||||||
|
LOC_MAP_PREFILTER,
|
||||||
|
LOC_MAP_BRDF
|
||||||
|
} ShaderLocationIndex;
|
||||||
|
|
||||||
|
#define LOC_MAP_DIFFUSE LOC_MAP_ALBEDO
|
||||||
|
#define LOC_MAP_SPECULAR LOC_MAP_METALNESS
|
||||||
|
|
||||||
|
// Material map type
|
||||||
|
typedef enum {
|
||||||
|
MAP_ALBEDO = 0, // MAP_DIFFUSE
|
||||||
|
MAP_METALNESS = 1, // MAP_SPECULAR
|
||||||
|
MAP_NORMAL = 2,
|
||||||
|
MAP_ROUGHNESS = 3,
|
||||||
|
MAP_OCCLUSION,
|
||||||
|
MAP_EMISSION,
|
||||||
|
MAP_HEIGHT,
|
||||||
|
MAP_CUBEMAP, // NOTE: Uses GL_TEXTURE_CUBE_MAP
|
||||||
|
MAP_IRRADIANCE, // NOTE: Uses GL_TEXTURE_CUBE_MAP
|
||||||
|
MAP_PREFILTER, // NOTE: Uses GL_TEXTURE_CUBE_MAP
|
||||||
|
MAP_BRDF
|
||||||
|
} TexmapIndex;
|
||||||
|
|
||||||
|
#define MAP_DIFFUSE MAP_ALBEDO
|
||||||
|
#define MAP_SPECULAR MAP_METALNESS
|
||||||
|
|
||||||
// VR Head Mounted Display devices
|
// VR Head Mounted Display devices
|
||||||
typedef enum {
|
typedef enum {
|
||||||
HMD_DEFAULT_DEVICE = 0,
|
HMD_DEFAULT_DEVICE = 0,
|
||||||
|
Reference in New Issue
Block a user