hook textures up to polyvoxs

This commit is contained in:
Seth Alves 2015-08-07 13:33:00 -07:00
parent 44ee13a185
commit fcb30dbbe7
3 changed files with 50 additions and 31 deletions

View file

@ -708,9 +708,9 @@ void RenderablePolyVoxEntityItem::render(RenderArgs* args) {
slotBindings.insert(gpu::Shader::Binding(std::string("materialBuffer"), MATERIAL_GPU_SLOT));
slotBindings.insert(gpu::Shader::Binding(std::string("xMap"), 0));
slotBindings.insert(gpu::Shader::Binding(std::string("yMap"), 1));
// slotBindings.insert(gpu::Shader::Binding(std::string("specularMap"), 2));
// slotBindings.insert(gpu::Shader::Binding(std::string("emissiveMap"), 3));
// slotBindings.insert(gpu::Shader::Binding(std::string("lightBuffer"), 4));
slotBindings.insert(gpu::Shader::Binding(std::string("zMap"), 2));
slotBindings.insert(gpu::Shader::Binding(std::string("polyVoxDimensions"), 3));
gpu::ShaderPointer program = gpu::ShaderPointer(gpu::Shader::createProgram(vertexShader, pixelShader));
gpu::Shader::makeProgram(*program, slotBindings);
@ -754,9 +754,18 @@ void RenderablePolyVoxEntityItem::render(RenderArgs* args) {
if (_xTexture) {
batch.setResourceTexture(0, _xTexture->getGPUTexture());
} else {
batch.setResourceTexture(0, DependencyManager::get<TextureCache>()->getWhiteTexture());
}
if (_yTexture) {
batch.setResourceTexture(1, _yTexture->getGPUTexture());
} else {
batch.setResourceTexture(1, DependencyManager::get<TextureCache>()->getWhiteTexture());
}
if (_zTexture) {
batch.setResourceTexture(2, _zTexture->getGPUTexture());
} else {
batch.setResourceTexture(2, DependencyManager::get<TextureCache>()->getWhiteTexture());
}
batch.drawIndexed(gpu::TRIANGLES, mesh->getNumIndices(), 0);

View file

@ -4,22 +4,46 @@
// model.frag
// fragment shader
//
// Created by Seth Alves on 2015-8-3
// Copyright 2015 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
//
void packDeferredFragment(vec3 normal, float alpha, vec3 diffuse, vec3 specular, float shininess) {
_fragColor0 = vec4(diffuse.rgb, alpha);
_fragColor1 = vec4(bestFitNormal(normal), 1.0);
_fragColor2 = vec4(specular, shininess / 128.0);
}
<@include gpu/Inputs.slh@>
layout(location = 0) out vec4 _fragColor0;
layout(location = 1) out vec4 _fragColor1;
layout(location = 2) out vec4 _fragColor2;
<@include model/Material.slh@>
in vec3 _normal;
in vec4 _position;
in vec4 _inPosition;
uniform sampler2D xMap;
uniform sampler2D yMap;
uniform sampler2D zMap;
void main(void) {
packDeferredFragment(normalize(_normal.xyz), 0.0, vec3(1.0, 1.0, 1.0), vec3(0.02, 0.02, 0.02), 10.0);
vec3 worldNormal = cross(dFdy(_inPosition.xyz), dFdx(_inPosition.xyz));
worldNormal = normalize(worldNormal);
vec4 xyDiffuse = texture2D(xMap, (_inPosition.xy - vec2(0.5)) / -8.0);
vec4 xzDiffuse = texture2D(yMap, (_inPosition.xz - vec2(0.5)) / -8.0);
vec4 yzDiffuse = texture2D(zMap, (_inPosition.yz - vec2(0.5)) / -8.0);
vec3 xyDiffuseScaled = xyDiffuse.rgb * abs(worldNormal.z);
vec3 xzDiffuseScaled = xzDiffuse.rgb * abs(worldNormal.y);
vec3 yzDiffuseScaled = yzDiffuse.rgb * abs(worldNormal.x);
vec4 diffuse = vec4(xyDiffuseScaled + xzDiffuseScaled + yzDiffuseScaled, 1.0);
Material mat = getMaterial();
_fragColor0 = vec4(diffuse.rgb, 0.0);
_fragColor1 = vec4(_normal, 1.0);
_fragColor2 = vec4(getMaterialSpecular(mat), getMaterialShininess(mat) / 128.0);
}

View file

@ -10,35 +10,21 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
<@include gpu/Inputs.slh@>
<@include gpu/Transform.slh@>
<$declareStandardTransform()$>
const int MAX_TEXCOORDS = 2;
uniform mat4 texcoordMatrices[MAX_TEXCOORDS];
// interpolated eye position
varying vec4 interpolatedPosition;
// the interpolated normal
varying vec4 interpolatedNormal;
varying vec3 color;
out vec4 _position;
out vec4 _inPosition;
out vec3 _normal;
void main(void) {
// pass along the diffuse color
color = gl_Color.xyz;
// and the texture coordinates
gl_TexCoord[0] = texcoordMatrices[0] * vec4(gl_MultiTexCoord0.xy, 0.0, 1.0);
// standard transform
TransformCamera cam = getTransformCamera();
TransformObject obj = getTransformObject();
<$transformModelToEyeAndClipPos(cam, obj, gl_Vertex, interpolatedPosition, gl_Position)$>
<$transformModelToEyeDir(cam, obj, gl_Normal, interpolatedNormal.xyz)$>
interpolatedNormal = vec4(normalize(interpolatedNormal.xyz), 0.0);
<$transformModelToEyeAndClipPos(cam, obj, inPosition, _position, gl_Position)$>
<$transformModelToEyeDir(cam, obj, inNormal.xyz, _normal)$>
_inPosition = inPosition;
}