浏览代码

render : Added DebugRenderMode & corresponding shaders. naive (VERY) implementation in MeshViewer.

legacy
Benjamin ‘Touky’ Huet touky 11 年前
父节点
当前提交
bb0051ae8e
共有 13 个文件被更改,包括 988 次插入42 次删除
  1. +47
    -30
      src/easymesh/easymesh.cpp
  2. +5
    -3
      src/easymesh/easymesh.h
  3. +225
    -0
      src/easymesh/shiny_SK.lolfx
  4. +192
    -0
      src/easymesh/shinydebugUV.lolfx
  5. +159
    -0
      src/easymesh/shinydebuglighting.lolfx
  6. +121
    -0
      src/easymesh/shinydebugnormal.lolfx
  7. +117
    -0
      src/easymesh/shinydebugwireframe.lolfx
  8. +0
    -2
      src/gpu/vertexbuffer.cpp
  9. +6
    -1
      src/lolcore.vcxproj
  10. +15
    -0
      src/lolcore.vcxproj.filters
  11. +57
    -0
      src/video.cpp
  12. +21
    -0
      src/video.h
  13. +23
    -6
      test/MeshViewer.cpp

+ 47
- 30
src/easymesh/easymesh.cpp 查看文件

@@ -36,6 +36,11 @@
#include "easymesh/easymesh-compiler.h"

LOLFX_RESOURCE_DECLARE(shiny);
LOLFX_RESOURCE_DECLARE(shinydebugwireframe);
LOLFX_RESOURCE_DECLARE(shinydebuglighting);
LOLFX_RESOURCE_DECLARE(shinydebugnormal);
LOLFX_RESOURCE_DECLARE(shinydebugUV);
LOLFX_RESOURCE_DECLARE(shiny_SK);

namespace lol
{
@@ -64,29 +69,39 @@ void EasyMesh::CloseBrace()

void EasyMesh::MeshConvert(Shader* provided_shader)
{
if(provided_shader == NULL)
for (int i = 0; i < DebugRenderMode::Max; i++)
{
m_gpu.shader = Shader::Create(LOLFX_RESOURCE_NAME(shiny));
}
else
{
m_gpu.shader = provided_shader;
if (i == DebugRenderMode::Default)
{
if(provided_shader == NULL)
m_gpu.shader << Shader::Create(LOLFX_RESOURCE_NAME(shiny));
else
m_gpu.shader << provided_shader;
}
else if (i == DebugRenderMode::Wireframe)
m_gpu.shader << Shader::Create(LOLFX_RESOURCE_NAME(shinydebugwireframe));
else if (i == DebugRenderMode::Lighting)
m_gpu.shader << Shader::Create(LOLFX_RESOURCE_NAME(shinydebuglighting));
else if (i == DebugRenderMode::Normal)
m_gpu.shader << Shader::Create(LOLFX_RESOURCE_NAME(shinydebugnormal));
else if (i == DebugRenderMode::UV)
m_gpu.shader << Shader::Create(LOLFX_RESOURCE_NAME(shinydebugUV));

m_gpu.modelview << m_gpu.shader.Last()->GetUniformLocation("in_ModelView");
m_gpu.view << m_gpu.shader.Last()->GetUniformLocation("in_View");
m_gpu.invview << m_gpu.shader.Last()->GetUniformLocation("in_Inv_View");
m_gpu.proj << m_gpu.shader.Last()->GetUniformLocation("in_Proj");
m_gpu.normalmat << m_gpu.shader.Last()->GetUniformLocation("in_NormalMat");
m_gpu.damage << m_gpu.shader.Last()->GetUniformLocation("in_Damage");
m_gpu.lights << m_gpu.shader.Last()->GetUniformLocation("u_Lights");
m_gpu.coord << m_gpu.shader.Last()->GetAttribLocation("in_Vertex",
VertexUsage::Position, 0);
m_gpu.norm << m_gpu.shader.Last()->GetAttribLocation("in_Normal",
VertexUsage::Normal, 0);
m_gpu.color << m_gpu.shader.Last()->GetAttribLocation("in_Color",
VertexUsage::Color, 0);
}

m_gpu.modelview = m_gpu.shader->GetUniformLocation("in_ModelView");
m_gpu.view = m_gpu.shader->GetUniformLocation("in_View");
m_gpu.invview = m_gpu.shader->GetUniformLocation("in_Inv_View");
m_gpu.proj = m_gpu.shader->GetUniformLocation("in_Proj");
m_gpu.normalmat = m_gpu.shader->GetUniformLocation("in_NormalMat");
m_gpu.damage = m_gpu.shader->GetUniformLocation("in_Damage");
m_gpu.lights = m_gpu.shader->GetUniformLocation("u_Lights");
m_gpu.coord = m_gpu.shader->GetAttribLocation("in_Vertex",
VertexUsage::Position, 0);
m_gpu.norm = m_gpu.shader->GetAttribLocation("in_Normal",
VertexUsage::Normal, 0);
m_gpu.color = m_gpu.shader->GetAttribLocation("in_Color",
VertexUsage::Color, 0);

m_gpu.vdecl = new VertexDeclaration(
VertexStream<vec3,vec3,u8vec4>(VertexUsage::Position,
VertexUsage::Normal,
@@ -122,10 +137,12 @@ void EasyMesh::MeshConvert(Shader* provided_shader)

void EasyMesh::Render(mat4 const &model, float damage)
{
DebugRenderMode d = Video::GetDebugRenderMode();

mat4 modelview = Scene::GetDefault()->GetViewMatrix() * model;
mat3 normalmat = transpose(inverse(mat3(modelview)));

m_gpu.shader->Bind();
m_gpu.shader[d]->Bind();

/* FIXME: this should be hidden in the shader */
/* FIXME: the 4th component of the position can be used for other things */
@@ -135,16 +152,16 @@ void EasyMesh::Render(mat4 const &model, float damage)
light_data << lights[i]->GetPosition() << lights[i]->GetColor();
while (light_data.Count() < 8)
light_data << vec4(0.f) << vec4(0.f);
m_gpu.shader->SetUniform(m_gpu.lights, light_data);
m_gpu.shader->SetUniform(m_gpu.modelview, modelview);
m_gpu.shader->SetUniform(m_gpu.view, Scene::GetDefault()->GetViewMatrix());
m_gpu.shader->SetUniform(m_gpu.invview, inverse(Scene::GetDefault()->GetViewMatrix()));
m_gpu.shader->SetUniform(m_gpu.proj, Scene::GetDefault()->GetProjMatrix());
m_gpu.shader->SetUniform(m_gpu.normalmat, normalmat);
m_gpu.shader->SetUniform(m_gpu.damage, damage);
m_gpu.shader[d]->SetUniform(m_gpu.lights[d], light_data);
m_gpu.shader[d]->SetUniform(m_gpu.modelview[d], modelview);
m_gpu.shader[d]->SetUniform(m_gpu.view[d], Scene::GetDefault()->GetViewMatrix());
m_gpu.shader[d]->SetUniform(m_gpu.invview[d], inverse(Scene::GetDefault()->GetViewMatrix()));
m_gpu.shader[d]->SetUniform(m_gpu.proj[d], Scene::GetDefault()->GetProjMatrix());
m_gpu.shader[d]->SetUniform(m_gpu.normalmat[d], normalmat);
m_gpu.shader[d]->SetUniform(m_gpu.damage[d], damage);
m_gpu.vdecl->Bind();
m_gpu.vdecl->SetStream(m_gpu.vbo, m_gpu.coord, m_gpu.norm, m_gpu.color);
m_gpu.vdecl->SetStream(m_gpu.vbo, m_gpu.coord[d], m_gpu.norm[d], m_gpu.color[d]);
m_gpu.ibo->Bind();
m_gpu.vdecl->DrawIndexedElements(MeshPrimitive::Triangles,
0, 0, m_gpu.vertexcount,


+ 5
- 3
src/easymesh/easymesh.h 查看文件

@@ -154,9 +154,11 @@ private:
/* FIXME: put this in a separate class so that we can copy meshes. */
struct
{
Shader *shader;
ShaderAttrib coord, norm, color;
ShaderUniform modelview, view, invview, proj, normalmat, damage, lights;
/* FIXME: very naughty way of handling debug render modes */
Array<Shader *>shader;
Array<ShaderAttrib> coord, norm, color;
Array<ShaderUniform> modelview, view, invview, proj, normalmat, damage, lights;

VertexDeclaration *vdecl;
VertexBuffer *vbo;
IndexBuffer *ibo;


+ 225
- 0
src/easymesh/shiny_SK.lolfx 查看文件

@@ -0,0 +1,225 @@

[vert.glsl]
#version 120

attribute vec3 in_Vertex;
attribute vec3 in_Normal;
attribute vec4 in_Color;
attribute vec2 in_Index;
attribute vec2 in_Weight;

uniform mat4 in_ModelView;
uniform mat4 in_View;
uniform mat4 in_Proj;
uniform mat3 in_NormalMat;
//10is not a fix idea, should be more.
uniform mat4 in_BoneList[10];

varying vec4 pass_Vertex; /* View space */
varying vec3 pass_TNormal;
varying vec4 pass_Color;

void main(void)
{
vec4 vertex = in_ModelView * vec4(in_Vertex, 1.0);
vec3 tnorm = normalize(in_NormalMat * in_Normal);

pass_Vertex = vertex;
pass_TNormal = tnorm;
pass_Color = in_Color;

gl_Position = in_Proj * vertex;
}

[frag.glsl]
#version 120

#if defined GL_ES
precision highp float;
#endif

uniform float in_Damage;
uniform mat4 in_View;
uniform mat4 in_Inv_View;

uniform vec4 u_Lights[8 * 2];

varying vec4 pass_Vertex; /* View space */
varying vec3 pass_TNormal;
varying vec4 pass_Color;

#if 0
//Cube Light
//Cos(45) = 0.70710678118
//1.0 - Cos(45) = 0.29289321881

const float cos_45 = 0.70710678118;
const float inv_cos_45 = 0.29289321881;

vec4 in_Light3_Pos = vec4(-10.0, 20.0, 0.0, 1.0);
vec3 in_Light3_Size_Inner = vec3(12.0, 12.0, 12.0);
vec3 in_Light3_Size_Outer = vec3(10.0, 10.0, 10.0);
vec3 in_Light3_diffuse = vec3(0.4, 1.0, 0.4);
#endif

void main(void)
{
/* Material properties */
vec3 specular_reflect = vec3(0.8, 0.75, 0.4);
float specular_power = 60.0;

/* World properties */
vec3 ambient = vec3(0.7, 0.7, 0.7);
vec3 specular = vec3(0.0, 0.0, 0.0);
vec3 diffuse = vec3(0.0, 0.0, 0.0);

/* Light precalculations */
vec3 v = normalize(-pass_Vertex.xyz);

/* Apply lighting */
for (int i = 0; i < 8; i++)
{
vec4 pos = u_Lights[i * 2];
vec4 color = u_Lights[i * 2 + 1];
vec3 s, r;

if (pos.w > 0.0)
{
/* Point light -- no attenuation yet */
s = normalize((in_View * pos).xyz - pass_Vertex.xyz);
r = reflect(-s, pass_TNormal);
}
else
{
/* Directional light */
s = normalize(-pos.xyz);
r = reflect(s, pass_TNormal);
}

float sdotn = max(dot(s, pass_TNormal), 0.0);
diffuse += color.xyz * sdotn;
if (sdotn > 0.0)
specular += color.xyz * specular_reflect
* pow(max(dot(r, v), 0.0), specular_power);
}

#if 0
//Light calculation for cube light
//const float cos_45 = 0.70710678118;
//const float inv_cos_45 = 0.29289321881;
vec3 local_vertex = (in_Inv_View * pass_Vertex).xyz - (in_Light3_Pos).xyz;
vec3 proj_vertex = clamp(local_vertex.xyz, -in_Light3_Size_Inner, in_Light3_Size_Inner);
vec3 proj_local_dir = local_vertex - proj_vertex;
vec3 inner_dir = proj_vertex / in_Light3_Size_Inner;
inner_dir.x = (inner_dir.x == 1.0)?(1.0):(0.0);
inner_dir.y = (inner_dir.y == 1.0)?(1.0):(0.0);
inner_dir.z = (inner_dir.z == 1.0)?(1.0):(0.0);

//inside the cube
if (length(proj_local_dir) == 0.0)
{
sdotn = 1.0;
light_radius_mod = 1.0;
}
//spec calculation
else
{
//Distance calculation
vec3 proj_local_light = proj_local_dir / in_Light3_Size_Outer;
light_radius_mod = max(0.0, 1.0 - length(proj_local_light));
//cube orientation
sdotn = max(0.0, dot(normalize(proj_local_dir), normalize(inner_dir)));


//if (length(inner_dir) > 1.0)
// sdotn = 0.0;
//else
//{
// //vec3 proj_local_light = max(vec3(0.0,0.0,0.0), vec3(1.0,1.0,1.0) - abs(proj_local_dir / in_Light3_Size_Outer));
//}
/*
proj_local_dir = normalize((in_View * vec4(proj_vertex + in_Light3_Pos.xyz,1.0)).xyz - pass_Vertex.xyz);
sdotn = max(dot(proj_local_dir, pass_TNormal), 0.0);
r = reflect(-proj_local_dir, pass_TNormal);
if (sdotn > 0.0 && light_radius_mod > 0.0)
specular += specular_color * min(specular_reflect, light_radius_mod)
* pow(max(dot(r, v), 0.0), specular_power);
*/
}
//diffuse calculation
diffuse += in_Light3_diffuse * sdotn; //min(sdotn, light_radius_mod);
//----------
#endif

vec3 light = ambient + diffuse + specular;

vec4 real_color = mix(pass_Color, vec4(1.2, 1.2, 1.2, 1.0), in_Damage);
gl_FragColor = real_color * vec4(light, 1.0);
}

[vert.hlsl]

void main(float3 in_Vertex : POSITION,
float3 in_Normal : NORMAL,
float4 in_Color : COLOR,
uniform float4x4 in_ModelView,
uniform float4x4 in_Model,
uniform float4x4 in_Proj,
uniform float3x3 in_NormalMat,
out float4 pass_Vertex : TEXCOORD0,
out float3 pass_TNormal : TEXCOORD1,
out float4 pass_Color : COLOR,
out float4 out_Position : POSITION)
{
float4 eye = mul(in_ModelView, float4(in_Vertex, 1.0));
float3 tnorm = normalize(mul(in_NormalMat, in_Normal));

pass_Vertex = eye;
pass_TNormal = tnorm;
#ifdef _XBOX
pass_Color = in_Color.abgr;
#else
pass_Color = in_Color;
#endif

out_Position = mul(in_Proj, eye);
}

[frag.hlsl]

void main(float4 pass_Vertex : TEXCOORD0,
float3 pass_TNormal : TEXCOORD1,
float4 pass_Color : COLOR,
uniform float in_Damage,
out float4 out_FragColor : COLOR)
{
float3 in_LightDir = float3(0.3, 0.3, 0.7);

/* Material properties */
float3 specular_reflect = float3(0.8, 0.75, 0.4);
float specular_power = 60.0;

/* World properties */
float ambient_mul = 0.5;
float3 ambient_color = float3(0.25, 0.2, 0.35);
float3 diffuse_color = float3(1.0, 1.0, 0.6);
float3 specular_color = float3(1.0, 1.0, 0.6);

float3 s = normalize(in_LightDir); /* normalize(pass_Vertex - lightpos); */
float3 v = normalize(-pass_Vertex.xyz);
float3 r = reflect(-s, pass_TNormal);

float3 ambient = ambient_color;
float sdotn = max(dot(s, pass_TNormal), 0.0);
float3 diffuse = diffuse_color * sdotn;
float3 specular = float3(0.0, 0.0, 0.0);
if (sdotn > 0.0)
specular = specular_color * specular_reflect
* pow(max(dot(r, v), 0.0), specular_power);
float3 light = ambient + diffuse + specular;

float4 real_color = in_Damage * float4(1.2, 1.2, 1.2, 1.0)
+ (1.0 - in_Damage) * pass_Color;
out_FragColor = real_color * float4(light, 1.0);
}


+ 192
- 0
src/easymesh/shinydebugUV.lolfx 查看文件

@@ -0,0 +1,192 @@

[vert.glsl]
#version 120

attribute vec3 in_Vertex;
attribute vec3 in_Normal;
attribute vec4 in_Color;

uniform mat4 in_ModelView;
uniform mat4 in_View;
uniform mat4 in_Proj;
uniform mat3 in_NormalMat;

varying vec4 pass_Vertex; /* View space */
varying vec3 pass_TNormal;
varying vec4 pass_Color;

void main(void)
{
vec4 vertex = in_ModelView * vec4(in_Vertex, 1.0);
vec3 tnorm = normalize(in_NormalMat * in_Normal);

pass_Vertex = vertex;
pass_TNormal = tnorm;
pass_Color = in_Color;

gl_Position = in_Proj * vertex;
}

[frag.glsl]
#version 120

#if defined GL_ES
precision highp float;
#endif

uniform float in_Damage;
uniform mat4 in_View;
uniform mat4 in_Inv_View;

uniform vec4 u_Lights[8 * 2];

varying vec4 pass_Vertex; /* View space */
varying vec3 pass_TNormal;
varying vec4 pass_Color;

#if 0
//Cube Light
vec4 in_Light3_Pos = vec4(-10.0, 10.0, 5.0, 1.0);
vec3 in_Light3_Size_Inner = vec3(3.0, 1.0, 3.0);
vec3 in_Light3_Size_Outer = vec3(15.0, 15.0, 15.0);
vec3 in_Light3_diffuse = vec3(0.4, 1.0, 0.4);
#endif

void main(void)
{
/* Material properties */
vec3 specular_reflect = vec3(0.8, 0.75, 0.4);
float specular_power = 60.0;

/* World properties */
vec3 ambient = vec3(0.1, 0.1, 0.1);
vec3 specular = vec3(0.0, 0.0, 0.0);
vec3 diffuse = vec3(0.0, 0.0, 0.0);

/* Light precalculations */
vec3 v = normalize(-pass_Vertex.xyz);

/* Apply lighting */
for (int i = 0; i < 8; i++)
{
vec4 pos = u_Lights[i * 2];
vec4 color = u_Lights[i * 2 + 1];
vec3 s, r;

if (pos.w > 0.0)
{
/* Point light -- no attenuation yet */
s = normalize((in_View * pos).xyz - pass_Vertex.xyz);
r = reflect(-s, pass_TNormal);
}
else
{
/* Directional light */
s = normalize(-pos.xyz);
r = reflect(s, pass_TNormal);
}

float sdotn = max(dot(s, pass_TNormal), 0.0);
diffuse += color.xyz * sdotn;
if (sdotn > 0.0)
specular += color.xyz * specular_reflect
* pow(max(dot(r, v), 0.0), specular_power);
}

#if 0
//Light calculation for cube light
vec3 specular_color = vec3(1.0, 1.0, 0.6);
vec3 Local_Vertex = (in_Inv_View * pass_Vertex).xyz - (in_Light3_Pos).xyz;
vec3 Proj_Vertex = clamp(Local_Vertex.xyz, -in_Light3_Size_Inner, in_Light3_Size_Inner);
vec3 new_LightDir = Local_Vertex - Proj_Vertex;

vec3 light_radius = max(vec3(0.0,0.0,0.0), vec3(1.0,1.0,1.0) - abs(new_LightDir / in_Light3_Size_Outer));
float light_radius_mod = min(light_radius.x, min(light_radius.y, light_radius.z));

if (length(new_LightDir) == 0.0)
sdotn = 1.0;
else
{
new_LightDir = normalize((in_View * vec4(Proj_Vertex + in_Light3_Pos.xyz,1.0)).xyz - pass_Vertex.xyz);
sdotn = max(dot(new_LightDir, pass_TNormal), 0.0);
r = reflect(-new_LightDir, pass_TNormal);
if (sdotn > 0.0 && light_radius_mod > 0.0)
specular += specular_color * min(specular_reflect, light_radius_mod)
* pow(max(dot(r, v), 0.0), specular_power);
}
diffuse += in_Light3_diffuse * min(sdotn, light_radius_mod);
//----------
#endif

vec3 light = ambient + diffuse + specular;

vec4 real_color = mix(pass_Color, vec4(1.2, 1.2, 1.2, 1.0), in_Damage);
gl_FragColor = real_color * vec4(light, 1.0);
}

[vert.hlsl]

void main(float3 in_Vertex : POSITION,
float3 in_Normal : NORMAL,
float4 in_Color : COLOR,
uniform float4x4 in_ModelView,
uniform float4x4 in_Model,
uniform float4x4 in_Proj,
uniform float3x3 in_NormalMat,
out float4 pass_Vertex : TEXCOORD0,
out float3 pass_TNormal : TEXCOORD1,
out float4 pass_Color : COLOR,
out float4 out_Position : POSITION)
{
float4 eye = mul(in_ModelView, float4(in_Vertex, 1.0));
float3 tnorm = normalize(mul(in_NormalMat, in_Normal));

pass_Vertex = eye;
pass_TNormal = tnorm;
#ifdef _XBOX
pass_Color = in_Color.abgr;
#else
pass_Color = in_Color;
#endif

out_Position = mul(in_Proj, eye);
}

[frag.hlsl]

void main(float4 pass_Vertex : TEXCOORD0,
float3 pass_TNormal : TEXCOORD1,
float4 pass_Color : COLOR,
uniform float in_Damage,
out float4 out_FragColor : COLOR)
{
float3 in_LightDir = float3(0.3, 0.3, 0.7);

/* Material properties */
float3 specular_reflect = float3(0.8, 0.75, 0.4);
float specular_power = 60.0;

/* World properties */
float ambient_mul = 0.5;
float3 ambient_color = float3(0.25, 0.2, 0.35);
float3 diffuse_color = float3(1.0, 1.0, 0.6);
float3 specular_color = float3(1.0, 1.0, 0.6);

float3 s = normalize(in_LightDir); /* normalize(pass_Vertex - lightpos); */
float3 v = normalize(-pass_Vertex.xyz);
float3 r = reflect(-s, pass_TNormal);

float3 ambient = ambient_color;
float sdotn = max(dot(s, pass_TNormal), 0.0);
float3 diffuse = diffuse_color * sdotn;
float3 specular = float3(0.0, 0.0, 0.0);
if (sdotn > 0.0)
specular = specular_color * specular_reflect
* pow(max(dot(r, v), 0.0), specular_power);
float3 light = ambient + diffuse + specular;

float4 real_color = in_Damage * float4(1.2, 1.2, 1.2, 1.0)
+ (1.0 - in_Damage) * pass_Color;
out_FragColor = real_color * float4(light, 1.0);
}


+ 159
- 0
src/easymesh/shinydebuglighting.lolfx 查看文件

@@ -0,0 +1,159 @@

[vert.glsl]
#version 120

attribute vec3 in_Vertex;
attribute vec3 in_Normal;
attribute vec4 in_Color;

uniform mat4 in_ModelView;
uniform mat4 in_View;
uniform mat4 in_Proj;
uniform mat3 in_NormalMat;

varying vec4 pass_Vertex; /* View space */
varying vec3 pass_TNormal;
varying vec4 pass_Color;

void main(void)
{
vec4 vertex = in_ModelView * vec4(in_Vertex, 1.0);
vec3 tnorm = normalize(in_NormalMat * in_Normal);

pass_Vertex = vertex;
pass_TNormal = tnorm;
pass_Color = vec4(1.0, 1.0, 1.0, in_Color.w);//;

gl_Position = in_Proj * vertex;
}

[frag.glsl]
#version 120

#if defined GL_ES
precision highp float;
#endif

uniform float in_Damage;
uniform mat4 in_View;
uniform mat4 in_Inv_View;

uniform vec4 u_Lights[8 * 2];

varying vec4 pass_Vertex; /* View space */
varying vec3 pass_TNormal;
varying vec4 pass_Color;

void main(void)
{
/* Material properties */
vec3 specular_reflect = vec3(0.8, 0.75, 0.4);
float specular_power = 60.0;

/* World properties */
vec3 ambient = vec3(0.1, 0.1, 0.1);
vec3 specular = vec3(0.0, 0.0, 0.0);
vec3 diffuse = vec3(0.0, 0.0, 0.0);

/* Light precalculations */
vec3 v = normalize(-pass_Vertex.xyz);

/* Apply lighting */
for (int i = 0; i < 8; i++)
{
vec4 pos = u_Lights[i * 2];
vec4 color = u_Lights[i * 2 + 1];
vec3 s, r;

if (pos.w > 0.0)
{
/* Point light -- no attenuation yet */
s = normalize((in_View * pos).xyz - pass_Vertex.xyz);
r = reflect(-s, pass_TNormal);
}
else
{
/* Directional light */
s = normalize(-pos.xyz);
r = reflect(s, pass_TNormal);
}

float sdotn = max(dot(s, pass_TNormal), 0.0);
diffuse += color.xyz * sdotn;
if (sdotn > 0.0)
specular += color.xyz * specular_reflect
* pow(max(dot(r, v), 0.0), specular_power);
}

vec3 light = ambient + diffuse + specular;

//vec4 real_color = mix(pass_Color, vec4(1.0, 1.0, 1.0, 1.0), 1.0);
gl_FragColor = pass_Color * vec4(light, 1.0);
}

[vert.hlsl]

void main(float3 in_Vertex : POSITION,
float3 in_Normal : NORMAL,
float4 in_Color : COLOR,
uniform float4x4 in_ModelView,
uniform float4x4 in_Model,
uniform float4x4 in_Proj,
uniform float3x3 in_NormalMat,
out float4 pass_Vertex : TEXCOORD0,
out float3 pass_TNormal : TEXCOORD1,
out float4 pass_Color : COLOR,
out float4 out_Position : POSITION)
{
float4 eye = mul(in_ModelView, float4(in_Vertex, 1.0));
float3 tnorm = normalize(mul(in_NormalMat, in_Normal));

pass_Vertex = eye;
pass_TNormal = tnorm;
#ifdef _XBOX
pass_Color = in_Color.abgr;
#else
pass_Color = in_Color;
#endif

out_Position = mul(in_Proj, eye);
}

[frag.hlsl]

void main(float4 pass_Vertex : TEXCOORD0,
float3 pass_TNormal : TEXCOORD1,
float4 pass_Color : COLOR,
uniform float in_Damage,
out float4 out_FragColor : COLOR)
{
float3 in_LightDir = float3(0.3, 0.3, 0.7);

/* Material properties */
float3 specular_reflect = float3(0.8, 0.75, 0.4);
float specular_power = 60.0;

/* World properties */
float ambient_mul = 0.5;
float3 ambient_color = float3(0.25, 0.2, 0.35);
float3 diffuse_color = float3(1.0, 1.0, 0.6);
float3 specular_color = float3(1.0, 1.0, 0.6);

float3 s = normalize(in_LightDir); /* normalize(pass_Vertex - lightpos); */
float3 v = normalize(-pass_Vertex.xyz);
float3 r = reflect(-s, pass_TNormal);

float3 ambient = ambient_color;
float sdotn = max(dot(s, pass_TNormal), 0.0);
float3 diffuse = diffuse_color * sdotn;
float3 specular = float3(0.0, 0.0, 0.0);
if (sdotn > 0.0)
specular = specular_color * specular_reflect
* pow(max(dot(r, v), 0.0), specular_power);
float3 light = ambient + diffuse + specular;

float4 real_color = in_Damage * float4(1.2, 1.2, 1.2, 1.0)
+ (1.0 - in_Damage) * pass_Color;
out_FragColor = real_color * float4(light, 1.0);
}


+ 121
- 0
src/easymesh/shinydebugnormal.lolfx 查看文件

@@ -0,0 +1,121 @@

[vert.glsl]
#version 120

attribute vec3 in_Vertex;
attribute vec3 in_Normal;
attribute vec4 in_Color;

uniform mat4 in_ModelView;
uniform mat4 in_View;
uniform mat4 in_Proj;
uniform mat3 in_NormalMat;

varying vec4 pass_Vertex; /* View space */
varying vec3 pass_TNormal;
varying vec4 pass_Color;

void main(void)
{
vec4 vertex = in_ModelView * vec4(in_Vertex, 1.0);
vec3 tnorm = normalize(in_Normal);

pass_Vertex = vertex;
pass_TNormal = tnorm;
pass_Color = in_Color;

gl_Position = in_Proj * vertex;
}

[frag.glsl]
#version 120

#if defined GL_ES
precision highp float;
#endif

uniform float in_Damage;
uniform mat4 in_View;
uniform mat4 in_Inv_View;

uniform vec4 u_Lights[8 * 2];

varying vec4 pass_Vertex; /* View space */
varying vec3 pass_TNormal;
varying vec4 pass_Color;

void main(void)
{
vec3 real_color = vec3(0.0, 0.0, 0.0);
real_color += abs(pass_TNormal.x) * ((pass_TNormal.x < .0f)?(vec3(0.0, 1.0, 1.0)):(vec3(1.0, 0.0, 0.0)));
real_color += abs(pass_TNormal.y) * ((pass_TNormal.y < .0f)?(vec3(1.0, 0.0, 1.0)):(vec3(0.0, 1.0, 0.0)));
real_color += abs(pass_TNormal.z) * ((pass_TNormal.z < .0f)?(vec3(1.0, 1.0, 0.0)):(vec3(0.0, 0.0, 1.0)));
gl_FragColor = vec4(real_color, pass_Color.w);
}

[vert.hlsl]

void main(float3 in_Vertex : POSITION,
float3 in_Normal : NORMAL,
float4 in_Color : COLOR,
uniform float4x4 in_ModelView,
uniform float4x4 in_Model,
uniform float4x4 in_Proj,
uniform float3x3 in_NormalMat,
out float4 pass_Vertex : TEXCOORD0,
out float3 pass_TNormal : TEXCOORD1,
out float4 pass_Color : COLOR,
out float4 out_Position : POSITION)
{
float4 eye = mul(in_ModelView, float4(in_Vertex, 1.0));
float3 tnorm = normalize(mul(in_NormalMat, in_Normal));

pass_Vertex = eye;
pass_TNormal = tnorm;
#ifdef _XBOX
pass_Color = in_Color.abgr;
#else
pass_Color = in_Color;
#endif

out_Position = mul(in_Proj, eye);
}

[frag.hlsl]

void main(float4 pass_Vertex : TEXCOORD0,
float3 pass_TNormal : TEXCOORD1,
float4 pass_Color : COLOR,
uniform float in_Damage,
out float4 out_FragColor : COLOR)
{
float3 in_LightDir = float3(0.3, 0.3, 0.7);

/* Material properties */
float3 specular_reflect = float3(0.8, 0.75, 0.4);
float specular_power = 60.0;

/* World properties */
float ambient_mul = 0.5;
float3 ambient_color = float3(0.25, 0.2, 0.35);
float3 diffuse_color = float3(1.0, 1.0, 0.6);
float3 specular_color = float3(1.0, 1.0, 0.6);

float3 s = normalize(in_LightDir); /* normalize(pass_Vertex - lightpos); */
float3 v = normalize(-pass_Vertex.xyz);
float3 r = reflect(-s, pass_TNormal);

float3 ambient = ambient_color;
float sdotn = max(dot(s, pass_TNormal), 0.0);
float3 diffuse = diffuse_color * sdotn;
float3 specular = float3(0.0, 0.0, 0.0);
if (sdotn > 0.0)
specular = specular_color * specular_reflect
* pow(max(dot(r, v), 0.0), specular_power);
float3 light = ambient + diffuse + specular;

float4 real_color = in_Damage * float4(1.2, 1.2, 1.2, 1.0)
+ (1.0 - in_Damage) * pass_Color;
out_FragColor = real_color * float4(light, 1.0);
}


+ 117
- 0
src/easymesh/shinydebugwireframe.lolfx 查看文件

@@ -0,0 +1,117 @@

[vert.glsl]
#version 120

attribute vec3 in_Vertex;
attribute vec3 in_Normal;
attribute vec4 in_Color;

uniform mat4 in_ModelView;
uniform mat4 in_View;
uniform mat4 in_Proj;
uniform mat3 in_NormalMat;

varying vec4 pass_Vertex; /* View space */
varying vec3 pass_TNormal;
varying vec4 pass_Color;

void main(void)
{
vec4 vertex = in_ModelView * vec4(in_Vertex, 1.0);
vec3 tnorm = normalize(in_NormalMat * in_Normal);

pass_Vertex = vertex;
pass_TNormal = tnorm;
pass_Color = in_Color;

gl_Position = in_Proj * vertex;
}

[frag.glsl]
#version 120

#if defined GL_ES
precision highp float;
#endif

uniform float in_Damage;
uniform mat4 in_View;
uniform mat4 in_Inv_View;

uniform vec4 u_Lights[8 * 2];

varying vec4 pass_Vertex; /* View space */
varying vec3 pass_TNormal;
varying vec4 pass_Color;

void main(void)
{
gl_FragColor = pass_Color * length(normalize(pass_TNormal));
}

[vert.hlsl]

void main(float3 in_Vertex : POSITION,
float3 in_Normal : NORMAL,
float4 in_Color : COLOR,
uniform float4x4 in_ModelView,
uniform float4x4 in_Model,
uniform float4x4 in_Proj,
uniform float3x3 in_NormalMat,
out float4 pass_Vertex : TEXCOORD0,
out float3 pass_TNormal : TEXCOORD1,
out float4 pass_Color : COLOR,
out float4 out_Position : POSITION)
{
float4 eye = mul(in_ModelView, float4(in_Vertex, 1.0));
float3 tnorm = normalize(mul(in_NormalMat, in_Normal));

pass_Vertex = eye;
pass_TNormal = tnorm;
#ifdef _XBOX
pass_Color = in_Color.abgr;
#else
pass_Color = in_Color;
#endif

out_Position = mul(in_Proj, eye);
}

[frag.hlsl]

void main(float4 pass_Vertex : TEXCOORD0,
float3 pass_TNormal : TEXCOORD1,
float4 pass_Color : COLOR,
uniform float in_Damage,
out float4 out_FragColor : COLOR)
{
float3 in_LightDir = float3(0.3, 0.3, 0.7);

/* Material properties */
float3 specular_reflect = float3(0.8, 0.75, 0.4);
float specular_power = 60.0;

/* World properties */
float ambient_mul = 0.5;
float3 ambient_color = float3(0.25, 0.2, 0.35);
float3 diffuse_color = float3(1.0, 1.0, 0.6);
float3 specular_color = float3(1.0, 1.0, 0.6);

float3 s = normalize(in_LightDir); /* normalize(pass_Vertex - lightpos); */
float3 v = normalize(-pass_Vertex.xyz);
float3 r = reflect(-s, pass_TNormal);

float3 ambient = ambient_color;
float sdotn = max(dot(s, pass_TNormal), 0.0);
float3 diffuse = diffuse_color * sdotn;
float3 specular = float3(0.0, 0.0, 0.0);
if (sdotn > 0.0)
specular = specular_color * specular_reflect
* pow(max(dot(r, v), 0.0), specular_power);
float3 light = ambient + diffuse + specular;

float4 real_color = in_Damage * float4(1.2, 1.2, 1.2, 1.0)
+ (1.0 - in_Damage) * pass_Color;
out_FragColor = real_color * float4(light, 1.0);
}


+ 0
- 2
src/gpu/vertexbuffer.cpp 查看文件

@@ -158,7 +158,6 @@ void VertexDeclaration::DrawElements(MeshPrimitive type, int skip, int count)
#else
/* FIXME: this has nothing to do here! */
glFrontFace(GL_CCW);
glEnable(GL_CULL_FACE);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

@@ -222,7 +221,6 @@ void VertexDeclaration::DrawIndexedElements(MeshPrimitive type, int vbase,
#else
/* FIXME: this has nothing to do here! */
glFrontFace(GL_CCW);
glEnable(GL_CULL_FACE);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);



+ 6
- 1
src/lolcore.vcxproj 查看文件

@@ -642,6 +642,11 @@
</ItemGroup>
<ItemGroup>
<LolFxCompile Include="easymesh\shiny.lolfx" />
<LolFxCompile Include="easymesh\shinydebuglighting.lolfx" />
<LolFxCompile Include="easymesh\shinydebugnormal.lolfx" />
<LolFxCompile Include="easymesh\shinydebugUV.lolfx" />
<LolFxCompile Include="easymesh\shinydebugwireframe.lolfx" />
<LolFxCompile Include="easymesh\shiny_SK.lolfx" />
<LolFxCompile Include="gpu\defaultmaterial.lolfx" />
<LolFxCompile Include="gpu\emptymaterial.lolfx" />
<LolFxCompile Include="gpu\testmaterial.lolfx" />
@@ -658,4 +663,4 @@
<ImportGroup Label="ExtensionTargets">
<Import Project="$(SolutionDir)\Lol.Fx.targets" />
</ImportGroup>
</Project>
</Project>

+ 15
- 0
src/lolcore.vcxproj.filters 查看文件

@@ -1699,6 +1699,21 @@
<LolFxCompile Include="gpu\tile.lolfx">
<Filter>...</Filter>
</LolFxCompile>
<LolFxCompile Include="easymesh\shiny_SK.lolfx">
<Filter>easymesh</Filter>
</LolFxCompile>
<LolFxCompile Include="easymesh\shinydebuglighting.lolfx">
<Filter>easymesh</Filter>
</LolFxCompile>
<LolFxCompile Include="easymesh\shinydebugnormal.lolfx">
<Filter>easymesh</Filter>
</LolFxCompile>
<LolFxCompile Include="easymesh\shinydebugUV.lolfx">
<Filter>easymesh</Filter>
</LolFxCompile>
<LolFxCompile Include="easymesh\shinydebugwireframe.lolfx">
<Filter>easymesh</Filter>
</LolFxCompile>
</ItemGroup>
<ItemGroup>
<None Include="easymesh\easymesh-parser.y">


+ 57
- 0
src/video.cpp 查看文件

@@ -51,6 +51,7 @@ class VideoData
private:
static mat4 proj_matrix;
static ivec2 saved_viewport;
static DebugRenderMode render_mode;
#if defined USE_D3D9 || defined _XBOX
# if defined USE_D3D9
static IDirect3D9 *d3d_ctx;
@@ -66,6 +67,7 @@ private:

mat4 VideoData::proj_matrix;
ivec2 VideoData::saved_viewport(0, 0);
DebugRenderMode VideoData::render_mode = DebugRenderMode::Default;

#if defined USE_D3D9 || defined _XBOX
# if defined USE_D3D9
@@ -153,6 +155,7 @@ void Video::Setup(ivec2 size)
/* Initialise reasonable scene default properties */
SetClearColor(vec4(0.1f, 0.2f, 0.3f, 1.0f));
SetClearDepth(1.f);
SetDebugRenderMode(DebugRenderMode::Default);
}

void Video::SetFov(float theta)
@@ -232,6 +235,60 @@ void Video::SetClearDepth(float f)
#endif
}

void Video::SetDebugRenderMode(DebugRenderMode d)
{
if (d == DebugRenderMode::Max)
return;

switch(d)
{
//All these modes are handled in the shaders.
case DebugRenderMode::Default:
case DebugRenderMode::Lighting:
case DebugRenderMode::Normal:
case DebugRenderMode::UV:
{
#if defined USE_D3D9 || defined _XBOX
#else
glEnable(GL_CULL_FACE);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
#endif
break;
}
case DebugRenderMode::Wireframe:
{
if (VideoData::render_mode == DebugRenderMode::Wireframe)
{
#if defined USE_D3D9 || defined _XBOX
#else
if (glIsEnabled(GL_CULL_FACE) == GL_TRUE)
glDisable(GL_CULL_FACE);
else
glEnable(GL_CULL_FACE);
#endif
}
else
{
#if defined USE_D3D9 || defined _XBOX
#else
glDisable(GL_CULL_FACE);
#endif
}
#if defined USE_D3D9 || defined _XBOX
#else
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
#endif
break;
}
}
VideoData::render_mode = d;
}

DebugRenderMode Video::GetDebugRenderMode()
{
return VideoData::render_mode;
}

void Video::Clear(ClearMask m)
{
#if defined USE_D3D9 || defined _XBOX


+ 21
- 0
src/video.h 查看文件

@@ -41,6 +41,25 @@ struct ClearMask
inline operator Value() { return m_value; }
};

struct DebugRenderMode
{
enum Value
{
//Add your new rendermode at your convenience
Default,
Wireframe,
Lighting,
Normal,
UV,

Max
}
m_value;

inline DebugRenderMode(Value v) : m_value(v) {}
inline operator Value() { return m_value; }
};

class Video
{
public:
@@ -50,6 +69,8 @@ public:
static void SetDepth(bool set);
static void SetClearColor(vec4 color);
static void SetClearDepth(float f);
static void SetDebugRenderMode(DebugRenderMode d);
static DebugRenderMode GetDebugRenderMode();
static void Clear(ClearMask m);
static void Capture(uint32_t *buffer);
static ivec2 GetSize();


+ 23
- 6
test/MeshViewer.cpp 查看文件

@@ -50,10 +50,10 @@ public:
{
//FOV compensation doesn't work
ivec2 video_size = Video::GetSize();
float near = -video_size.x - video_size.y;
float far = video_size.x + video_size.y;
float near = (float)-video_size.x - video_size.y;
float far = (float)video_size.x + video_size.y;
float t1 = tanf(new_fov / 2);
float dist = video_size.x / (2.0f * t1);
float dist = (float)video_size.x / (2.0f * t1);
//m_fov_compensation = mat4::translate(-0.5f * video_size.x, -0.5f * video_size.y, -dist);
m_fov_compensation = mat4::translate(vec3(.0f));
if (new_fov > 0.1f)
@@ -156,9 +156,12 @@ public:
{
WorldEntity::TickGame(seconds);

//Shutdown logic
if (Input::WasReleased(Key::Escape))
Ticker::Shutdown();
//TODO : This should probably be "standard LoL behaviour"
{
//Shutdown logic
if (Input::WasReleased(Key::Escape))
Ticker::Shutdown();
}

//Update Mesh BBox - Get the Min/Max needed
vec3 min_max[2] = { vec3(FLT_MAX), vec3(-FLT_MAX) };
@@ -283,6 +286,20 @@ public:
{
WorldEntity::TickDraw(seconds);

//TODO : This should probably be "standard LoL behaviour"
{
if (Input::WasReleased(Key::F1))
Video::SetDebugRenderMode(DebugRenderMode::Default);
if (Input::WasReleased(Key::F2))
Video::SetDebugRenderMode(DebugRenderMode::Wireframe);
if (Input::WasReleased(Key::F3))
Video::SetDebugRenderMode(DebugRenderMode::Lighting);
if (Input::WasReleased(Key::F4))
Video::SetDebugRenderMode(DebugRenderMode::Normal);
if (Input::WasReleased(Key::F5))
Video::SetDebugRenderMode(DebugRenderMode::UV);
}

for (int i = 0; i < m_meshes.Count(); i++)
{
if (!m_meshes[i].m2)


正在加载...
取消
保存