浏览代码

MeshViewer : Added shitty texture to bulletproof easymesh UV, and therefore correct wrongly set ones.

legacy
Benjamin ‘Touky’ Huet touky 12 年前
父节点
当前提交
a573b0908b
共有 10 个文件被更改,包括 255 次插入36 次删除
  1. +24
    -3
      build/vs2010/Lol.sln
  2. +18
    -19
      src/easymesh/easymesh.cpp
  3. +1
    -1
      src/easymesh/easymesh.h
  4. +5
    -0
      src/tileset.cpp
  5. +1
    -0
      src/tileset.h
  6. +27
    -1
      test/MeshViewer.cpp
  7. +2
    -1
      test/MeshViewer.vcxproj
  8. +13
    -11
      test/MeshViewerBuffer.txt
  9. 二进制
      test/data/MeshViewerTestTexture.png
  10. +164
    -0
      test/shinyMVTexture.lolfx

+ 24
- 3
build/vs2010/Lol.sln 查看文件

@@ -128,6 +128,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "benlitzTest1", "..\..\peopl
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MeshViewer", "..\..\test\MeshViewer.vcxproj", "{7CE9FE12-E4AB-4A22-90D4-2C15F0C30D4E}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Tactics", "..\..\people\touky\private\Tactics\Tactics.vcxproj", "{25493FC8-75AC-4703-AD57-AB0C2A0FB79C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -648,9 +650,9 @@ Global
{58922993-9830-4A40-B462-0326342F69ED}.Release|x64.Build.0 = Release|Any CPU
{58922993-9830-4A40-B462-0326342F69ED}.Release|Xbox 360.ActiveCfg = Release|Any CPU
{834852DB-EDB6-4FD0-BCF9-45CD01126962}.Debug|Any CPU.ActiveCfg = Debug|Xbox 360
{834852DB-EDB6-4FD0-BCF9-45CD01126962}.Debug|Mixed Platforms.ActiveCfg = Debug|Xbox 360
{834852DB-EDB6-4FD0-BCF9-45CD01126962}.Debug|Mixed Platforms.Build.0 = Debug|Xbox 360
{834852DB-EDB6-4FD0-BCF9-45CD01126962}.Debug|Mixed Platforms.Deploy.0 = Debug|Xbox 360
{834852DB-EDB6-4FD0-BCF9-45CD01126962}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{834852DB-EDB6-4FD0-BCF9-45CD01126962}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{834852DB-EDB6-4FD0-BCF9-45CD01126962}.Debug|Mixed Platforms.Deploy.0 = Debug|Win32
{834852DB-EDB6-4FD0-BCF9-45CD01126962}.Debug|PS3.ActiveCfg = Debug|PS3
{834852DB-EDB6-4FD0-BCF9-45CD01126962}.Debug|PS3.Build.0 = Debug|PS3
{834852DB-EDB6-4FD0-BCF9-45CD01126962}.Debug|Win32.ActiveCfg = Debug|Win32
@@ -709,6 +711,24 @@ Global
{7CE9FE12-E4AB-4A22-90D4-2C15F0C30D4E}.Release|x64.ActiveCfg = Release|x64
{7CE9FE12-E4AB-4A22-90D4-2C15F0C30D4E}.Release|x64.Build.0 = Release|x64
{7CE9FE12-E4AB-4A22-90D4-2C15F0C30D4E}.Release|Xbox 360.ActiveCfg = Release|x64
{25493FC8-75AC-4703-AD57-AB0C2A0FB79C}.Debug|Any CPU.ActiveCfg = Debug|x64
{25493FC8-75AC-4703-AD57-AB0C2A0FB79C}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{25493FC8-75AC-4703-AD57-AB0C2A0FB79C}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{25493FC8-75AC-4703-AD57-AB0C2A0FB79C}.Debug|PS3.ActiveCfg = Debug|x64
{25493FC8-75AC-4703-AD57-AB0C2A0FB79C}.Debug|Win32.ActiveCfg = Debug|Win32
{25493FC8-75AC-4703-AD57-AB0C2A0FB79C}.Debug|Win32.Build.0 = Debug|Win32
{25493FC8-75AC-4703-AD57-AB0C2A0FB79C}.Debug|x64.ActiveCfg = Debug|x64
{25493FC8-75AC-4703-AD57-AB0C2A0FB79C}.Debug|x64.Build.0 = Debug|x64
{25493FC8-75AC-4703-AD57-AB0C2A0FB79C}.Debug|Xbox 360.ActiveCfg = Debug|x64
{25493FC8-75AC-4703-AD57-AB0C2A0FB79C}.Release|Any CPU.ActiveCfg = Release|x64
{25493FC8-75AC-4703-AD57-AB0C2A0FB79C}.Release|Mixed Platforms.ActiveCfg = Release|x64
{25493FC8-75AC-4703-AD57-AB0C2A0FB79C}.Release|Mixed Platforms.Build.0 = Release|x64
{25493FC8-75AC-4703-AD57-AB0C2A0FB79C}.Release|PS3.ActiveCfg = Release|x64
{25493FC8-75AC-4703-AD57-AB0C2A0FB79C}.Release|Win32.ActiveCfg = Release|Win32
{25493FC8-75AC-4703-AD57-AB0C2A0FB79C}.Release|Win32.Build.0 = Release|Win32
{25493FC8-75AC-4703-AD57-AB0C2A0FB79C}.Release|x64.ActiveCfg = Release|x64
{25493FC8-75AC-4703-AD57-AB0C2A0FB79C}.Release|x64.Build.0 = Release|x64
{25493FC8-75AC-4703-AD57-AB0C2A0FB79C}.Release|Xbox 360.ActiveCfg = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -745,6 +765,7 @@ Global
{9CC50C06-DF5E-41A7-AD90-04F05386E081} = {3D341D8A-E400-4B1D-BC05-B5C35487D9B5}
{587FCCE9-1D8D-4398-B8B6-E8F4E9A92233} = {B357514A-7881-422D-8358-161B689E7620}
{EE203B88-44CF-4859-9D42-7A5F43FECB52} = {9EA99B18-D352-47F6-BC04-A0B49CAA2772}
{25493FC8-75AC-4703-AD57-AB0C2A0FB79C} = {9EA99B18-D352-47F6-BC04-A0B49CAA2772}
{A69411B3-6DE8-404E-8E70-0D3375A7492A} = {0A1651FC-322B-4B04-82CB-28E9046D9383}
{5A77DCDD-2CBA-43E9-8B45-00C281443F77} = {0A1651FC-322B-4B04-82CB-28E9046D9383}
{C2E01551-B636-4324-8461-71811DF6FBB5} = {E27FDF36-50C4-4ED2-8CF5-A20FED016910}


+ 18
- 19
src/easymesh/easymesh.cpp 查看文件

@@ -1150,13 +1150,13 @@ void EasyMesh::AppendCylinder(int nsides, float h, float d1, float d2,
//LOWER DISC
SetTexCoordData(vec2(.0f, .5f), vec2(.5f, .5f));
SetCurColor(m_color);
AppendDisc(nsides, r1);
AppendDisc(nsides, d1);
Translate(vec3(.0f, h, .0f));
RotateX(180.0f);
//UPPER DISC
SetTexCoordData(vec2(.5f, .5f), vec2(.5f, .5f));
SetCurColor(m_color2);
AppendDisc(nsides, r2);
AppendDisc(nsides, d2);
Translate(vec3(.0f, h * .5f, .0f));
CloseBrace();
}
@@ -1293,11 +1293,12 @@ void EasyMesh::AppendCapsule(int ndivisions, float h, float d)
{
int rid[] = { id[k + l], id[(k + 1) % 3 + l], id[(k + 2) % 3 + l] };
AddVertex(p[rid[0]]);
vec2 new_uv;
if (uv[rid[0]].x < .0f)
SetCurVertTexCoord(vec2((uv[rid[1]].x + uv[rid[2]].x) * .5f,
uv[rid[0]].y));
new_uv = vec2((uv[rid[1]].x + uv[rid[2]].x) * .5f, uv[rid[0]].y);
else
SetCurVertTexCoord(uv[rid[0]]);
new_uv = uv[rid[0]];
SetCurVertTexCoord(vec2(0.f, 1.f) - new_uv);
}
AppendTriangle(0, 2, 1, m_vert.Count() - 3);
}
@@ -1431,19 +1432,19 @@ void EasyMesh::AppendBox(vec3 const &size, float chamf, bool smooth)

//Bottom vertices
AddVertex(vec3(-d.x, -d.y - chamf, +d.z));
SetCurVertTexCoord(vec2(0.f, 1.f));
SetCurVertTexCoord(vec2(.5f, 1.f));
AddVertex(vec3(-d.x, -d.y - chamf, -d.z));
SetCurVertTexCoord(vec2(0.f, .5f));
AddVertex(vec3(+d.x, -d.y - chamf, -d.z));
SetCurVertTexCoord(vec2(.5f, .5f));
AddVertex(vec3(+d.x, -d.y - chamf, -d.z));
SetCurVertTexCoord(vec2(.0f, .5f));
AddVertex(vec3(+d.x, -d.y - chamf, +d.z));
SetCurVertTexCoord(vec2(.5f, 1.f));
SetCurVertTexCoord(vec2(.0f, 1.f));

//Top vertices
AddVertex(vec3(-d.x, +d.y + chamf, -d.z));
SetCurVertTexCoord(vec2(0.f, 1.f));
SetCurVertTexCoord(vec2(1.f, 1.f));
AddVertex(vec3(-d.x, +d.y + chamf, +d.z));
SetCurVertTexCoord(vec2(0.f, .5f));
SetCurVertTexCoord(vec2(1.f, .5f));
AddVertex(vec3(+d.x, +d.y + chamf, +d.z));
SetCurVertTexCoord(vec2(.5f, .5f));
AddVertex(vec3(+d.x, +d.y + chamf, -d.z));
@@ -1621,11 +1622,11 @@ void EasyMesh::AppendSimpleTriangle(float d, int fade)

AddVertex(p); SetCurVertTexCoord(vec2(.5f, 0.133975f));
p = m * p;
AddVertex(p); SetCurVertTexCoord(vec2(1.f, 1.f));
AddVertex(p); SetCurVertTexCoord(vec2(0.f, 1.f));
if (fade)
SetCurVertColor(m_color2);
p = m * p;
AddVertex(p); SetCurVertTexCoord(vec2(0.f, 1.f));
AddVertex(p); SetCurVertTexCoord(vec2(1.f, 1.f));
if (fade)
SetCurVertColor(m_color2);

@@ -1641,14 +1642,12 @@ void EasyMesh::AppendSimpleQuad(float size, int fade)
//-----------------------------------------------------------------------------
void EasyMesh::AppendSimpleQuad(vec2 p1, vec2 p2, float z, int fade)
{
AddVertex(vec3(p2.x, z, -p1.y)); SetCurVertTexCoord(vec2(0.f, 1.f));
AddVertex(vec3(p2.x, z, -p1.y)); SetCurVertTexCoord(vec2(1.f, 0.f));
AddVertex(vec3(p2.x, z, -p2.y)); SetCurVertTexCoord(vec2(0.f, 0.f));
AddVertex(vec3(p1.x, z, -p2.y)); SetCurVertTexCoord(vec2(1.f, 0.f));
if (fade)
SetCurVertColor(m_color2);
AddVertex(vec3(p1.x, z, -p2.y)); SetCurVertTexCoord(vec2(0.f, 1.f));
if (fade) SetCurVertColor(m_color2);
AddVertex(vec3(p1.x, z, -p1.y)); SetCurVertTexCoord(vec2(1.f, 1.f));
if (fade)
SetCurVertColor(m_color2);
if (fade) SetCurVertColor(m_color2);

AppendQuad(0, 1, 2, 3, m_vert.Count() - 4);
ComputeNormals(m_indices.Count() - 6, 6);


+ 1
- 1
src/easymesh/easymesh.h 查看文件

@@ -19,7 +19,7 @@
#define VU_TEX_UV 1
#define VU_VANILLA 0

#define VERTEX_USEAGE VU_VANILLA
#define VERTEX_USEAGE VU_TEX_UV

#if !defined __EASYMESH_EASYMESH_H__
#define __EASYMESH_EASYMESH_H__


+ 5
- 0
src/tileset.cpp 查看文件

@@ -174,6 +174,11 @@ ivec2 TileSet::GetSize(int tileid) const
return data->size;
}

ShaderTexture TileSet::GetTexture() const
{
return data->m_texture->GetTexture();
}

void TileSet::Bind()
{
if (!data->img && data->m_texture)


+ 1
- 0
src/tileset.h 查看文件

@@ -43,6 +43,7 @@ public:
/* New methods */
ivec2 GetCount() const;
ivec2 GetSize(int tileid) const;
ShaderTexture GetTexture() const;
void Bind();
void Unbind();
void BlitTile(uint32_t id, vec3 pos, int o, vec2 scale,


+ 27
- 1
test/MeshViewer.cpp 查看文件

@@ -21,7 +21,10 @@
using namespace std;
using namespace lol;

static int const TEXTURE_WIDTH = 256;

LOLFX_RESOURCE_DECLARE(shinyfur);
LOLFX_RESOURCE_DECLARE(shinyMVTexture);

#define IPT_CAM_RESET "Cam_Center"
#define IPT_CAM_FORWARD "Cam_Forward"
@@ -95,6 +98,7 @@ public:
Input::LinkActionToKey(IPT_MESH_ROT_DOWN, Key::KP5);

m_angle = 0;
DefaultTexture = NULL;

//Camera Setup
m_fov_zoom_damp = .0f;
@@ -325,6 +329,22 @@ public:
Video::SetDebugRenderMode(DebugRenderMode::UV);
}

if (!DefaultTexture)
{
m_texture_shader = Shader::Create(LOLFX_RESOURCE_NAME(shinyMVTexture));
m_texture_uni = m_texture_shader->GetUniformLocation("u_Texture");
//m_image = new Image("data/MeshViewerTestTexture.png");
DefaultTexture = Tiler::Register("data/MeshViewerTestTexture.png", ivec2(0), ivec2(0,1));

//ivec2 size = m_image->GetSize();
//// m_image->GetFormat()
//m_texture = new Texture(m_image->GetSize(), PixelFormat::ABGR_8);
//m_texture->SetData(m_image->GetData());
// PixelFormat::ABGR_8
}
else if (m_texture && DefaultTexture)
m_texture_shader->SetUniform(m_texture_uni, DefaultTexture->GetTexture(), 0);

for (int i = 0; i < m_meshes.Count(); i++)
{
if (!m_meshes[i].m2)
@@ -333,7 +353,8 @@ public:
#if WITH_FUR
m_meshes[i].m1.MeshConvert(Shader::Create(LOLFX_RESOURCE_NAME(shinyfur)));
#else
m_meshes[i].m1.MeshConvert();
m_meshes[i].m1.MeshConvert(m_texture_shader);
//m_meshes[i].m1.MeshConvert();
#endif
m_meshes[i].m2 = true;
}
@@ -401,6 +422,11 @@ private:
Array<EasyMesh, bool, float, vec3> m_meshes;
Array<Light *> m_lights;
Camera * m_camera;
Shader * m_texture_shader;
TileSet * DefaultTexture;
Texture * m_texture;
ShaderUniform m_texture_uni;
Image * m_image;
float m_fov;
float m_fov_damp;
float m_fov_zoom_damp;


+ 2
- 1
test/MeshViewer.vcxproj 查看文件

@@ -52,6 +52,7 @@
</ItemGroup>
<ItemGroup>
<LolFxCompile Include="shinyfur.lolfx" />
<LolFxCompile Include="shinyMVTexture.lolfx" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{7CE9FE12-E4AB-4A22-90D4-2C15F0C30D4E}</ProjectGuid>
@@ -73,4 +74,4 @@
<ImportGroup Label="ExtensionTargets">
<Import Project="$(SolutionDir)\Lol.Fx.targets" />
</ImportGroup>
</Project>
</Project>

+ 13
- 11
test/MeshViewerBuffer.txt 查看文件

@@ -1,20 +1,22 @@
[sc#88f ab 4 4 4 smth 3 1 1 ]//twy 45 0 bdxy 90 0 splt 5 tz 2
[sc#fff scb#fff ato 20 8 12 rx0]
[sc#fff scb#fff acg 8 2 5 1 6 8 4 2 .1 1]
//[sc#fff ab 4 4 4 smth 0 1 1 ]//twy 45 0 bdxy 90 0 splt 5 tz 2
//[sc#88f ab 4 4 4 tx 4 ab 4 4 4 tx -2 tax .4 .4 0]
//[sc#88f ab .25 1 1 tx .25 ab .25 1 1 tx .25 ab .25 1 1 tx .25 ab .25 1 1 tx .125 stx 10 0 0]
//[sc#ff2 scb#2ff acg 13 2 1 1 8 8 4 4 0 1 tax -2 0 0 0]
// tax -2 0 0 0
//[sc#88f ab 4 4 4 tx 4 ab 4 4 4 tx -2 shz 1 0 0 0]
//[sc#ff2 asph 4 4 shx 0 0 0 0]
//[sc#fff asph 4 4]
//[sc#ff2 asph 4 4 tax .4 .4 0]
//[sc#ff2 asph 2 4]
//[sc#ff2 acap 1 4 4]
//[sc#ff2 scb#ff2 ac 10 4 4 4 0 0 1]
//[sc#fff acap 1 4 4]
//[sc#fff scb#fff ac 10 4 4 4 0 0 1]
//[sc#ff2 scb#ff2 ad 10 4 0]
//[sc#ff2 scb#ff2 ato 40 1 4]
//[sc#ff2 scb#2ff at 4 1]
//[sc#ff2 scb#2ff aq 4 0]
//[sc#ff2 scb#2ff aes 5 3 6 2]
//[sc#ff2 scb#2ff as 4 2 4 0 0]
//[sc#ff2 scb#2ff acg 2 10 .1 .1 .4 .4 .1 .1 0 1]
//[sc#fff scb#fff at 4 1]
//[sc#fff scb#000 aq 4 1]
//[sc#fff scb#2ff aes 5 3 6 2]
//[sc#fff scb#2ff as 4 2 4 0 0]
//[sc#fff scb#fff acg 2 10 .1 .1 .4 .4 .1 .1 0 1]
//[sc#ff2 asph 2 10 10 10]
//[sc#400 asph 2 10 10 10 t 2 2 2 csgs]


二进制
test/data/MeshViewerTestTexture.png 查看文件

之前 之后
宽度: 256  |  高度: 256  |  大小: 2.3 KiB

+ 164
- 0
test/shinyMVTexture.lolfx 查看文件

@@ -0,0 +1,164 @@

[vert.glsl]
#version 120

attribute vec3 in_Vertex;
attribute vec3 in_Normal;
attribute vec4 in_Color;
attribute vec2 in_TexCoord;

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;
varying vec2 pass_TexCoord;

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;
pass_TexCoord = in_TexCoord;

gl_Position = in_Proj * vertex;
}

[frag.glsl]
#version 120

#if defined GL_ES
precision highp float;
#endif

uniform mat4 in_View;
uniform mat4 in_Inv_View;
uniform mat4 in_Inv_ModelView;
uniform sampler2D u_Texture;

//Light list
uniform vec4 u_Lights[8 * 2];

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

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);
}

vec3 light = ambient + diffuse + specular;

gl_FragColor = texture2D(u_Texture, pass_TexCoord.xy) * pass_Color * vec4(light, 1.0f);
}

[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);
}


||||||
x
 
000:0
正在加载...
取消
保存