mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 19:19:56 +00:00
vertex colors
This commit is contained in:
parent
9bd888d9a1
commit
8e683c2e05
4 changed files with 36 additions and 6 deletions
|
@ -226,7 +226,7 @@ void NIFLoader::createMaterial(const String &name,
|
||||||
const Vector &emissive,
|
const Vector &emissive,
|
||||||
float glossiness, float alpha,
|
float glossiness, float alpha,
|
||||||
int alphaFlags, float alphaTest,
|
int alphaFlags, float alphaTest,
|
||||||
const String &texName)
|
const String &texName, bool vertexColor)
|
||||||
{
|
{
|
||||||
if (texName.empty())
|
if (texName.empty())
|
||||||
return;
|
return;
|
||||||
|
@ -246,6 +246,9 @@ void NIFLoader::createMaterial(const String &name,
|
||||||
|
|
||||||
instance->setProperty ("diffuseMap", sh::makeProperty(texName));
|
instance->setProperty ("diffuseMap", sh::makeProperty(texName));
|
||||||
|
|
||||||
|
if (vertexColor)
|
||||||
|
instance->setProperty ("has_vertex_colour", sh::makeProperty<sh::BooleanValue>(new sh::BooleanValue(true)));
|
||||||
|
|
||||||
// Add transparency if NiAlphaProperty was present
|
// Add transparency if NiAlphaProperty was present
|
||||||
if (alphaFlags != -1)
|
if (alphaFlags != -1)
|
||||||
{
|
{
|
||||||
|
@ -272,7 +275,6 @@ void NIFLoader::createMaterial(const String &name,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if (!texName.empty())
|
if (!texName.empty())
|
||||||
{
|
{
|
||||||
|
@ -668,6 +670,8 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou
|
||||||
NiTexturingProperty *t = NULL;
|
NiTexturingProperty *t = NULL;
|
||||||
NiMaterialProperty *m = NULL;
|
NiMaterialProperty *m = NULL;
|
||||||
NiAlphaProperty *a = NULL;
|
NiAlphaProperty *a = NULL;
|
||||||
|
// can't make any sense of these values, so ignoring them for now
|
||||||
|
//NiVertexColorProperty *v = NULL;
|
||||||
|
|
||||||
// Scan the property list for material information
|
// Scan the property list for material information
|
||||||
PropertyList &list = shape->props;
|
PropertyList &list = shape->props;
|
||||||
|
@ -685,6 +689,8 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou
|
||||||
m = static_cast<NiMaterialProperty*>(pr);
|
m = static_cast<NiMaterialProperty*>(pr);
|
||||||
else if (pr->recType == RC_NiAlphaProperty)
|
else if (pr->recType == RC_NiAlphaProperty)
|
||||||
a = static_cast<NiAlphaProperty*>(pr);
|
a = static_cast<NiAlphaProperty*>(pr);
|
||||||
|
//else if (pr->recType == RC_NiVertexColorProperty)
|
||||||
|
//v = static_cast<NiVertexColorProperty*>(pr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Texture
|
// Texture
|
||||||
|
@ -755,7 +761,7 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou
|
||||||
{
|
{
|
||||||
//std::cout << "new";
|
//std::cout << "new";
|
||||||
createMaterial(material, d->ambient, d->diffuse, d->specular, d->emissive,
|
createMaterial(material, d->ambient, d->diffuse, d->specular, d->emissive,
|
||||||
d->glossiness, d->alpha, alphaFlags, alphaTest, texName);
|
d->glossiness, d->alpha, alphaFlags, alphaTest, texName, shape->data->colors.length != 0);
|
||||||
MaterialMap.insert(std::make_pair(texName,material));
|
MaterialMap.insert(std::make_pair(texName,material));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -771,7 +777,7 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou
|
||||||
}
|
}
|
||||||
|
|
||||||
createMaterial(material, one, one, zero, zero, 0.0, 1.0,
|
createMaterial(material, one, one, zero, zero, 0.0, 1.0,
|
||||||
alphaFlags, alphaTest, texName);
|
alphaFlags, alphaTest, texName, shape->data->colors.length != 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // End of material block, if(!hidden) ...
|
} // End of material block, if(!hidden) ...
|
||||||
|
|
|
@ -142,7 +142,8 @@ class NIFLoader : Ogre::ManualResourceLoader
|
||||||
const Nif::Vector &emissive,
|
const Nif::Vector &emissive,
|
||||||
float glossiness, float alpha,
|
float glossiness, float alpha,
|
||||||
int alphaFlags, float alphaTest,
|
int alphaFlags, float alphaTest,
|
||||||
const Ogre::String &texName);
|
const Ogre::String &texName,
|
||||||
|
bool vertexColor);
|
||||||
|
|
||||||
void findRealTexture(Ogre::String &texName);
|
void findRealTexture(Ogre::String &texName);
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
#define shOutput(type, name) , out type name : TEXCOORD@shCounter(2)
|
#define shOutput(type, name) , out type name : TEXCOORD@shCounter(2)
|
||||||
|
|
||||||
#define shNormalInput(type) , in type normal : NORMAL
|
#define shNormalInput(type) , in type normal : NORMAL
|
||||||
|
|
||||||
|
#define shColourInput(type) , in type colour : COLOR
|
||||||
|
|
||||||
#ifdef SH_VERTEX_SHADER
|
#ifdef SH_VERTEX_SHADER
|
||||||
|
|
||||||
|
@ -40,7 +42,7 @@
|
||||||
|
|
||||||
#define SH_BEGIN_PROGRAM \
|
#define SH_BEGIN_PROGRAM \
|
||||||
void main( \
|
void main( \
|
||||||
out float4 oColor : COLOR
|
out float4 oColor0 : COLOR
|
||||||
|
|
||||||
#define SH_START_PROGRAM \
|
#define SH_START_PROGRAM \
|
||||||
) \
|
) \
|
||||||
|
@ -69,7 +71,9 @@
|
||||||
|
|
||||||
#define shMatrixMult(m, v) m * v
|
#define shMatrixMult(m, v) m * v
|
||||||
|
|
||||||
|
// automatically recognized by ogre when the input name equals this
|
||||||
#define shInputPosition vertex
|
#define shInputPosition vertex
|
||||||
|
|
||||||
#define shOutputPosition gl_Position
|
#define shOutputPosition gl_Position
|
||||||
#define shOutputColor(num) oColor##num
|
#define shOutputColor(num) oColor##num
|
||||||
|
|
||||||
|
@ -78,7 +82,9 @@
|
||||||
#define shInput(type, name) in type name;
|
#define shInput(type, name) in type name;
|
||||||
#define shOutput(type, name) out type name;
|
#define shOutput(type, name) out type name;
|
||||||
|
|
||||||
|
// automatically recognized by ogre when the input name equals this
|
||||||
#define shNormalInput(type) in type normal;
|
#define shNormalInput(type) in type normal;
|
||||||
|
#define shColourInput(type) in type colour;
|
||||||
|
|
||||||
#ifdef SH_VERTEX_SHADER
|
#ifdef SH_VERTEX_SHADER
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
#define NEED_DEPTH
|
#define NEED_DEPTH
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define HAS_VERTEXCOLOR @shPropertyBool(has_vertex_colour)
|
||||||
|
|
||||||
#ifdef SH_VERTEX_SHADER
|
#ifdef SH_VERTEX_SHADER
|
||||||
|
|
||||||
SH_BEGIN_PROGRAM
|
SH_BEGIN_PROGRAM
|
||||||
|
@ -22,6 +24,10 @@
|
||||||
shOutput(float4, normalPassthrough)
|
shOutput(float4, normalPassthrough)
|
||||||
#ifdef NEED_DEPTH
|
#ifdef NEED_DEPTH
|
||||||
shOutput(float, depthPassthrough)
|
shOutput(float, depthPassthrough)
|
||||||
|
#endif
|
||||||
|
#if HAS_VERTEXCOLOR
|
||||||
|
shColourInput(float4)
|
||||||
|
shOutput(float4, colorPassthrough)
|
||||||
#endif
|
#endif
|
||||||
SH_START_PROGRAM
|
SH_START_PROGRAM
|
||||||
{
|
{
|
||||||
|
@ -31,6 +37,10 @@
|
||||||
#ifdef NEED_DEPTH
|
#ifdef NEED_DEPTH
|
||||||
depthPassthrough = shOutputPosition.z;
|
depthPassthrough = shOutputPosition.z;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if HAS_VERTEXCOLOR
|
||||||
|
colorPassthrough = colour;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
@ -50,13 +60,20 @@
|
||||||
#if FOG
|
#if FOG
|
||||||
shUniform(float3 fogColor) @shAutoConstant(fogColor, fog_colour)
|
shUniform(float3 fogColor) @shAutoConstant(fogColor, fog_colour)
|
||||||
shUniform(float4 fogParams) @shAutoConstant(fogParams, fog_params)
|
shUniform(float4 fogParams) @shAutoConstant(fogParams, fog_params)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAS_VERTEXCOLOR
|
||||||
|
shInput(float4, colorPassthrough)
|
||||||
#endif
|
#endif
|
||||||
SH_START_PROGRAM
|
SH_START_PROGRAM
|
||||||
{
|
{
|
||||||
//shOutputColor(0) = float4((normalize(normalPassthrough.xyz)+float3(1.0,1.0,1.0)) / 2.f, 1.0);
|
//shOutputColor(0) = float4((normalize(normalPassthrough.xyz)+float3(1.0,1.0,1.0)) / 2.f, 1.0);
|
||||||
shOutputColor(0) = shSample(diffuseMap, UV);
|
shOutputColor(0) = shSample(diffuseMap, UV);
|
||||||
|
|
||||||
|
#if HAS_VERTEXCOLOR
|
||||||
|
shOutputColor(0).xyz *= colorPassthrough.xyz;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if FOG
|
#if FOG
|
||||||
float fogValue = shSaturate((depthPassthrough - fogParams.y) * fogParams.w);
|
float fogValue = shSaturate((depthPassthrough - fogParams.y) * fogParams.w);
|
||||||
shOutputColor(0).xyz = shLerp (shOutputColor(0).xyz, fogColor, fogValue);
|
shOutputColor(0).xyz = shLerp (shOutputColor(0).xyz, fogColor, fogValue);
|
||||||
|
|
Loading…
Reference in a new issue