Skip to content

Instantly share code, notes, and snippets.

@croxis
Created July 8, 2015 15:56
Show Gist options
  • Save croxis/e0b4e5d0fc26f020675c to your computer and use it in GitHub Desktop.
Save croxis/e0b4e5d0fc26f020675c to your computer and use it in GitHub Desktop.
Ring shaders
#version 410
#pragma include "Includes/Configuration.include"
#pragma include "Includes/Structures/VertexOutput.struct"
#extension GL_EXT_shader_image_load_store : enable
// Input from the vertex shader
layout(location=0) in VertexOutput vOutput;
// Texture Samplers
uniform sampler2D p3d_Texture0;
uniform sampler2D p3d_Texture1;
uniform sampler2D p3d_Texture2;
uniform sampler2D p3d_Texture3;
layout(location=7) in vec4 position_in_object_coordinates;
// This is required for the materials
#pragma include "Includes/MaterialPacking.include"
#pragma include "Includes/CommonFunctions.include"
// This include enables us to compute the tangent in the fragment shader
#pragma include "Includes/TangentFromDDX.include"
// Transparency bufers
layout (r32ui) coherent uniform uimage2D pixelCountBuffer;
layout (r32ui) coherent uniform uimage2D listHeadBuffer;
layout (r32i) coherent uniform iimage2D spinLockBuffer;
layout (rgba32ui) coherent uniform uimageBuffer materialDataBuffer;
#pragma include "Includes/Transparency.include"
uniform vec3 cameraPosition;
void main() {
float inside = 1.6;
float outside = 2.6;
if(length(position_in_object_coordinates) > outside || length(position_in_object_coordinates) < inside) {
discard;
}
// Create a material to store the properties on
//Material m = getDefaultMaterial();
TransparentMaterial tm = getDefaultTransparentMaterial();
vec2 newTexCoords = vOutput.texcoord;
newTexCoords.x = (length(position_in_object_coordinates) - inside) / (outside - inside);
// ^ adjust so inner ring edge is 0, outer edge is 1
// Sample the diffuse color
//vec4 sampledDiffuse = texture(p3d_Texture0, vOutput.texcoord);
vec4 sampledDiffuse = texture(p3d_Texture0, newTexCoords);
// Alpha test
// if (sampledDiffuse.a < 0.5) discard;
// Sample the other maps
vec4 sampledNormal = texture(p3d_Texture1, vOutput.texcoord);
vec4 sampledSpecular = texture(p3d_Texture2, vOutput.texcoord);
vec4 sampledRoughness = texture(p3d_Texture3, vOutput.texcoord);
// Extract the material properties
float bumpFactor = vOutput.materialDiffuse.w * 0.0;
float specularFactor = vOutput.materialSpecular.x;
float metallic = vOutput.materialSpecular.y;
float roughnessFactor = vOutput.materialSpecular.z;
// Merge the detail normal with the vertex normal
vec3 detailNormal = sampledNormal.xyz * 2.0 - 1.0;
vec3 tangent; vec3 binormal;
reconstructTanBin(tangent, binormal);
vec3 mixedNormal = mergeNormal(detailNormal, bumpFactor, vOutput.normalWorld, tangent, binormal);
// Store the properties
//m.baseColor = sampledDiffuse.rgb * vOutput.materialDiffuse.rgb;
//m.roughness = sampledRoughness.r * roughnessFactor;
//m.specular = sampledSpecular.r * specularFactor;
//m.metallic = metallic;
//m.normal = mixedNormal;
//m.position = vOutput.positionWorld;
//m.roughness = 0.4;
//m.specular = 0.01;
//m.metallic = 0.0;
//m.translucency = (vOutput.materialDiffuse.r + vOutput.materialDiffuse.g + vOutput.materialDiffuse.b) / 3;
//tm.color = sampledDiffuse.rgb * vOutput.materialDiffuse.rgb;
tm.color = sampledDiffuse.rgb;
tm.alpha = (sampledDiffuse.r + sampledDiffuse.g + sampledDiffuse.b) * 3.0/ 3.0;
//tm.alpha = (tm.color.r + tm.color.g + tm.color.b) / 3.0;
//tm.alpha = 0.1;
tm.normal = mixedNormal;
tm.depth = distance(cameraPosition, vOutput.positionWorld) / CAMERA_FAR;
tm.materialType = 0;
// Write the material to the G-Buffer
//renderMaterial(m);
renderTransparentMaterial(tm);
}
#version 410
#pragma include "Includes/Configuration.include"
#pragma include "Includes/Structures/VertexOutput.struct"
#pragma include "Includes/Structures/PandaMaterial.struct"
// Matrices
uniform mat4 trans_model_to_world;
uniform mat4 tpose_world_to_model;
// Material properties
in vec4 p3d_Vertex;
in vec3 p3d_Normal;
in vec4 p3d_Color;
// Texture-Coordinate
in vec2 p3d_MultiTexCoord0;
// Outputs
layout(location=0) out VertexOutput vOutput;
uniform PandaMaterial p3d_Material;
uniform vec4 p3d_ColorScale;
uniform mat4 p3d_ModelViewProjectionMatrix;
// We need this for the velocity
uniform mat4 lastMVP;
layout(location=7) out vec4 position_in_object_coordinates;
void main() {
// Transform normal to world space
vOutput.normalWorld = normalize(tpose_world_to_model * vec4(p3d_Normal, 0) ).xyz;
// Transform position to world space
vOutput.positionWorld = (trans_model_to_world * p3d_Vertex).xyz;
// Pass texcoord to fragment shader
vOutput.texcoord = p3d_MultiTexCoord0.xy;
// Also pass diffuse to fragment shader
vOutput.materialDiffuse = p3d_Material.diffuse * p3d_ColorScale * p3d_Color;
vOutput.materialSpecular = p3d_Material.specular;
vOutput.materialAmbient = p3d_Material.ambient.z;
// Compute velocity in vertex shader, but it's important
// to move the w-divide to the fragment shader
vOutput.lastProjectedPos = lastMVP * vec4(vOutput.positionWorld, 1) * vec4(1,1,1,2);
// Transform vertex to window space
// Only required when not using tesselation shaders
gl_Position = p3d_ModelViewProjectionMatrix * p3d_Vertex;
position_in_object_coordinates = p3d_Vertex;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment