mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 15:33:10 +02:00
Fixed to use standard shaders from render-utils
This commit is contained in:
parent
e601484b17
commit
691cb48a08
6 changed files with 4 additions and 412 deletions
|
@ -1,124 +0,0 @@
|
|||
//
|
||||
// gputest_shaders.h
|
||||
// hifi
|
||||
//
|
||||
// Created by Seiji Emery on 8/3/15.
|
||||
//
|
||||
//
|
||||
|
||||
#ifndef hifi_gputest_shaders_h
|
||||
#define hifi_gputest_shaders_h
|
||||
|
||||
|
||||
const std::string & standardVertexShader() {
|
||||
static std::string src = R"(
|
||||
|
||||
in vec4 inPosition;
|
||||
in vec4 inNormal;
|
||||
in vec4 inColor;
|
||||
in vec4 inTexCoord0;
|
||||
in vec4 inTangent;
|
||||
in vec4 inSkinClusterIndex;
|
||||
in vec4 inSkinClusterWeight;
|
||||
in vec4 inTexCoord1;
|
||||
|
||||
struct TransformObject {
|
||||
mat4 _model;
|
||||
mat4 _modelInverse;
|
||||
};
|
||||
|
||||
struct TransformCamera {
|
||||
mat4 _view;
|
||||
mat4 _viewInverse;
|
||||
mat4 _projectionViewUntranslated;
|
||||
mat4 _projection;
|
||||
mat4 _projectionInverse;
|
||||
vec4 _viewport;
|
||||
};
|
||||
|
||||
uniform transformObjectBuffer {
|
||||
TransformObject _object;
|
||||
};
|
||||
TransformObject getTransformObject() {
|
||||
return _object;
|
||||
}
|
||||
|
||||
uniform transformCameraBuffer {
|
||||
TransformCamera _camera;
|
||||
};
|
||||
TransformCamera getTransformCamera() {
|
||||
return _camera;
|
||||
}
|
||||
|
||||
|
||||
const int MAX_TEXCOORDS = 2;
|
||||
|
||||
uniform mat4 texcoordMatrices[MAX_TEXCOORDS];
|
||||
|
||||
out vec4 _position;
|
||||
out vec3 _normal;
|
||||
out vec3 _color;
|
||||
out vec2 _texCoord0;
|
||||
|
||||
)";
|
||||
return src;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
const std::string & basicVertexShader () {
|
||||
static std::string src = R"(
|
||||
// Basic forward-rendered shading w/ a single directional light source.
|
||||
|
||||
#version 410
|
||||
|
||||
// I/O
|
||||
layout (location = 0) in vec3 vertexPosition;
|
||||
layout (location = 1) in vec3 vertexNormal;
|
||||
|
||||
out vec3 outColor;
|
||||
|
||||
// Light info
|
||||
uniform vec4 lightPosition;
|
||||
uniform vec3 kd; // diffuse reflectivity
|
||||
uniform vec3 ld; // light source intensity
|
||||
|
||||
// Model transforms
|
||||
uniform mat4 modelViewMatrix;
|
||||
uniform mat3 normalMatrix;
|
||||
uniform mat4 projectionMatrix;
|
||||
uniform mat4 mvp;
|
||||
|
||||
void main (void) {
|
||||
vec3 norm = normalize(normalMatrix * vertexNormal);
|
||||
vec4 eyePos = modelViewMatrix * vec4(vertexPosition, 0);
|
||||
vec3 s = normalize(vec3(lightPosition - eyePos));
|
||||
|
||||
outColor = ld * kd * max(dot(s, norm), 0.0);
|
||||
|
||||
gl_Position = mvp * vec4(vertexPosition, 1.0);
|
||||
}
|
||||
|
||||
)";
|
||||
return src;
|
||||
}
|
||||
|
||||
const std::string & basicFragmentShader () {
|
||||
static std::string src = R"(
|
||||
#version 410
|
||||
|
||||
// Just pass interpolated color value along
|
||||
in vec3 outColor;
|
||||
|
||||
layout (location = 0) out vec4 fragColor;
|
||||
|
||||
void main(void) {
|
||||
fragColor = vec4(outColor, 1.0);
|
||||
}
|
||||
|
||||
)";
|
||||
return src;
|
||||
}
|
||||
#endif
|
|
@ -1,105 +0,0 @@
|
|||
// File generated by Scribe Wed Aug 5 16:50:24 2015
|
||||
#ifndef scribe_simple_frag_h
|
||||
#define scribe_simple_frag_h
|
||||
|
||||
const char simple_frag[] = R"SCRIBE(#version 410 core
|
||||
// Generated on Wed Aug 5 16:50:24 2015
|
||||
//
|
||||
// simple.frag
|
||||
// fragment shader
|
||||
//
|
||||
// Created by Andrzej Kapolka on 9/15/14.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
layout(location = 0) out vec4 _fragColor0;
|
||||
layout(location = 1) out vec4 _fragColor1;
|
||||
layout(location = 2) out vec4 _fragColor2;
|
||||
|
||||
// the glow intensity
|
||||
uniform float glowIntensity;
|
||||
|
||||
// the alpha threshold
|
||||
uniform float alphaThreshold;
|
||||
|
||||
float evalOpaqueFinalAlpha(float alpha, float mapAlpha) {
|
||||
return mix(alpha * glowIntensity, 1.0 - alpha * glowIntensity, step(mapAlpha, alphaThreshold));
|
||||
}
|
||||
|
||||
const vec3 DEFAULT_SPECULAR = vec3(0.1);
|
||||
const float DEFAULT_SHININESS = 10;
|
||||
|
||||
void packDeferredFragment(vec3 normal, float alpha, vec3 diffuse, vec3 specular, float shininess) {
|
||||
if (alpha != glowIntensity) {
|
||||
discard;
|
||||
}
|
||||
_fragColor0 = vec4(diffuse.rgb, alpha);
|
||||
_fragColor1 = vec4(normal, 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0);
|
||||
_fragColor2 = vec4(specular, shininess / 128.0);
|
||||
}
|
||||
|
||||
void packDeferredFragmentLightmap(vec3 normal, float alpha, vec3 diffuse, vec3 specular, float shininess, vec3 emissive) {
|
||||
if (alpha != glowIntensity) {
|
||||
discard;
|
||||
}
|
||||
|
||||
_fragColor0 = vec4(diffuse.rgb, alpha);
|
||||
//_fragColor1 = vec4(normal, 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0);
|
||||
_fragColor1 = vec4(normal, 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 0.5);
|
||||
_fragColor2 = vec4(emissive, shininess / 128.0);
|
||||
}
|
||||
|
||||
void packDeferredFragmentTranslucent(vec3 normal, float alpha, vec3 diffuse, vec3 specular, float shininess) {
|
||||
if (alpha <= alphaThreshold) {
|
||||
discard;
|
||||
}
|
||||
|
||||
_fragColor0 = vec4(diffuse.rgb, alpha);
|
||||
// _fragColor1 = vec4(normal, 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0);
|
||||
// _fragColor2 = vec4(specular, shininess / 128.0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
struct Material {
|
||||
vec4 _diffuse;
|
||||
vec4 _specular;
|
||||
vec4 _emissive;
|
||||
vec4 _spare;
|
||||
};
|
||||
|
||||
uniform materialBuffer {
|
||||
Material _mat;
|
||||
};
|
||||
|
||||
Material getMaterial() {
|
||||
return _mat;
|
||||
}
|
||||
|
||||
float getMaterialOpacity(Material m) { return m._diffuse.a; }
|
||||
vec3 getMaterialDiffuse(Material m) { return m._diffuse.rgb; }
|
||||
vec3 getMaterialSpecular(Material m) { return m._specular.rgb; }
|
||||
float getMaterialShininess(Material m) { return m._specular.a; }
|
||||
|
||||
|
||||
// the interpolated normal
|
||||
in vec3 _normal;
|
||||
in vec3 _color;
|
||||
|
||||
void main(void) {
|
||||
Material material = getMaterial();
|
||||
packDeferredFragment(
|
||||
normalize(_normal.xyz),
|
||||
glowIntensity,
|
||||
_color.rgb,
|
||||
DEFAULT_SPECULAR, DEFAULT_SHININESS);
|
||||
}
|
||||
|
||||
)SCRIBE";
|
||||
|
||||
#endif
|
|
@ -1,113 +0,0 @@
|
|||
// File generated by Scribe Wed Aug 5 16:50:23 2015
|
||||
#ifndef scribe_simple_vert_h
|
||||
#define scribe_simple_vert_h
|
||||
|
||||
const char simple_vert[] = R"SCRIBE(#version 410 core
|
||||
// Generated on Wed Aug 5 16:50:23 2015
|
||||
//
|
||||
// simple.vert
|
||||
// vertex shader
|
||||
//
|
||||
// Created by Andrzej Kapolka on 9/15/14.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
in vec4 inPosition;
|
||||
in vec4 inNormal;
|
||||
in vec4 inColor;
|
||||
in vec4 inTexCoord0;
|
||||
in vec4 inTangent;
|
||||
in vec4 inSkinClusterIndex;
|
||||
in vec4 inSkinClusterWeight;
|
||||
in vec4 inTexCoord1;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
struct TransformObject {
|
||||
mat4 _model;
|
||||
mat4 _modelInverse;
|
||||
};
|
||||
|
||||
struct TransformCamera {
|
||||
mat4 _view;
|
||||
mat4 _viewInverse;
|
||||
mat4 _projectionViewUntranslated;
|
||||
mat4 _projection;
|
||||
mat4 _projectionInverse;
|
||||
vec4 _viewport;
|
||||
};
|
||||
|
||||
uniform transformObjectBuffer {
|
||||
TransformObject _object;
|
||||
};
|
||||
TransformObject getTransformObject() {
|
||||
return _object;
|
||||
}
|
||||
|
||||
uniform transformCameraBuffer {
|
||||
TransformCamera _camera;
|
||||
};
|
||||
TransformCamera getTransformCamera() {
|
||||
return _camera;
|
||||
}
|
||||
|
||||
|
||||
// the interpolated normal
|
||||
|
||||
out vec3 _normal;
|
||||
out vec3 _color;
|
||||
out vec2 _texCoord0;
|
||||
|
||||
void main(void) {
|
||||
_color = inColor.rgb;
|
||||
_texCoord0 = inTexCoord0.st;
|
||||
|
||||
// standard transform
|
||||
TransformCamera cam = getTransformCamera();
|
||||
TransformObject obj = getTransformObject();
|
||||
|
||||
|
||||
{ // transformModelToClipPos
|
||||
vec4 _eyepos = (obj._model * inPosition) + vec4(-inPosition.w * cam._viewInverse[3].xyz, 0.0);
|
||||
gl_Position = cam._projectionViewUntranslated * _eyepos;
|
||||
}
|
||||
|
||||
|
||||
{ // transformModelToEyeDir
|
||||
vec3 mr0 = vec3(obj._modelInverse[0].x, obj._modelInverse[1].x, obj._modelInverse[2].x);
|
||||
vec3 mr1 = vec3(obj._modelInverse[0].y, obj._modelInverse[1].y, obj._modelInverse[2].y);
|
||||
vec3 mr2 = vec3(obj._modelInverse[0].z, obj._modelInverse[1].z, obj._modelInverse[2].z);
|
||||
|
||||
vec3 mvc0 = vec3(dot(cam._viewInverse[0].xyz, mr0), dot(cam._viewInverse[0].xyz, mr1), dot(cam._viewInverse[0].xyz, mr2));
|
||||
vec3 mvc1 = vec3(dot(cam._viewInverse[1].xyz, mr0), dot(cam._viewInverse[1].xyz, mr1), dot(cam._viewInverse[1].xyz, mr2));
|
||||
vec3 mvc2 = vec3(dot(cam._viewInverse[2].xyz, mr0), dot(cam._viewInverse[2].xyz, mr1), dot(cam._viewInverse[2].xyz, mr2));
|
||||
|
||||
_normal = vec3(dot(mvc0, inNormal.xyz), dot(mvc1, inNormal.xyz), dot(mvc2, inNormal.xyz));
|
||||
}
|
||||
|
||||
}
|
||||
)SCRIBE";
|
||||
|
||||
#endif
|
|
@ -35,9 +35,8 @@
|
|||
#include <PathUtils.h>
|
||||
#include <GeometryCache.h>
|
||||
|
||||
#include "gputest_shaders.h"
|
||||
#include "gputest_simple_frag.h"
|
||||
#include "gputest_simple_vert.h"
|
||||
#include "../../libraries/render-utils/simple_frag.h"
|
||||
#include "../../libraries/render-utils/simple_vert.h"
|
||||
|
||||
class RateCounter {
|
||||
std::vector<float> times;
|
||||
|
@ -200,8 +199,8 @@ BasicModelPointer makeCube () {
|
|||
gpu::BufferView normalView { normalBuffer, normalElement };
|
||||
|
||||
// Create shaders
|
||||
auto vs = gpu::ShaderPointer(gpu::Shader::createVertex(basicVertexShader()));
|
||||
auto fs = gpu::ShaderPointer(gpu::Shader::createPixel(basicFragmentShader()));
|
||||
auto vs = gpu::ShaderPointer(gpu::Shader::createVertex({ simple_vert }));
|
||||
auto fs = gpu::ShaderPointer(gpu::Shader::createPixel({ simple_frag }));
|
||||
auto shader = gpu::ShaderPointer(gpu::Shader::createProgram(vs, fs));
|
||||
|
||||
gpu::Shader::BindingSet bindings;
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
<@include gpu/Config.slh@>
|
||||
<$VERSION_HEADER$>
|
||||
// Generated on <$_SCRIBE_DATE$>
|
||||
//
|
||||
// simple.frag
|
||||
// fragment shader
|
||||
//
|
||||
// Created by Andrzej Kapolka on 9/15/14.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
<@include DeferredBufferWrite.slh@>
|
||||
<@include model/Material.slh@>
|
||||
|
||||
// the interpolated normal
|
||||
in vec3 _normal;
|
||||
in vec3 _color;
|
||||
|
||||
void main(void) {
|
||||
Material material = getMaterial();
|
||||
packDeferredFragment(
|
||||
normalize(_normal.xyz),
|
||||
glowIntensity,
|
||||
_color.rgb,
|
||||
DEFAULT_SPECULAR, DEFAULT_SHININESS);
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
<@include gpu/Config.slh@>
|
||||
<$VERSION_HEADER$>
|
||||
// Generated on <$_SCRIBE_DATE$>
|
||||
//
|
||||
// simple.vert
|
||||
// vertex shader
|
||||
//
|
||||
// Created by Andrzej Kapolka on 9/15/14.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
<@include gpu/Inputs.slh@>
|
||||
|
||||
<@include gpu/Transform.slh@>
|
||||
|
||||
<$declareStandardTransform()$>
|
||||
|
||||
// the interpolated normal
|
||||
|
||||
out vec3 _normal;
|
||||
out vec3 _color;
|
||||
out vec2 _texCoord0;
|
||||
|
||||
void main(void) {
|
||||
_color = inColor.rgb;
|
||||
_texCoord0 = inTexCoord0.st;
|
||||
|
||||
// standard transform
|
||||
TransformCamera cam = getTransformCamera();
|
||||
TransformObject obj = getTransformObject();
|
||||
<$transformModelToClipPos(cam, obj, inPosition, gl_Position)$>
|
||||
<$transformModelToEyeDir(cam, obj, inNormal.xyz, _normal)$>
|
||||
}
|
Loading…
Reference in a new issue