Skip to content

Commit

Permalink
Fixes #8 by implementing render groups 32 and 33
Browse files Browse the repository at this point in the history
Apparently I had support for emission groups for way longer now.
  • Loading branch information
cochrane committed Feb 2, 2013
1 parent 29964b4 commit 6fc530d
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 2 deletions.
4 changes: 4 additions & 0 deletions GLLara.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
523DE12D1604E10D00BB9F61 /* thailand_mirror_statue_left.modelparams.plist in Resources */ = {isa = PBXBuildFile; fileRef = 523DE12B1604E10C00BB9F61 /* thailand_mirror_statue_left.modelparams.plist */; };
523DE12E1604E10D00BB9F61 /* thailand_mirror_statue_right.modelparams.plist in Resources */ = {isa = PBXBuildFile; fileRef = 523DE12C1604E10D00BB9F61 /* thailand_mirror_statue_right.modelparams.plist */; };
52421C1316BDAD5500D41EAA /* GLLModelMeshV3.m in Sources */ = {isa = PBXBuildFile; fileRef = 52421C1216BDAD5500D41EAA /* GLLModelMeshV3.m */; };
52421C1516BDB78100D41EAA /* DiffuseSpecular.fs in Resources */ = {isa = PBXBuildFile; fileRef = 52421C1416BDB78100D41EAA /* DiffuseSpecular.fs */; };
52423AF41604EB35009F5753 /* panther_thrall.modelparams.plist in Resources */ = {isa = PBXBuildFile; fileRef = 52423AE91604EB35009F5753 /* panther_thrall.modelparams.plist */; };
52423AF51604EB35009F5753 /* panther.modelparams.plist in Resources */ = {isa = PBXBuildFile; fileRef = 52423AEA1604EB35009F5753 /* panther.modelparams.plist */; };
52423AF61604EB35009F5753 /* poacher.modelparams.plist in Resources */ = {isa = PBXBuildFile; fileRef = 52423AEB1604EB35009F5753 /* poacher.modelparams.plist */; };
Expand Down Expand Up @@ -378,6 +379,7 @@
52421C0F16BDA65B00D41EAA /* GLLSceneModel 3.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = file; path = "GLLSceneModel 3.xcdatamodel"; sourceTree = "<group>"; };
52421C1116BDAD5500D41EAA /* GLLModelMeshV3.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GLLModelMeshV3.h; sourceTree = "<group>"; };
52421C1216BDAD5500D41EAA /* GLLModelMeshV3.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GLLModelMeshV3.m; sourceTree = "<group>"; };
52421C1416BDB78100D41EAA /* DiffuseSpecular.fs */ = {isa = PBXFileReference; explicitFileType = sourcecode.glsl; fileEncoding = 4; path = DiffuseSpecular.fs; sourceTree = "<group>"; };
52423AE91604EB35009F5753 /* panther_thrall.modelparams.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = panther_thrall.modelparams.plist; sourceTree = "<group>"; };
52423AEA1604EB35009F5753 /* panther.modelparams.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = panther.modelparams.plist; sourceTree = "<group>"; };
52423AEB1604EB35009F5753 /* poacher.modelparams.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = poacher.modelparams.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1109,6 +1111,7 @@
5275F6C11607E19C00978779 /* TexturelessOBJ.fs */,
522C4BF9160932BF0043FCBA /* DiffuseSpecularNormalOBJ.fs */,
52629397163DDB6500AC1088 /* DiffuseBumpEmission.fs */,
52421C1416BDB78100D41EAA /* DiffuseSpecular.fs */,
);
path = Shaders;
sourceTree = "<group>";
Expand Down Expand Up @@ -1426,6 +1429,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
52421C1516BDB78100D41EAA /* DiffuseSpecular.fs in Resources */,
5275F6C21607E19C00978779 /* TexturelessOBJ.fs in Resources */,
522C4BFB1609331D0043FCBA /* DiffuseSpecularNormalOBJ.fs in Resources */,
521326391602B19700787AA1 /* Square.fs in Resources */,
Expand Down
27 changes: 27 additions & 0 deletions GLLara/Model Parameters/xnaLaraDefault.modelparams.plist
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,33 @@
</dict>
<key>shaders</key>
<dict>
<key>DiffuseSpecular</key>
<dict>
<key>additionalParameters</key>
<array>
<string>bumpSpecularGloss</string>
</array>
<key>parameters</key>
<array>
<string>bumpSpecularAmount</string>
</array>
<key>textures</key>
<array>
<string>diffuseTexture</string>
</array>
<key>alphaMeshGroups</key>
<array>
<string>MeshGroup33</string>
</array>
<key>solidMeshGroups</key>
<array>
<string>MeshGroup32</string>
</array>
<key>fragment</key>
<string>DiffuseSpecular.fs</string>
<key>vertex</key>
<string>Basic.vs</string>
</dict>
<key>StaticTRLShadeless</key>
<dict>
<key>textures</key>
Expand Down
10 changes: 8 additions & 2 deletions GLLara/Shaders/Basic.vs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ in vec4 boneWeights;

out vec4 outColor;
out vec2 outTexCoord;
out vec3 positionWorld;
out vec3 normalWorld;

mat4 boneTransform()
Expand All @@ -34,9 +35,14 @@ mat4 boneTransform()

void main()
{
// Transform
// Transformation
mat4 bone = boneTransform();
gl_Position = transform.viewProjection * bone * vec4(position, 1.0);
gl_Position = transform.viewProjection * (bone * vec4(position, 1.0));

// Relative to world
positionWorld = vec3(bone * vec4(position, 1.0));

// Normal
normalWorld = mat3(bone) * normal;

// Pass through
Expand Down
67 changes: 67 additions & 0 deletions GLLara/Shaders/DiffuseSpecular.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Diffuse with specular. Arguably what should have been the default from the
* beginning, but XPS implemented it only recently. It's a copy of DiffuseBump
* that does not use a bump map.
*/
#version 150

in vec4 outColor;
in vec2 outTexCoord;
in vec3 positionWorld;
in vec3 normalWorld;

out vec4 screenColor;

uniform sampler2D diffuseTexture;

struct Light {
vec4 diffuseColor;
vec4 specularColor;
vec4 direction;
};

layout(std140) uniform LightData {
vec4 cameraPosition;
vec4 ambientColor;
Light lights[3];
} lightData;

uniform RenderParameters {
float bumpSpecularGloss;
float bumpSpecularAmount;
} parameters;

layout(std140) uniform AlphaTest {
uint mode; // 0 - none, 1 - pass if greater than, 2 - pass if less than.
float reference;
} alphaTest;

void main()
{
// Find diffuse texture and do alpha test.
vec4 diffuseTexColor = texture(diffuseTexture, outTexCoord);
if ((alphaTest.mode == 1U && diffuseTexColor.a <= alphaTest.reference) || (alphaTest.mode == 2U && diffuseTexColor.a >= alphaTest.reference))
discard;

// Base diffuse color
vec4 diffuseColor = diffuseTexColor * outColor;

// Direction to camera
vec3 cameraDirection = normalize(lightData.cameraPosition.xyz - positionWorld);

vec4 color = lightData.ambientColor * diffuseColor;
for (int i = 0; i < 3; i++)
{
// Diffuse term
float diffuseFactor = max(dot(-normalWorld, lightData.lights[i].direction.xyz), 0);
color += diffuseTexColor * lightData.lights[i].diffuseColor * diffuseFactor;

// Specular term
vec3 reflectedLightDirection = reflect(lightData.lights[i].direction.xyz, normalWorld);
float specularFactor = pow(max(dot(cameraDirection, reflectedLightDirection), 0), parameters.bumpSpecularGloss) * parameters.bumpSpecularAmount;
color += lightData.lights[i].specularColor * specularFactor;
}

float alpha = alphaTest.mode == 0U ? 1.0 : diffuseTexColor.a;
screenColor = vec4(color.rgb, alpha);
}

0 comments on commit 6fc530d

Please sign in to comment.