Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GLSL 330 shaders #1726

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions ogre_media/materials/glsl150/Script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

function rotateY(t) {
var s = Math.sin(t);
var c = Math.cos(t);
return [
c, 0,-s, 0,
0, 1, 0, 0,
s, 0, c, 0,
0, 0, 0, 1
];
}

function perspective(fovy, aspect, near, far) {
var y = 1 / Math.tan(fovy / 2 * Math.PI / 180);
var x = y / aspect;
var c = (near + far) / (near - far);
var d = (near * far) / (near - far) * 2;
return [
x, 0, 0, 0,
0, y, 0, 0,
0, 0, c,-1,
0, 0, d, 0
];
}
18 changes: 9 additions & 9 deletions ogre_media/materials/glsl150/box.geom
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#version 150
#version 330 core

// Generates an axis-aligned box with a given size
// for each input vertex.
Expand All @@ -19,13 +19,13 @@ uniform mat4 worldviewproj_matrix;
uniform vec4 size;
uniform vec4 auto_size;

in gl_PerVertex {
vec4 gl_Position;
vec4 gl_FrontColor;
} gl_in[];
in PerVertex {
vec4 frontColor;
} gs_in[];
Comment on lines -22 to +24
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these are the only strictly necessary changes in this PR



out vec4 gl_TexCoord[];
out vec4 texCoord[];
out vec4 frontColor;

layout(points) in;
layout(triangle_strip, max_vertices=24) out;
Expand All @@ -49,12 +49,12 @@ void emitVertex( int side, vec4 x, vec4 y, vec4 z, vec3 tex )
vec4 pos_rel = tex.x*x + tex.y*y + tex.z*z;
vec4 pos = gl_in[0].gl_Position + vec4( pos_rel * size_factor * 0.5 );
gl_Position = worldviewproj_matrix * pos;
gl_TexCoord[0] = vec4( tex.x*0.5+0.5, tex.y*0.5+0.5, 0.0, 0.0 );
texCoord[0] = vec4( tex.x*0.5+0.5, tex.y*0.5+0.5, 0.0, 0.0 );

#ifdef WITH_LIGHTING
gl_FrontColor = vec4( gl_in[0].gl_FrontColor.xyz * lightness[side], gl_in[0].gl_FrontColor.a );
frontColor = vec4( gs_in[0].frontColor.xyz * lightness[side], gs_in[0].frontColor.a );
#else
gl_FrontColor = vec4( gl_in[0].gl_FrontColor.xyz, gl_in[0].gl_FrontColor.a );
gl_FrontColor = vec4( gs_in[0].frontColor.xyz, gs_in[0].frontColor.a );
#endif

#ifdef WITH_DEPTH
Expand Down
219 changes: 219 additions & 0 deletions ogre_media/materials/glsl150/box.gpjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
[
{
"executeOn": "ResetEvaluation",
"fileName": "../../../../../../../../tmp/.mount_GPUpadasGMNv/usr/share/gpupad/samples/Cube/math.js",
"id": 103,
"type": "Script"
},
{
"fileName": "cube_position_normal_texcoords.bin",
"id": 7253,
"items": [
{
"id": 7254,
"items": [
{
"count": 3,
"dataType": "Float",
"id": 7255,
"name": "position",
"padding": 0,
"type": "Field"
},
{
"count": 3,
"dataType": "Float",
"id": 7256,
"name": "normal",
"padding": 0,
"type": "Field"
},
{
"count": 2,
"dataType": "Float",
"id": 7257,
"name": "texcoords",
"padding": 0,
"type": "Field"
}
],
"name": "Vertex",
"offset": "0",
"rowCount": "36",
"type": "Block"
}
],
"type": "Buffer"
},
{
"id": 7247,
"items": [
{
"divisor": 0,
"fieldId": 7255,
"id": 7248,
"name": "vertex",
"normalize": false,
"type": "Attribute"
}
],
"name": "Stream",
"type": "Stream"
},
{
"bindingType": "Uniform",
"editor": "Expression4",
"id": 7250,
"name": "size",
"type": "Binding",
"values": [
"4",
"4",
"4",
"4"
]
},
{
"bindingType": "Uniform",
"editor": "Expression4x4",
"id": 78,
"name": "uView",
"type": "Binding",
"values": [
"1",
"0",
"0",
"0",
"0",
"1",
"0",
"0",
"0",
"0",
"1",
"0",
"0.40",
"-0.75",
"-4.00",
"1"
]
},
{
"bindingType": "Uniform",
"editor": "Expression",
"id": 7259,
"name": "uProjection",
"type": "Binding",
"values": [
"perspective(45, 1, 1, 100)"
]
},
{
"bindingType": "Uniform",
"editor": "Expression",
"id": 7249,
"name": "worldviewproj_matrix",
"type": "Binding",
"values": [
"uProjection*uView"
]
},
{
"bindingType": "Uniform",
"editor": "Expression4",
"id": 7251,
"name": "auto_size",
"type": "Binding",
"values": [
"4",
"4",
"4",
"4"
]
},
{
"id": 7241,
"items": [
{
"fileName": "pass_pos_color.vert",
"id": 7242,
"language": "GLSL",
"shaderType": "Vertex",
"type": "Shader"
},
{
"fileName": "box.geom",
"id": 7243,
"language": "GLSL",
"shaderType": "Geometry",
"type": "Shader"
}
],
"name": "Program",
"type": "Program"
},
{
"flipVertically": false,
"format": "RGBA8_UNorm",
"height": "600",
"id": 7252,
"name": "Texture",
"target": "Target2D",
"type": "Texture",
"width": "800"
},
{
"blendConstant": "#ffffffff",
"cullMode": "NoCulling",
"frontFace": "CCW",
"id": 7245,
"items": [
{
"blendAlphaDest": "Zero",
"blendAlphaEq": "Add",
"blendAlphaSource": "One",
"blendColorDest": "Zero",
"blendColorEq": "Add",
"blendColorSource": "One",
"colorWriteMask": 15,
"id": 7246,
"level": 0,
"name": "Attachment",
"textureId": 7252,
"type": "Attachment"
}
],
"logicOperation": "NoLogicOperation",
"name": "Target",
"polygonMode": "Fill",
"type": "Target"
},
{
"callType": "ClearTexture",
"checked": true,
"clearColor": "#ff000000",
"clearDepth": 1,
"clearStencil": 0,
"executeOn": "EveryEvaluation",
"id": 7258,
"name": "Clear Texture",
"textureId": 7252,
"type": "Call"
},
{
"baseInstance": "0",
"callType": "Draw",
"checked": true,
"count": "3",
"executeOn": "EveryEvaluation",
"first": "0",
"id": 7244,
"instanceCount": "1",
"name": "Draw",
"primitiveType": "Points",
"programId": 7241,
"targetId": 7245,
"type": "Call",
"vertexStreamId": 7247
}
]
3 changes: 3 additions & 0 deletions ogre_media/materials/glsl150/box.gpjs.state
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[General]
editorState=@ByteArray(\0\0\0\xff\0\0\0\0\xfd\0\0\0\x1\0\0\0\x2\0\0\x4\xf9\0\0\x3\v\xfc\x1\0\0\0\x10\xfc\0\0\0\0\0\0\x3 \0\0\0\0\0\xff\xff\xff\xfa\0\0\0\0\x1\0\0\0\x2\xfb\0\0\0\x1e\0\x66\0\x37\0\x61\0\x64\0\x35\0\x63\0\x66\0\x38\0\x36\0\x35\0\x30\0\x61\0\x66\0\x63\0\x65\x1\0\0\0\0\xff\xff\xff\xff\0\0\0\0\0\0\0\0\xfb\0\0\0 \0\x31\0\x31\0\x36\0\x34\0\x39\0\x33\0\x35\0\x34\0\x37\0\x61\0\x65\0\x62\0\x33\0\x63\0\x36\0\x31\x1\0\0\0\0\xff\xff\xff\xff\0\0\0\0\0\0\0\0\xfc\0\0\0\0\0\0\x1\xe0\0\0\0\0\0\xff\xff\xff\xfa\0\0\0\0\x1\0\0\0\x2\xfb\0\0\0 \0\x31\0\x30\0\x61\0\x65\0\x32\0\x66\0\x64\0\x39\0\x63\0\x34\0\x65\0\x63\0\x64\0\x39\0\x66\0\x31\x1\0\0\0\0\xff\xff\xff\xff\0\0\0\0\0\0\0\0\xfb\0\0\0 \0\x39\0\x35\0\x64\0\x62\0\x33\0\x37\0\x38\0\x64\0\x31\0\x64\0\x33\0\x37\0\x31\0\x63\0\x62\0\x66\x1\0\0\0\0\xff\xff\xff\xff\0\0\0\0\0\0\0\0\xfc\0\0\x1\xe6\0\0\x1\xd7\0\0\0\0\0\xff\xff\xff\xfa\0\0\0\0\x1\0\0\0\x2\xfb\0\0\0 \0\x64\0\x35\0\x35\0\x38\0\x39\0\x30\0\x66\0\x37\0\x61\0\x64\0\x61\0\x33\0\x37\0\x35\0\x66\0\x30\x1\0\0\0\0\xff\xff\xff\xff\0\0\0\0\0\0\0\0\xfb\0\0\0 \0\x65\0\x30\0\x36\0\x64\0\x38\0\x31\0\x61\0\x38\0\x39\0\x64\0\x64\0\x38\0\x37\0\x61\0\x35\0\x36\x1\0\0\0\0\xff\xff\xff\xff\0\0\0\0\0\0\0\0\xfc\0\0\0\0\0\0\x2\x61\0\0\0\0\0\xff\xff\xff\xfa\0\0\0\0\x1\0\0\0\x2\xfb\0\0\0 \0\x66\0\x38\0\x30\0\x64\0\x65\0\x36\0\x63\0\x35\0\x37\0\x34\0\x33\0\x37\0\x35\0\x32\0\x30\0\x39\x1\0\0\0\0\xff\xff\xff\xff\0\0\0\0\0\0\0\0\xfb\0\0\0 \0\x63\0\x35\0\x36\0\x31\0\x65\0\x38\0\x37\0\x38\0\x33\0\x63\0\x63\0\x30\0\x31\0\x30\0\x38\0\x66\x1\0\0\0\0\xff\xff\xff\xff\0\0\0\0\0\0\0\0\xfc\0\0\x2g\0\0\x2N\0\0\0\0\0\xff\xff\xff\xfa\0\0\0\0\x1\0\0\0\x4\xfb\0\0\0 \0\x62\0\x39\0\x32\0\x38\0\x31\0\x62\0\x65\0\x30\0\x36\0\x66\0\x64\0\x61\0\x32\0\x32\0\x34\0\x39\x1\0\0\0\0\xff\xff\xff\xff\0\0\0\0\0\0\0\0\xfb\0\0\0 \0\x37\0\x37\0\x31\0\x38\0\x30\0\x39\0\x36\0\x63\0\x32\0\x65\0\x30\0\x65\0\x62\0\x38\0\x38\0\x65\x1\0\0\0\0\xff\xff\xff\xff\0\0\0\0\0\0\0\0\xfb\0\0\0 \0\x38\0\x32\0\x38\0\x32\0\x34\0\x37\0\x66\0\x33\0\x63\0\x62\0\x31\0\x34\0\x37\0\x30\0\x61\0\x38\x1\0\0\0\0\xff\xff\xff\xff\0\0\0\0\0\0\0\0\xfb\0\0\0 \0\x66\0\x36\0\x33\0\x38\0\x66\0\x39\0\x39\0\x63\0\x38\0\x63\0\x35\0\x36\0\x34\0\x61\0\x36\0\x66\x1\0\0\0\0\xff\xff\xff\xff\0\0\0\0\0\0\0\0\xfb\0\0\0\x1e\0\x32\0\x63\0\x66\0\x33\0\x33\0\x39\0\x63\0\x38\0\x62\0\x30\0\x66\0\x61\0\x63\0\x31\0\x64\x1\0\0\0\0\0\0\x4\xb5\0\0\0\0\0\0\0\0\xfb\0\0\0\x1e\0\x66\0\x30\0\x37\0\x31\0\x31\0\x66\0\x32\0\x35\0\x63\0\x65\0\x37\0\x61\0\x64\0\x31\0\x66\x1\0\0\0\0\0\0\x4\xb5\0\0\0\0\0\0\0\0\xfb\0\0\0 \0\x39\0\x65\0\x63\0\x34\0\x37\0\x62\0\x37\0\x35\0\x30\0\x39\0\x61\0\x34\0\x34\0\x35\0\x39\0\x30\x1\0\0\0\0\0\0\x4\xb5\0\0\0\0\0\0\0\0\xfb\0\0\0\x1e\0\x32\0\x31\0\x30\0\x31\0\x37\0\x65\0\x32\0\x66\0\x35\0\x37\0\x66\0\x32\0\x39\0\x66\0\x61\x1\0\0\0\0\0\0\x4\xb5\0\0\0\0\0\0\0\0\xfb\0\0\0 \0\x65\0\x35\0\x37\0\x33\0\x65\0\x30\0\x36\0\x65\0\x39\0\x34\0\x36\0\x62\0\x35\0\x36\0\x65\0\x35\x1\0\0\0\0\0\0\x4\xb5\0\0\0\0\0\0\0\0\xfb\0\0\0 \0\x36\0\x63\0\x63\0\x35\0\x34\0\x33\0\x65\0\x62\0\x34\0\x61\0\x61\0\x31\0\x35\0\x63\0\x37\0\x36\x1\0\0\0\0\0\0\x4\xb5\0\0\0\0\0\0\0\0\xfb\0\0\0 \0\x64\0\x65\0\x32\0\x32\0\x34\0\x33\0\x65\0\x63\0\x62\0\x38\0\x62\0\x64\0\x32\0\x37\0\x31\0\x61\x1\0\0\0\0\0\0\x4\xb5\0\0\0\0\0\0\0\0\xfb\0\0\0 \0\x62\0\x36\0\x62\0\x62\0\x37\0\x30\0\x30\0\x63\0\x39\0\x31\0\x34\0\x35\0\x34\0\x61\0\x32\0\x37\x1\0\0\0\0\0\0\x2X\0\0\0\0\0\0\0\0\xfc\0\0\x2^\0\0\x2W\0\0\0\0\0\xff\xff\xff\xfa\0\0\0\0\x1\0\0\0\x4\xfb\0\0\0 \0\x32\0\x39\0\x38\0\x62\0\x35\0\x64\0\x37\0\x34\0\x35\0\x36\0\x38\0\x39\0\x39\0\x64\0\x30\0\x31\x1\0\0\0\0\xff\xff\xff\xff\0\0\0\0\0\0\0\0\xfb\0\0\0 \0\x66\0\x34\0\x64\0\x30\0\x39\0\x39\0\x63\0\x61\0\x32\0\x38\0\x33\0\x34\0\x33\0\x32\0\x36\0\x63\x1\0\0\0\0\xff\xff\xff\xff\0\0\0\0\0\0\0\0\xfb\0\0\0 \0\x63\0\x36\0\x36\0\x34\0\x66\0\x38\0\x34\0\x65\0\x37\0\x37\0\x36\0\x37\0\x31\0\x61\0\x38\0\x35\x1\0\0\0\0\xff\xff\xff\xff\0\0\0\0\0\0\0\0\xfb\0\0\0 \0\x34\0\x36\0\x33\0\x34\0\x66\0\x64\0\x66\0\x63\0\x34\0\x65\0\x39\0\x39\0\x39\0\x30\0\x30\0\x39\x1\0\0\0\0\xff\xff\xff\xff\0\0\0\0\0\0\0\0\xfc\0\0\0\0\0\0\x2\x8f\0\0\0{\0\xff\xff\xff\xfa\0\0\0\0\x1\0\0\0\x4\xfb\0\0\0 \0\x34\0\x33\0\x33\0\x33\0\x65\0\x34\0\x61\0\x31\0\x38\0\x33\0\x35\0\x30\0\x64\0\x63\0\x64\0\x38\x1\0\0\0\0\xff\xff\xff\xff\0\0\0H\0\xff\xff\xff\xfb\0\0\0\x1e\0\x33\0\x62\0\x62\0\x38\0\x32\0\x61\0\x66\0\x61\0\x37\0\x66\0\x32\0\x61\0\x64\0\x38\0\x38\x1\0\0\0\0\xff\xff\xff\xff\0\0\0H\0\xff\xff\xff\xfb\0\0\0 \0\x37\0\x32\0\x61\0\x30\0\x66\0\x32\0\x64\0\x65\0\x39\0\x35\0\x34\0\x32\0\x30\0\x64\0\x34\0\x66\x1\0\0\0\0\xff\xff\xff\xff\0\0\0\0\0\0\0\0\xfb\0\0\0 \0\x64\0\x30\0\x36\0\x65\0\x39\0\x66\0\x66\0\x64\0\x34\0\x65\0\x66\0\x36\0\x32\0\x30\0\x63\0\x66\x1\0\0\0\0\xff\xff\xff\xff\0\0\0H\0\xff\xff\xff\xfb\0\0\0 \0\x64\0\x35\0\x38\0\x35\0\x37\0\x32\0\x35\0\x61\0\x64\0\x31\0\x62\0\x36\0\x30\0\x35\0\x66\0\x33\x1\0\0\x2\x95\0\0\x2\x64\0\0\0H\0\xff\xff\xff\0\0\x4\xf9\0\0\0\0\0\0\0\x4\0\0\0\x4\0\0\0\b\0\0\0\b\xfc\0\0\0\0)
openEditors=103|d06e9ffd4ef620cf, 7242|4333e4a18350dcd8, 7243|3bb82afa7f2ad88, 7252|d585725ad1b605f3
Binary file not shown.
27 changes: 27 additions & 0 deletions ogre_media/materials/glsl150/depth.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#version 330

// Passes on the packed depth value

// Splits up a normalized depth value in the range (0..1)
// into the vertex RGB values.
// Alpha values below 1/255 are rendered transparent.

uniform float alpha;
uniform float far_clip_distance;

const float minimum_alpha = 1.0 / 255.0;

varying float depth;

void main()
{
float normalized_depth = depth / far_clip_distance;

// split up float into rgb components
const vec3 shift = vec3(256.0 * 256.0, 256.0, 1.0);
const vec3 mask = vec3(0.0, 1.0 / 256.0, 1.0 / 256.0);
vec3 depth_packed = fract(normalized_depth * shift);
depth_packed -= depth_packed.xxy * mask;

gl_FragColor = vec4( depth_packed.zyx, step( minimum_alpha, alpha ));
}
14 changes: 14 additions & 0 deletions ogre_media/materials/glsl150/glsl150.program
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

fragment_program rviz/glsl150/depth.frag glsl { source depth.frag }

//all shaders, sorted by name

geometry_program rviz/glsl150/billboard.geom glsl
Expand Down Expand Up @@ -78,3 +81,14 @@ vertex_program rviz/glsl150/pass_pos_color.vert glsl
{
source pass_pos_color.vert
}


fragment_program rviz/glsl150/smooth_square.frag glsl
{
source smooth_square.frag
default_params
{
param_named_auto highlight custom 5
param_named_auto alpha custom 1
}
}
19 changes: 12 additions & 7 deletions ogre_media/materials/glsl150/pass_pos_color.vert
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
#version 150 compatibility
#version 330

// this merely passes over position and color,
// as needed by box.geom

out gl_PerVertex {
vec4 gl_Position;
vec4 gl_FrontColor;
};
layout(location = 0) in vec3 vertex;
layout(location = 3) in vec4 color;

uniform mat4 uProjection;

out PerVertex {
vec4 frontColor;
} perVertex;


void main() {
gl_Position = gl_Vertex;
gl_FrontColor = gl_Color;
gl_Position = uProjection * vec4(vertex, 1);
perVertex.frontColor = color;
}
30 changes: 30 additions & 0 deletions ogre_media/materials/glsl150/smooth_square.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#version 330

// rasterizes a smooth square with ax,ay in [-0.5..0.5]

uniform vec4 highlight;
uniform float alpha;

in vec4 texCoord[];
in vec4 frontColor;

out vec4 fragColor;

void main()
{
float ax = texCoord[0].x-0.5;
float ay = texCoord[0].y-0.5;

float blend = smoothstep(-0.48, -0.45, ay) * (1.0 - smoothstep(0.45, 0.48, ay)) *
smoothstep(-0.48, -0.45, ax) * (1.0 - smoothstep(0.45, 0.48, ax));

float inv_blend = 1.0 - blend;
vec3 col = blend * frontColor.xyz + (sign(0.5 - length(vec3(frontColor.xyz))) * vec3(0.2, 0.2, 0.2) + frontColor.xyz) * inv_blend;

//alternative version: make color at edge darker
//vec3 col = (0.5 + 0.5*blend) * gl_Color.xyz;

col = col + col * highlight.xyz;

fragColor = vec4(col.r, col.g, col.b, alpha * frontColor.a );
}
Loading