/cocos3d/cocos3d/Shaders/CC3ShaderSemantics.m
Objective C | 1739 lines | 1405 code | 180 blank | 154 comment | 74 complexity | cdf98d8faeea0cf87577a72ea094f72b MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- /*
- * CC3ShaderSemantics.m
- *
- * cocos3d 2.0.0
- * Author: Bill Hollings
- * Copyright (c) 2011-2014 The Brenwill Workshop Ltd. All rights reserved.
- * http://www.brenwill.com
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * http://en.wikipedia.org/wiki/MIT_License
- *
- * See header file CC3ShaderSemantics.h for full API documentation.
- */
- #import "CC3ShaderSemantics.h"
- #import "CC3GLSLVariable.h"
- #import "CC3NodeVisitor.h"
- #import "CC3MeshNode.h"
- #import "CC3Camera.h"
- #import "CC3Light.h"
- #import "CC3Scene.h"
- #import "CC3PointParticles.h"
- #import "CC3NodeAnimation.h"
- #import "CC3VertexSkinning.h"
- #import "CC3OpenGL.h"
- NSString* NSStringFromCC3Semantic(CC3Semantic semantic) {
- switch (semantic) {
- case kCC3SemanticNone: return @"kCC3SemanticNone";
- // VERTEX CONTENT --------------
- case kCC3SemanticVertexLocation: return @"kCC3SemanticVertexLocation";
- case kCC3SemanticVertexNormal: return @"kCC3SemanticVertexNormal";
- case kCC3SemanticVertexTangent: return @"kCC3SemanticVertexTangent";
- case kCC3SemanticVertexBitangent: return @"kCC3SemanticVertexBitangent";
- case kCC3SemanticVertexColor: return @"kCC3SemanticVertexColor";
- case kCC3SemanticVertexPointSize: return @"kCC3SemanticVertexPointSize";
- case kCC3SemanticVertexBoneWeights: return @"kCC3SemanticVertexBoneWeights";
- case kCC3SemanticVertexBoneIndices: return @"kCC3SemanticVertexBoneIndices";
- case kCC3SemanticVertexTexture: return @"kCC3SemanticVertexTexture";
-
- case kCC3SemanticHasVertexNormal: return @"kCC3SemanticHasVertexNormal";
- case kCC3SemanticShouldNormalizeVertexNormal: return @"kCC3SemanticShouldNormalizeVertexNormal";
- case kCC3SemanticShouldRescaleVertexNormal: return @"kCC3SemanticShouldRescaleVertexNormal";
- case kCC3SemanticHasVertexTangent: return @"kCC3SemanticHasVertexTangent";
- case kCC3SemanticHasVertexBitangent: return @"kCC3SemanticHasVertexBitangent";
- case kCC3SemanticHasVertexColor: return @"kCC3SemanticHasVertexColor";
- case kCC3SemanticHasVertexWeight: return @"kCC3SemanticHasVertexWeight";
- case kCC3SemanticHasVertexMatrixIndex: return @"kCC3SemanticHasVertexMatrixIndex";
- case kCC3SemanticHasVertexTextureCoordinate: return @"kCC3SemanticHasVertexTextureCoordinate";
- case kCC3SemanticHasVertexPointSize: return @"kCC3SemanticHasVertexPointSize";
- case kCC3SemanticIsDrawingPoints: return @"kCC3SemanticIsDrawingPoints";
- case kCC3SemanticShouldDrawFrontFaces: return @"kCC3SemanticShouldDrawFrontFaces";
- case kCC3SemanticShouldDrawBackFaces: return @"kCC3SemanticShouldDrawBackFaces";
- // ENVIRONMENT MATRICES --------------
- case kCC3SemanticModelLocalMatrix: return @"kCC3SemanticModelLocalMatrix";
- case kCC3SemanticModelLocalMatrixInv: return @"kCC3SemanticModelLocalMatrixInv";
- case kCC3SemanticModelLocalMatrixInvTran: return @"kCC3SemanticModelLocalMatrixInvTran";
- case kCC3SemanticModelMatrix: return @"kCC3SemanticModelMatrix";
- case kCC3SemanticModelMatrixInv: return @"kCC3SemanticModelMatrixInv";
- case kCC3SemanticModelMatrixInvTran: return @"kCC3SemanticModelMatrixInvTran";
- case kCC3SemanticViewMatrix: return @"kCC3SemanticViewMatrix";
- case kCC3SemanticViewMatrixInv: return @"kCC3SemanticViewMatrixInv";
- case kCC3SemanticViewMatrixInvTran: return @"kCC3SemanticViewMatrixInvTran";
- case kCC3SemanticModelViewMatrix: return @"kCC3SemanticModelViewMatrix";
- case kCC3SemanticModelViewMatrixInv: return @"kCC3SemanticModelViewMatrixInv";
- case kCC3SemanticModelViewMatrixInvTran: return @"kCC3SemanticModelViewMatrixInvTran";
- case kCC3SemanticProjMatrix: return @"kCC3SemanticProjMatrix";
- case kCC3SemanticProjMatrixInv: return @"kCC3SemanticProjMatrixInv";
- case kCC3SemanticProjMatrixInvTran: return @"kCC3SemanticProjMatrixInvTran";
- case kCC3SemanticViewProjMatrix: return @"kCC3SemanticViewProjMatrix";
- case kCC3SemanticViewProjMatrixInv: return @"kCC3SemanticViewProjMatrixInv";
- case kCC3SemanticViewProjMatrixInvTran: return @"kCC3SemanticViewProjMatrixInvTran";
- case kCC3SemanticModelViewProjMatrix: return @"kCC3SemanticModelViewProjMatrix";
- case kCC3SemanticModelViewProjMatrixInv: return @"kCC3SemanticModelViewProjMatrixInv";
- case kCC3SemanticModelViewProjMatrixInvTran: return @"kCC3SemanticModelViewProjMatrixInvTran";
-
- // CAMERA -----------------
- case kCC3SemanticCameraLocationModelSpace: return @"kCC3SemanticCameraLocationModelSpace";
- case kCC3SemanticCameraLocationGlobal: return @"kCC3SemanticCameraLocationGlobal";
- case kCC3SemanticCameraFrustum: return @"kCC3SemanticCameraFrustum";
- case kCC3SemanticCameraFrustumDepth: return @"kCC3SemanticCameraFrustumDepth";
-
- // MATERIALS --------------
- case kCC3SemanticColor: return @"kCC3SemanticColor";
- case kCC3SemanticMaterialColorAmbient: return @"kCC3SemanticMaterialColorAmbient";
- case kCC3SemanticMaterialColorDiffuse: return @"kCC3SemanticMaterialColorDiffuse";
- case kCC3SemanticMaterialColorSpecular: return @"kCC3SemanticMaterialColorSpecular";
- case kCC3SemanticMaterialColorEmission: return @"kCC3SemanticMaterialColorEmission";
- case kCC3SemanticMaterialOpacity: return @"kCC3SemanticMaterialOpacity";
- case kCC3SemanticMaterialShininess: return @"kCC3SemanticMaterialShininess";
- case kCC3SemanticMaterialReflectivity: return @"kCC3SemanticMaterialReflectivity";
- // LIGHTING --------------
- case kCC3SemanticIsUsingLighting: return @"kCC3SemanticIsUsingLighting";
- case kCC3SemanticSceneLightColorAmbient: return @"kCC3SemanticSceneLightColorAmbient";
- case kCC3SemanticLightIsEnabled: return @"kCC3SemanticLightIsEnabled";
- case kCC3SemanticLightPositionGlobal: return @"kCC3SemanticLightPositionGlobal";
- case kCC3SemanticLightPositionEyeSpace: return @"kCC3SemanticLightPositionEyeSpace";
- case kCC3SemanticLightPositionModelSpace: return @"kCC3SemanticLightPositionModelSpace";
- case kCC3SemanticLightInvertedPositionGlobal: return @"kCC3SemanticLightInvertedPositionGlobal";
- case kCC3SemanticLightInvertedPositionEyeSpace: return @"kCC3SemanticLightInvertedPositionEyeSpace";
- case kCC3SemanticLightInvertedPositionModelSpace: return @"kCC3SemanticLightInvertedPositionModelSpace";
- case kCC3SemanticLightColorAmbient: return @"kCC3SemanticLightColorAmbient";
- case kCC3SemanticLightColorDiffuse: return @"kCC3SemanticLightColorDiffuse";
- case kCC3SemanticLightColorSpecular: return @"kCC3SemanticLightColorSpecular";
- case kCC3SemanticLightAttenuation: return @"kCC3SemanticLightAttenuation";
- case kCC3SemanticLightSpotDirectionGlobal: return @"kCC3SemanticLightSpotDirectionGlobal";
- case kCC3SemanticLightSpotDirectionEyeSpace: return @"kCC3SemanticLightSpotDirectionEyeSpace";
- case kCC3SemanticLightSpotDirectionModelSpace: return @"kCC3SemanticLightSpotDirectionModelSpace";
- case kCC3SemanticLightSpotExponent: return @"kCC3SemanticLightSpotExponent";
- case kCC3SemanticLightSpotCutoffAngle: return @"kCC3SemanticLightSpotCutoffAngle";
- case kCC3SemanticLightSpotCutoffAngleCosine: return @"kCC3SemanticLightSpotCutoffAngleCosine";
- case kCC3SemanticFogIsEnabled: return @"kCC3SemanticFogIsEnabled";
- case kCC3SemanticFogColor: return @"kCC3SemanticFogColor";
- case kCC3SemanticFogAttenuationMode: return @"kCC3SemanticFogAttenuationMode";
- case kCC3SemanticFogDensity: return @"kCC3SemanticFogDensity";
- case kCC3SemanticFogStartDistance: return @"kCC3SemanticFogStartDistance";
- case kCC3SemanticFogEndDistance: return @"kCC3SemanticFogEndDistance";
-
- // TEXTURES --------------
- case kCC3SemanticTextureCount: return @"kCC3SemanticTextureCount";
- case kCC3SemanticTextureSampler: return @"kCC3SemanticTextureSampler";
- case kCC3SemanticTexture2DCount: return @"kCC3SemanticTexture2DCount";
- case kCC3SemanticTexture2DSampler: return @"kCC3SemanticTexture2DSampler";
- case kCC3SemanticTextureCubeCount: return @"kCC3SemanticTextureCubeCount";
- case kCC3SemanticTextureCubeSampler: return @"kCC3SemanticTextureCubeSampler";
- case kCC3SemanticTexUnitMode: return @"kCC3SemanticTexUnitMode";
- case kCC3SemanticTexUnitConstantColor: return @"kCC3SemanticTexUnitConstantColor";
- case kCC3SemanticTexUnitCombineRGBFunction: return @"kCC3SemanticTexUnitCombineRGBFunction";
- case kCC3SemanticTexUnitSource0RGB: return @"kCC3SemanticTexUnitSource0RGB";
- case kCC3SemanticTexUnitSource1RGB: return @"kCC3SemanticTexUnitSource1RGB";
- case kCC3SemanticTexUnitSource2RGB: return @"kCC3SemanticTexUnitSource2RGB";
- case kCC3SemanticTexUnitOperand0RGB: return @"kCC3SemanticTexUnitOperand0RGB";
- case kCC3SemanticTexUnitOperand1RGB: return @"kCC3SemanticTexUnitOperand1RGB";
- case kCC3SemanticTexUnitOperand2RGB: return @"kCC3SemanticTexUnitOperand2RGB";
- case kCC3SemanticTexUnitCombineAlphaFunction: return @"kCC3SemanticTexUnitCombineAlphaFunction";
- case kCC3SemanticTexUnitSource0Alpha: return @"kCC3SemanticTexUnitSource0Alpha";
- case kCC3SemanticTexUnitSource1Alpha: return @"kCC3SemanticTexUnitSource1Alpha";
- case kCC3SemanticTexUnitSource2Alpha: return @"kCC3SemanticTexUnitSource2Alpha";
- case kCC3SemanticTexUnitOperand0Alpha: return @"kCC3SemanticTexUnitOperand0Alpha";
- case kCC3SemanticTexUnitOperand1Alpha: return @"kCC3SemanticTexUnitOperand1Alpha";
- case kCC3SemanticTexUnitOperand2Alpha: return @"kCC3SemanticTexUnitOperand2Alpha";
-
- // MODEL ----------------
- case kCC3SemanticAnimationFraction: return @"kCC3SemanticAnimationFraction";
- case kCC3SemanticCenterOfGeometry: return @"kCC3SemanticCenterOfGeometry";
- case kCC3SemanticBoundingBoxMin: return @"kCC3SemanticBoundingBoxMin";
- case kCC3SemanticBoundingBoxMax: return @"kCC3SemanticBoundingBoxMax";
- case kCC3SemanticBoundingBoxSize: return @"kCC3SemanticBoundingBoxSize";
- case kCC3SemanticBoundingRadius: return @"kCC3SemanticBoundingRadius";
-
- // BONE SKINNING
- case kCC3SemanticVertexBoneCount: return @"kCC3SemanticVertexBoneCount";
- case kCC3SemanticBatchBoneCount: return @"kCC3SemanticBatchBoneCount";
- // BONE SKINNING MATRICES
- case kCC3SemanticBoneMatricesGlobal: return @"kCC3SemanticBoneMatricesGlobal";
- case kCC3SemanticBoneMatricesInvTranGlobal: return @"kCC3SemanticBoneMatricesInvTranGlobal";
- case kCC3SemanticBoneMatricesEyeSpace: return @"kCC3SemanticBoneMatricesEyeSpace";
- case kCC3SemanticBoneMatricesInvTranEyeSpace: return @"kCC3SemanticBoneMatricesInvTranEyeSpace";
- case kCC3SemanticBoneMatricesModelSpace: return @"kCC3SemanticBoneMatricesModelSpace";
- case kCC3SemanticBoneMatricesInvTranModelSpace: return @"kCC3SemanticBoneMatricesInvTranModelSpace";
- // BONE SKINNING DISCRETE TRANSFORMS
- case kCC3SemanticBoneQuaternionsGlobal: return @"kCC3SemanticBoneQuaternionsGlobal";
- case kCC3SemanticBoneTranslationsGlobal: return @"kCC3SemanticBoneTranslationsGlobal";
- case kCC3SemanticBoneScalesGlobal: return @"kCC3SemanticBoneScalesGlobal";
- case kCC3SemanticBoneQuaternionsEyeSpace: return @"kCC3SemanticBoneQuaternionsEyeSpace";
- case kCC3SemanticBoneTranslationsEyeSpace: return @"kCC3SemanticBoneTranslationsEyeSpace";
- case kCC3SemanticBoneScalesEyeSpace: return @"kCC3SemanticBoneScalesEyeSpace";
- case kCC3SemanticBoneQuaternionsModelSpace: return @"kCC3SemanticBoneQuaternionsModelSpace";
- case kCC3SemanticBoneTranslationsModelSpace: return @"kCC3SemanticBoneTranslationsModelSpace";
- case kCC3SemanticBoneScalesModelSpace: return @"kCC3SemanticBoneScalesModelSpace";
-
- // PARTICLES ------------
- case kCC3SemanticPointSize: return @"kCC3SemanticPointSize";
- case kCC3SemanticPointSizeAttenuation: return @"kCC3SemanticPointSizeAttenuation";
- case kCC3SemanticPointSizeMinimum: return @"kCC3SemanticPointSizeMinimum";
- case kCC3SemanticPointSizeMaximum: return @"kCC3SemanticPointSizeMaximum";
- case kCC3SemanticPointSpritesIsEnabled: return @"kCC3SemanticPointSpritesIsEnabled";
-
- // TIME ------------------
- case kCC3SemanticFrameTime: return @"kCC3SemanticFrameTime";
-
- case kCC3SemanticSceneTime: return @"kCC3SemanticSceneTime";
- case kCC3SemanticSceneTimeSine: return @"kCC3SemanticSceneTimeSine";
- case kCC3SemanticSceneTimeCosine: return @"kCC3SemanticSceneTimeCosine";
- case kCC3SemanticSceneTimeTangent: return @"kCC3SemanticSceneTimeTangent";
- // MISC ENVIRONMENT ---------
- case kCC3SemanticViewport: return @"kCC3SemanticViewport";
- case kCC3SemanticDrawCountCurrentFrame: return @"kCC3SemanticDrawCountCurrentFrame";
- case kCC3SemanticRandomNumber: return @"kCC3SemanticRandomNumber";
-
- case kCC3SemanticAppBase: return @"kCC3SemanticAppBase";
- case kCC3SemanticMax: return @"kCC3SemanticMax";
- default: return [NSString stringWithFormat: @"Unknown state semantic (%u)", semantic];
- }
- }
- #pragma mark -
- #pragma mark CC3GLSLVariableConfiguration
- @implementation CC3GLSLVariableConfiguration
- @synthesize name=_name, semantic=_semantic, semanticIndex=_semanticIndex;
- -(void) dealloc {
- [_name release];
- [super dealloc];
- }
- -(id) init {
- if ( (self = [super init]) ) {
- _name = nil;
- _semantic = kCC3SemanticNone;
- _semanticIndex = 0;
- }
- return self;
- }
- @end
- #pragma mark -
- #pragma mark CC3ShaderSemanticsBase
- @implementation CC3ShaderSemanticsBase
- +(id) semanticsDelegate { return [[[self alloc] init] autorelease]; }
- -(NSString*) nameOfSemantic: (GLenum) semantic { return NSStringFromCC3Semantic(semantic); }
- -(BOOL) configureVariable: (CC3GLSLVariable*) variable { return NO; }
- /**
- * Returns a variable scope derived from the specified semantic.
- *
- * Subclasses that permit application-specific semantics should override this method to
- * handle those additional semantics if they should not default to kCC3GLSLVariableScopeNode.
- */
- -(CC3GLSLVariableScope) variableScopeForSemantic: (GLenum) semantic {
- switch (semantic) {
- // Draw scope semantics
- case kCC3SemanticDrawCountCurrentFrame:
- case kCC3SemanticRandomNumber:
- case kCC3SemanticBatchBoneCount:
- case kCC3SemanticBoneMatricesGlobal:
- case kCC3SemanticBoneMatricesInvTranGlobal:
- case kCC3SemanticBoneMatricesEyeSpace:
- case kCC3SemanticBoneMatricesInvTranEyeSpace:
- case kCC3SemanticBoneMatricesModelSpace:
- case kCC3SemanticBoneMatricesInvTranModelSpace:
- case kCC3SemanticBoneQuaternionsGlobal:
- case kCC3SemanticBoneTranslationsGlobal:
- case kCC3SemanticBoneScalesGlobal:
- case kCC3SemanticBoneQuaternionsEyeSpace:
- case kCC3SemanticBoneTranslationsEyeSpace:
- case kCC3SemanticBoneScalesEyeSpace:
- case kCC3SemanticBoneQuaternionsModelSpace:
- case kCC3SemanticBoneTranslationsModelSpace:
- case kCC3SemanticBoneScalesModelSpace:
-
- return kCC3GLSLVariableScopeDraw;
-
- // Scene scope semantics
-
- case kCC3SemanticViewMatrix:
- case kCC3SemanticViewMatrixInv:
- case kCC3SemanticViewMatrixInvTran:
- case kCC3SemanticProjMatrix:
- case kCC3SemanticProjMatrixInv:
- case kCC3SemanticProjMatrixInvTran:
- case kCC3SemanticViewProjMatrix:
- case kCC3SemanticViewProjMatrixInv:
- case kCC3SemanticViewProjMatrixInvTran:
-
- case kCC3SemanticCameraLocationGlobal:
- case kCC3SemanticCameraFrustum:
- case kCC3SemanticCameraFrustumDepth:
- case kCC3SemanticViewport:
- case kCC3SemanticSceneLightColorAmbient:
- case kCC3SemanticLightIsEnabled:
- case kCC3SemanticLightPositionGlobal:
- case kCC3SemanticLightPositionEyeSpace:
- case kCC3SemanticLightInvertedPositionGlobal:
- case kCC3SemanticLightInvertedPositionEyeSpace:
- case kCC3SemanticLightColorAmbient:
- case kCC3SemanticLightColorDiffuse:
- case kCC3SemanticLightColorSpecular:
- case kCC3SemanticLightAttenuation:
- case kCC3SemanticLightSpotDirectionGlobal:
- case kCC3SemanticLightSpotDirectionEyeSpace:
- case kCC3SemanticLightSpotExponent:
- case kCC3SemanticLightSpotCutoffAngle:
- case kCC3SemanticLightSpotCutoffAngleCosine:
- case kCC3SemanticFogIsEnabled:
- case kCC3SemanticFogColor:
- case kCC3SemanticFogAttenuationMode:
- case kCC3SemanticFogDensity:
- case kCC3SemanticFogStartDistance:
- case kCC3SemanticFogEndDistance:
-
- case kCC3SemanticFrameTime:
- case kCC3SemanticSceneTime:
- case kCC3SemanticSceneTimeSine:
- case kCC3SemanticSceneTimeCosine:
- case kCC3SemanticSceneTimeTangent:
-
- return kCC3GLSLVariableScopeScene;
-
-
- // Node scope semantics
- default:
- return kCC3GLSLVariableScopeNode;
- }
- }
- /**
- * For semantics that may have more than one target, such as components of lights, or textures,
- * the iteration loops in this method are designed to deal with two situations:
- * - If the uniform is declared as an array of single types (eg- an array of floats, bools, or
- * vec3's), the uniform semantic index will be zero and the uniform size will be larger than one.
- * - If the uniform is declared as a scalar (eg- distinct uniforms for each light, etc), the
- * uniform size will be one, but the uniform semantic index can be larger than zero.
- */
- -(BOOL) populateUniform: (CC3GLSLUniform*) uniform withVisitor: (CC3NodeDrawingVisitor*) visitor {
- LogTrace(@"%@ drawing %@ retrieving semantic value for %@", self, visitor.currentNode, uniform.fullDescription);
- GLenum semantic = uniform.semantic;
- GLuint semanticIndex = uniform.semanticIndex;
- GLint uniformSize = uniform.size;
-
- CC3Material* mat;
- CC3SkinSection* skin;
- CC3PointParticleEmitter* emitter;
- CC3Matrix4x4 m4x4;
- CC3Matrix4x3 m4x3, mRslt4x3, tfmMtx, *pm4x3;
- CC3Matrix3x3 m3x3;
- CC3Viewport vp;
- CCTime sceneTime;
- GLuint boneCnt = 0, tuCnt = 0, texCnt = 0;
- BOOL isInverted = NO, isPtEmitter = NO;
-
- switch (semantic) {
-
- #pragma mark Setting attribute semantics
- // ATTRIBUTE QUALIFIERS --------------
- case kCC3SemanticHasVertexNormal:
- [uniform setBoolean: visitor.currentMesh.hasVertexNormals];
- return YES;
- case kCC3SemanticShouldNormalizeVertexNormal:
- [uniform setBoolean: (visitor.currentMeshNode.effectiveNormalScalingMethod == kCC3NormalScalingNormalize)];
- return YES;
- case kCC3SemanticShouldRescaleVertexNormal:
- [uniform setBoolean: (visitor.currentMeshNode.effectiveNormalScalingMethod == kCC3NormalScalingRescale)];
- return YES;
- case kCC3SemanticHasVertexTangent:
- [uniform setBoolean: visitor.currentMesh.hasVertexTangents];
- return YES;
- case kCC3SemanticHasVertexBitangent:
- [uniform setBoolean: visitor.currentMesh.hasVertexBitangents];
- return YES;
- case kCC3SemanticHasVertexColor:
- [uniform setBoolean: visitor.currentMesh.hasVertexColors];
- return YES;
- case kCC3SemanticHasVertexWeight:
- [uniform setBoolean: visitor.currentMesh.hasVertexBoneWeights];
- return YES;
- case kCC3SemanticHasVertexMatrixIndex:
- [uniform setBoolean: visitor.currentMesh.hasVertexBoneIndices];
- return YES;
- case kCC3SemanticHasVertexTextureCoordinate:
- [uniform setBoolean: visitor.currentMesh.hasVertexTextureCoordinates];
- return YES;
- case kCC3SemanticHasVertexPointSize:
- [uniform setBoolean: visitor.currentMesh.hasVertexPointSizes];
- return YES;
- case kCC3SemanticIsDrawingPoints:
- [uniform setBoolean: visitor.currentMeshNode.drawingMode == GL_POINTS];
- return YES;
- case kCC3SemanticShouldDrawFrontFaces:
- [uniform setBoolean: !visitor.currentMeshNode.shouldCullFrontFaces];
- return YES;
- case kCC3SemanticShouldDrawBackFaces:
- [uniform setBoolean: !visitor.currentMeshNode.shouldCullBackFaces];
- return YES;
- #pragma mark Setting environment matrix semantics
- // ENVIRONMENT MATRICES --------------
- case kCC3SemanticModelLocalMatrix:
- // Get local matrix as P(-1).T where T is node transform P(-1) is inv-xfm of parent
- [visitor.currentMeshNode.parent.globalTransformMatrixInverted populateCC3Matrix4x3: &m4x3];
- [visitor.currentMeshNode.globalTransformMatrix populateCC3Matrix4x3: &tfmMtx];
- CC3Matrix4x3Multiply(&mRslt4x3, &m4x3, &tfmMtx);
- [uniform setMatrix4x3: &mRslt4x3];
- return YES;
- case kCC3SemanticModelLocalMatrixInv:
- // Get local matrix as P(-1).T where T is node transform P(-1) is inv-xfm of parent
- [visitor.currentMeshNode.parent.globalTransformMatrixInverted populateCC3Matrix4x3: &m4x3];
- [visitor.currentMeshNode.globalTransformMatrix populateCC3Matrix4x3: &tfmMtx];
- CC3Matrix4x3Multiply(&mRslt4x3, &m4x3, &tfmMtx);
- // Now invert
- CC3Matrix4x3InvertAdjoint(&mRslt4x3);
- [uniform setMatrix4x3: &mRslt4x3];
- return YES;
- case kCC3SemanticModelLocalMatrixInvTran:
- // Get local matrix as P(-1).T where T is node transform P(-1) is inv-xfm of parent
- [visitor.currentMeshNode.parent.globalTransformMatrixInverted populateCC3Matrix4x3: &m4x3];
- [visitor.currentMeshNode.globalTransformMatrix populateCC3Matrix4x3: &tfmMtx];
- CC3Matrix4x3Multiply(&mRslt4x3, &m4x3, &tfmMtx);
- CC3Matrix3x3PopulateFrom4x3(&m3x3, &mRslt4x3);
- CC3Matrix3x3InvertAdjointTranspose(&m3x3);
- [uniform setMatrix3x3: &m3x3];
- return YES;
-
- case kCC3SemanticModelMatrix:
- [uniform setMatrix4x3: visitor.modelMatrix];
- return YES;
- case kCC3SemanticModelMatrixInv:
- CC3Matrix4x3PopulateFrom4x3(&m4x3, visitor.modelMatrix);
- CC3Matrix4x3InvertAdjoint(&m4x3);
- [uniform setMatrix4x3: &m4x3];
- return YES;
- case kCC3SemanticModelMatrixInvTran:
- CC3Matrix3x3PopulateFrom4x3(&m3x3, visitor.modelMatrix);
- CC3Matrix3x3InvertAdjointTranspose(&m3x3);
- [uniform setMatrix3x3: &m3x3];
- return YES;
-
- case kCC3SemanticViewMatrix:
- [uniform setMatrix4x3: visitor.viewMatrix];
- return YES;
- case kCC3SemanticViewMatrixInv:
- CC3Matrix4x3PopulateFrom4x3(&m4x3, visitor.viewMatrix);
- CC3Matrix4x3InvertAdjoint(&m4x3);
- [uniform setMatrix4x3: &m4x3];
- return YES;
- case kCC3SemanticViewMatrixInvTran:
- CC3Matrix3x3PopulateFrom4x3(&m3x3, visitor.viewMatrix);
- CC3Matrix3x3InvertAdjointTranspose(&m3x3);
- [uniform setMatrix3x3: &m3x3];
- return YES;
-
- case kCC3SemanticModelViewMatrix:
- [uniform setMatrix4x3: visitor.modelViewMatrix];
- return YES;
- case kCC3SemanticModelViewMatrixInv:
- CC3Matrix4x3PopulateFrom4x3(&m4x3, visitor.modelViewMatrix);
- CC3Matrix4x3InvertAdjoint(&m4x3);
- [uniform setMatrix4x3: &m4x3];
- return YES;
- case kCC3SemanticModelViewMatrixInvTran:
- CC3Matrix3x3PopulateFrom4x3(&m3x3, visitor.modelViewMatrix);
- CC3Matrix3x3InvertAdjointTranspose(&m3x3);
- [uniform setMatrix3x3: &m3x3];
- return YES;
-
- case kCC3SemanticProjMatrix:
- [uniform setMatrix4x4: visitor.projMatrix];
- return YES;
- case kCC3SemanticProjMatrixInv:
- CC3Matrix4x4PopulateFrom4x4(&m4x4, visitor.projMatrix);
- CC3Matrix4x4InvertAdjoint(&m4x4);
- [uniform setMatrix4x4: &m4x4];
- return YES;
- case kCC3SemanticProjMatrixInvTran:
- CC3Matrix3x3PopulateFrom4x4(&m3x3, visitor.projMatrix);
- CC3Matrix3x3InvertAdjointTranspose(&m3x3);
- [uniform setMatrix3x3: &m3x3];
- return YES;
-
- case kCC3SemanticViewProjMatrix:
- [uniform setMatrix4x4: visitor.viewProjMatrix];
- return YES;
- case kCC3SemanticViewProjMatrixInv:
- CC3Matrix4x4PopulateFrom4x4(&m4x4, visitor.viewProjMatrix);
- CC3Matrix4x4InvertAdjoint(&m4x4);
- [uniform setMatrix4x4: &m4x4];
- return YES;
- case kCC3SemanticViewProjMatrixInvTran:
- CC3Matrix3x3PopulateFrom4x4(&m3x3, visitor.viewProjMatrix);
- CC3Matrix3x3InvertAdjointTranspose(&m3x3);
- [uniform setMatrix3x3: &m3x3];
- return YES;
-
- case kCC3SemanticModelViewProjMatrix:
- [uniform setMatrix4x4: visitor.modelViewProjMatrix];
- return YES;
- case kCC3SemanticModelViewProjMatrixInv:
- CC3Matrix4x4PopulateFrom4x4(&m4x4, visitor.modelViewProjMatrix);
- CC3Matrix4x4InvertAdjoint(&m4x4);
- [uniform setMatrix4x4: &m4x4];
- return YES;
- case kCC3SemanticModelViewProjMatrixInvTran:
- CC3Matrix3x3PopulateFrom4x4(&m3x3, visitor.modelViewProjMatrix);
- CC3Matrix3x3InvertAdjointTranspose(&m3x3);
- [uniform setMatrix3x3: &m3x3];
- return YES;
-
- #pragma mark Setting skinning semantics
- // BONE SKINNING ----------------
- case kCC3SemanticVertexBoneCount:
- [uniform setInteger: visitor.currentMeshNode.vertexBoneCount];
- return YES;
- case kCC3SemanticBatchBoneCount:
- [uniform setInteger: visitor.currentSkinSection.boneCount];
- return YES;
- // BONE SKINNING MATRICES ----------------
- case kCC3SemanticBoneMatricesGlobal:
- CC3AssertBoneUniformForSkinSection(uniform, visitor.currentSkinSection);
- boneCnt = visitor.currentSkinSection.boneCount;
- for (GLuint boneIdx = 0; boneIdx < boneCnt; boneIdx++)
- [uniform setMatrix4x3: [visitor globalBoneMatrixAt: boneIdx] at: boneIdx];
- return YES;
- case kCC3SemanticBoneMatricesInvTranGlobal:
- CC3AssertBoneUniformForSkinSection(uniform, visitor.currentSkinSection);
- boneCnt = visitor.currentSkinSection.boneCount;
- for (GLuint boneIdx = 0; boneIdx < boneCnt; boneIdx++) {
- CC3Matrix3x3PopulateFrom4x3(&m3x3, [visitor globalBoneMatrixAt: boneIdx]);
- CC3Matrix3x3InvertAdjointTranspose(&m3x3);
- [uniform setMatrix3x3: &m3x3 at: boneIdx];
- }
- return YES;
- case kCC3SemanticBoneMatricesEyeSpace:
- CC3AssertBoneUniformForSkinSection(uniform, visitor.currentSkinSection);
- boneCnt = visitor.currentSkinSection.boneCount;
- for (GLuint boneIdx = 0; boneIdx < boneCnt; boneIdx++)
- [uniform setMatrix4x3: [visitor eyeSpaceBoneMatrixAt: boneIdx] at: boneIdx];
- return YES;
- case kCC3SemanticBoneMatricesInvTranEyeSpace:
- CC3AssertBoneUniformForSkinSection(uniform, visitor.currentSkinSection);
- boneCnt = visitor.currentSkinSection.boneCount;
- for (GLuint boneIdx = 0; boneIdx < boneCnt; boneIdx++) {
- CC3Matrix3x3PopulateFrom4x3(&m3x3, [visitor eyeSpaceBoneMatrixAt: boneIdx]);
- CC3Matrix3x3InvertAdjointTranspose(&m3x3);
- [uniform setMatrix3x3: &m3x3 at: boneIdx];
- }
- return YES;
- case kCC3SemanticBoneMatricesModelSpace:
- CC3AssertBoneUniformForSkinSection(uniform, visitor.currentSkinSection);
- boneCnt = visitor.currentSkinSection.boneCount;
- for (GLuint boneIdx = 0; boneIdx < boneCnt; boneIdx++)
- [uniform setMatrix4x3: [visitor modelSpaceBoneMatrixAt: boneIdx] at: boneIdx];
- return YES;
- case kCC3SemanticBoneMatricesInvTranModelSpace:
- CC3AssertBoneUniformForSkinSection(uniform, visitor.currentSkinSection);
- boneCnt = visitor.currentSkinSection.boneCount;
- for (GLuint boneIdx = 0; boneIdx < boneCnt; boneIdx++) {
- CC3Matrix3x3PopulateFrom4x3(&m3x3, [visitor modelSpaceBoneMatrixAt: boneIdx]);
- CC3Matrix3x3InvertAdjointTranspose(&m3x3);
- [uniform setMatrix3x3: &m3x3 at: boneIdx];
- }
- return YES;
-
- // BONE SKINNING DISCRETE TRANSFORMS
- case kCC3SemanticBoneQuaternionsGlobal:
- CC3AssertBoneUniformForSkinSection(uniform, visitor.currentSkinSection);
- boneCnt = visitor.currentSkinSection.boneCount;
- for (GLuint boneIdx = 0; boneIdx < boneCnt; boneIdx++) {
- pm4x3 = [visitor globalBoneMatrixAt: boneIdx];
- [uniform setVector4: CC3Matrix4x3ExtractQuaternion(pm4x3) at: boneIdx];
- }
- return YES;
- case kCC3SemanticBoneTranslationsGlobal:
- CC3AssertBoneUniformForSkinSection(uniform, visitor.currentSkinSection);
- boneCnt = visitor.currentSkinSection.boneCount;
- for (GLuint boneIdx = 0; boneIdx < boneCnt; boneIdx++) {
- pm4x3 = [visitor globalBoneMatrixAt: boneIdx];
- [uniform setVector: CC3Matrix4x3ExtractTranslation(pm4x3) at: boneIdx];
- }
- return YES;
- case kCC3SemanticBoneScalesGlobal:
- case kCC3SemanticBoneScalesEyeSpace: // Same as global because view matrix is not scaled
- skin = visitor.currentSkinSection;
- boneCnt = skin.boneCount;
- CC3AssertBoneUniformForSkinSection(uniform, skin);
- for (GLuint boneIdx = 0; boneIdx < boneCnt; boneIdx++)
- [uniform setVector: CC3VectorScale(visitor.currentMeshNode.globalScale,
- [skin boneAt: boneIdx].skeletalScale)];
- return YES;
- case kCC3SemanticBoneQuaternionsEyeSpace:
- CC3AssertBoneUniformForSkinSection(uniform, visitor.currentSkinSection);
- boneCnt = visitor.currentSkinSection.boneCount;
- for (GLuint boneIdx = 0; boneIdx < boneCnt; boneIdx++) {
- pm4x3 = [visitor eyeSpaceBoneMatrixAt: boneIdx];
- [uniform setVector4: CC3Matrix4x3ExtractQuaternion(pm4x3) at: boneIdx];
- }
- return YES;
- case kCC3SemanticBoneTranslationsEyeSpace:
- CC3AssertBoneUniformForSkinSection(uniform, visitor.currentSkinSection);
- boneCnt = visitor.currentSkinSection.boneCount;
- for (GLuint boneIdx = 0; boneIdx < boneCnt; boneIdx++) {
- pm4x3 = [visitor eyeSpaceBoneMatrixAt: boneIdx];
- [uniform setVector: CC3Matrix4x3ExtractTranslation(pm4x3) at: boneIdx];
- }
- return YES;
- case kCC3SemanticBoneQuaternionsModelSpace:
- CC3AssertBoneUniformForSkinSection(uniform, visitor.currentSkinSection);
- boneCnt = visitor.currentSkinSection.boneCount;
- for (GLuint boneIdx = 0; boneIdx < boneCnt; boneIdx++) {
- pm4x3 = [visitor modelSpaceBoneMatrixAt: boneIdx];
- [uniform setVector4: CC3Matrix4x3ExtractQuaternion(pm4x3) at: boneIdx];
- }
- return YES;
- case kCC3SemanticBoneTranslationsModelSpace:
- CC3AssertBoneUniformForSkinSection(uniform, visitor.currentSkinSection);
- boneCnt = visitor.currentSkinSection.boneCount;
- for (GLuint boneIdx = 0; boneIdx < boneCnt; boneIdx++) {
- pm4x3 = [visitor modelSpaceBoneMatrixAt: boneIdx];
- [uniform setVector: CC3Matrix4x3ExtractTranslation(pm4x3) at: boneIdx];
- }
- return YES;
- case kCC3SemanticBoneScalesModelSpace:
- skin = visitor.currentSkinSection;
- boneCnt = skin.boneCount;
- CC3AssertBoneUniformForSkinSection(uniform, skin);
- for (GLuint boneIdx = 0; boneIdx < boneCnt; boneIdx++)
- [uniform setVector: [skin boneAt: boneIdx].skeletalScale];
- return YES;
-
- #pragma mark Setting camera semantics
- // CAMERA -----------------
- case kCC3SemanticCameraLocationGlobal:
- [uniform setVector: visitor.camera.globalLocation];
- return YES;
- case kCC3SemanticCameraLocationModelSpace:
- // Transform the global camera location to the local model space
- [uniform setVector: [visitor.currentMeshNode.globalTransformMatrixInverted
- transformLocation: visitor.camera.globalLocation]];
- return YES;
- case kCC3SemanticCameraFrustum: {
- // Applies the field of view angle to the narrower aspect.
- vp = visitor.camera.viewport;
- GLfloat aspect = (GLfloat) vp.w / (GLfloat) vp.h;
- CC3Camera* cam = visitor.camera;
- GLfloat fovWidth, fovHeight;
- if (aspect >= 1.0f) { // Landscape
- fovHeight = CC3DegToRad(cam.effectiveFieldOfView);
- fovWidth = fovHeight * aspect;
- } else { // Portrait
- fovWidth = CC3DegToRad(cam.effectiveFieldOfView);
- fovHeight = fovWidth / aspect;
- }
- [uniform setVector4: CC3Vector4Make(fovWidth, fovHeight,
- cam.nearClippingDistance,
- cam.farClippingDistance)];
- return YES;
- }
- case kCC3SemanticCameraFrustumDepth: {
- CC3Camera* cam = visitor.camera;
- [cam.projectionMatrix populateCC3Matrix4x4: &m4x4];
- [uniform setVector4: CC3Vector4Make(cam.farClippingDistance,
- cam.nearClippingDistance,
- m4x4.c3r3, m4x4.c4r3)];
- return YES;
- }
- case kCC3SemanticViewport:
- vp = visitor.camera.viewport;
- [uniform setIntVector4: CC3IntVector4Make(vp.x, vp.y, vp.w, vp.h)];
- return YES;
-
- #pragma mark Setting material semantics
- // MATERIALS --------------
- case kCC3SemanticColor:
- [uniform setColor4F: visitor.currentColor];
- return YES;
- case kCC3SemanticMaterialColorAmbient:
- [uniform setColor4F: visitor.currentMaterial.effectiveAmbientColor];
- return YES;
- case kCC3SemanticMaterialColorDiffuse:
- [uniform setColor4F: visitor.currentMaterial.effectiveDiffuseColor];
- return YES;
- case kCC3SemanticMaterialColorSpecular:
- [uniform setColor4F: visitor.currentMaterial.effectiveSpecularColor];
- return YES;
- case kCC3SemanticMaterialColorEmission:
- [uniform setColor4F: visitor.currentMaterial.effectiveEmissionColor];
- return YES;
- case kCC3SemanticMaterialOpacity:
- [uniform setFloat: visitor.currentMaterial.effectiveDiffuseColor.a];
- return YES;
- case kCC3SemanticMaterialShininess:
- [uniform setFloat: visitor.currentMaterial.shininess];
- return YES;
- case kCC3SemanticMaterialReflectivity:
- [uniform setFloat: visitor.currentMaterial.reflectivity];
- return YES;
- case kCC3SemanticMinimumDrawnAlpha:
- mat = visitor.currentMaterial;
- [uniform setFloat: (mat.shouldDrawLowAlpha ? 0.0f : mat.alphaTestReference)];
- return YES;
-
- #pragma mark Setting lighting semantics
- // LIGHTING --------------
- case kCC3SemanticIsUsingLighting:
- [uniform setBoolean: visitor.currentNode.shouldUseLighting];
- return YES;
- case kCC3SemanticSceneLightColorAmbient:
- [uniform setColor4F: visitor.scene.ambientLight];
- return YES;
- case kCC3SemanticLightIsEnabled:
- for (GLuint i = 0; i < uniformSize; i++) {
- CC3Light* light = [visitor lightAt: (semanticIndex + i)];
- [uniform setBoolean: light.visible at: i];
- }
- return YES;
- case kCC3SemanticLightInvertedPositionGlobal:
- isInverted = YES;
- case kCC3SemanticLightPositionGlobal:
- for (GLuint i = 0; i < uniformSize; i++) {
- CC3Light* light = [visitor lightAt: (semanticIndex + i)];
- CC3Vector4 ltPos = light.globalHomogeneousPosition;
- if (isInverted) ltPos = CC3Vector4HomogeneousNegate(ltPos);
- [uniform setVector4: ltPos at: i];
- }
- return YES;
- case kCC3SemanticLightInvertedPositionEyeSpace:
- isInverted = YES;
- case kCC3SemanticLightPositionEyeSpace:
- for (GLuint i = 0; i < uniformSize; i++) {
- CC3Light* light = [visitor lightAt: (semanticIndex + i)];
- CC3Vector4 ltPos = light.globalHomogeneousPosition;
- if (isInverted) ltPos = CC3Vector4HomogeneousNegate(ltPos);
- // Transform global position/direction to eye space and normalize if direction
- ltPos = CC3Matrix4x3TransformCC3Vector4(visitor.viewMatrix, ltPos);
- if (light.isDirectionalOnly) ltPos = CC3Vector4Normalize(ltPos);
- [uniform setVector4: ltPos at: i];
- }
- return YES;
- case kCC3SemanticLightInvertedPositionModelSpace:
- isInverted = YES;
- case kCC3SemanticLightPositionModelSpace:
- [visitor.currentMeshNode.globalTransformMatrixInverted populateCC3Matrix4x3: &m4x3];
- for (GLuint i = 0; i < uniformSize; i++) {
- CC3Light* light = [visitor lightAt: (semanticIndex + i)];
- CC3Vector4 ltPos = light.globalHomogeneousPosition;
- if (isInverted) ltPos = CC3Vector4HomogeneousNegate(ltPos);
- // Transform global position/direction to model space and normalize if direction
- ltPos = CC3Matrix4x3TransformCC3Vector4(&m4x3, ltPos);
- if (light.isDirectionalOnly) ltPos = CC3Vector4Normalize(ltPos);
- [uniform setVector4: ltPos at: i];
- }
- return YES;
- case kCC3SemanticLightColorAmbient:
- for (GLuint i = 0; i < uniformSize; i++) {
- CC3Light* light = [visitor lightAt: (semanticIndex + i)];
- ccColor4F ltColor = light.visible ? light.ambientColor : kCCC4FBlackTransparent;
- [uniform setColor4F: ltColor at: i];
- }
- return YES;
- case kCC3SemanticLightColorDiffuse:
- for (GLuint i = 0; i < uniformSize; i++) {
- CC3Light* light = [visitor lightAt: (semanticIndex + i)];
- ccColor4F ltColor = light.visible ? light.diffuseColor : kCCC4FBlackTransparent;
- [uniform setColor4F: ltColor at: i];
- }
- return YES;
- case kCC3SemanticLightColorSpecular:
- for (GLuint i = 0; i < uniformSize; i++) {
- CC3Light* light = [visitor lightAt: (semanticIndex + i)];
- ccColor4F ltColor = light.visible ? light.specularColor : kCCC4FBlackTransparent;
- [uniform setColor4F: ltColor at: i];
- }
- return YES;
- case kCC3SemanticLightAttenuation:
- for (GLuint i = 0; i < uniformSize; i++) {
- CC3Light* light = [visitor lightAt: (semanticIndex + i)];
- CC3AttenuationCoefficients ac = CC3AttenuationCoefficientsLegalize(light.attenuation);
- [uniform setVector: *(CC3Vector*)&ac at: i];
- }
- return YES;
- case kCC3SemanticLightSpotDirectionGlobal:
- for (GLuint i = 0; i < uniformSize; i++) {
- CC3Light* light = [visitor lightAt: (semanticIndex + i)];
- [uniform setVector: light.globalForwardDirection at: i];
- }
- return YES;
- case kCC3SemanticLightSpotDirectionEyeSpace:
- for (GLuint i = 0; i < uniformSize; i++) {
- CC3Light* light = [visitor lightAt: (semanticIndex + i)];
- CC3Vector spotDir = light.globalForwardDirection;
- // Transform global direction to eye space and normalize
- spotDir = CC3Matrix4x3TransformDirection(visitor.viewMatrix, spotDir);
- [uniform setVector: CC3VectorNormalize(spotDir) at: i];
- }
- return YES;
- case kCC3SemanticLightSpotDirectionModelSpace:
- [visitor.currentMeshNode.globalTransformMatrixInverted populateCC3Matrix4x3: &m4x3];
- for (GLuint i = 0; i < uniformSize; i++) {
- CC3Light* light = [visitor lightAt: (semanticIndex + i)];
- CC3Vector spotDir = light.globalForwardDirection;
- // Transform global direction to model space and normalize
- spotDir = CC3Matrix4x3TransformDirection(&m4x3, spotDir);
- [uniform setVector: CC3VectorNormalize(spotDir) at: i];
- }
- return YES;
- case kCC3SemanticLightSpotExponent:
- for (GLuint i = 0; i < uniformSize; i++) {
- CC3Light* light = [visitor lightAt: (semanticIndex + i)];
- [uniform setFloat: light.spotExponent at: i];
- }
- return YES;
- case kCC3SemanticLightSpotCutoffAngle:
- for (GLuint i = 0; i < uniformSize; i++) {
- CC3Light* light = [visitor lightAt: (semanticIndex + i)];
- [uniform setFloat: light.spotCutoffAngle at: i];
- }
- return YES;
- case kCC3SemanticLightSpotCutoffAngleCosine:
- for (GLuint i = 0; i < uniformSize; i++) {
- CC3Light* light = [visitor lightAt: (semanticIndex + i)];
- [uniform setFloat: cosf(CC3DegToRad(light.spotCutoffAngle)) at: i];
- }
- return YES;
-
- case kCC3SemanticFogIsEnabled:
- [uniform setBoolean: visitor.scene.fog.visible];
- return YES;
- case kCC3SemanticFogColor:
- [uniform setColor4F: visitor.scene.fog.diffuseColor];
- return YES;
- case kCC3SemanticFogAttenuationMode:
- [uniform setInteger: visitor.scene.fog.attenuationMode];
- return YES;
- case kCC3SemanticFogDensity:
- [uniform setFloat: visitor.scene.fog.density];
- return YES;
- case kCC3SemanticFogStartDistance:
- [uniform setFloat: visitor.scene.fog.startDistance];
- return YES;
- case kCC3SemanticFogEndDistance:
- [uniform setFloat: visitor.scene.fog.endDistance];
- return YES;
-
- #pragma mark Setting texture semantics
- // TEXTURES --------------
- case kCC3SemanticTextureCount:
- // Count all textures of any type
- [uniform setInteger: visitor.textureCount];
- return YES;
- case kCC3SemanticTextureSampler:
- // Samplers that can be any type are simply consecutive texture unit indices
- // starting at the semanticIndex of the uniform. Typically, semanticIndex > 0
- // and uniformSize > 1 are mutually exclusive.
- for (GLuint i = 0; i < uniformSize; i++) [uniform setInteger: (semanticIndex + i) at: i];
- return YES;
- case kCC3SemanticTexture2DCount:
- mat = visitor.currentMaterial;
- tuCnt = visitor.textureCount;
- // Count just the textures whose sampler semantic is of the correct type
- for (GLuint tuIdx = 0; tuIdx < tuCnt; tuIdx++)
- if ( [mat textureForTextureUnit: tuIdx].samplerSemantic == kCC3SemanticTexture2DSampler ) texCnt++;
- [uniform setInteger: texCnt];
- return YES;
- case kCC3SemanticTextureCubeCount:
- mat = visitor.currentMaterial;
- tuCnt = visitor.textureCount;
- // Count just the textures whose sampler semantic is of the correct type
- for (GLuint tuIdx = 0; tuIdx < tuCnt; tuIdx++)
- if ( [mat textureForTextureUnit: tuIdx].samplerSemantic == kCC3SemanticTextureCubeSampler ) texCnt++;
- [uniform setInteger: texCnt];
- return YES;
- case kCC3SemanticTexture2DSampler:
- // 2D samplers always come first and are consecutive, so we can simply use consecutive
- // texture unit indices starting at the semanticIndex of the uniform. Typically,
- // semanticIndex > 0 and uniformSize > 1 are mutually exclusive.
- for (GLuint i = 0; i < uniformSize; i++) [uniform setInteger: (semanticIndex + i) at: i];
- return YES;
- case kCC3SemanticTextureCubeSampler:
- // Cube samplers always come after 2D samplers, and are consecutive, so we can simply
- // use consecutive texture unit indices starting at the semanticIndex of the uniform,
- // plus an offset to skip any 2D textures. Typically, semanticIndex > 0 and
- // uniformSize > 1 are mutually exclusive.
- semanticIndex += visitor.currentShaderProgram.texture2DCount;
- for (GLuint i = 0; i < uniformSize; i++) [uniform setInteger: (semanticIndex + i) at: i];
- return YES;
- // The semantics below mimic OpenGL ES 1.1 configuration functionality for combining texture units.
- // In most shaders, these will be left unused in favor of customized the texture combining in code.
- case kCC3SemanticTexUnitMode:
- for (GLuint i = 0; i < uniformSize; i++) {
- CC3TextureUnit* tu = [visitor currentTextureUnitAt: (semanticIndex + i)];
- [uniform setInteger: (tu ? tu.textureEnvironmentMode : GL_MODULATE) at: i];
- }
- return YES;
- case kCC3SemanticTexUnitConstantColor:
- for (GLuint i = 0; i < uniformSize; i++) {
- CC3TextureUnit* tu = [visitor currentTextureUnitAt: (semanticIndex + i)];
- [uniform setColor4F: (tu ? tu.constantColor : kCCC4FBlackTransparent) at: i];
- }
- return YES;
- case kCC3SemanticTexUnitCombineRGBFunction:
- for (GLuint i = 0; i < uniformSize; i++) {
- CC3ConfigurableTextureUnit* ctu = (CC3ConfigurableTextureUnit*)[visitor currentTextureUnitAt: (semanticIndex + i)];
- BOOL isCTU = [ctu isKindOfClass: [CC3ConfigurableTextureUnit class]];
- [uniform setInteger: (isCTU ? ctu.combineRGBFunction : GL_MODULATE) at: i];
- }
- return YES;
- case kCC3SemanticTexUnitSource0RGB:
- for (GLuint i = 0; i < uniformSize; i++) {
- CC3ConfigurableTextureUnit* ctu = (CC3ConfigurableTextureUnit*)[visitor currentTextureUnitAt: (semanticIndex + i)];
- BOOL isCTU = [ctu isKindOfClass: [CC3ConfigurableTextureUnit class]];
- [uniform setInteger: (isCTU ? ctu.rgbSource0 : GL_TEXTURE) at: i];
- }
- return YES;
- case kCC3SemanticTexUnitSource1RGB:
- for (GLuint i = 0; i < uniformSize; i++) {
- CC3ConfigurableTextureUnit* ctu = (CC3ConfigurableTextureUnit*)[visitor currentTextureUnitAt: (semanticIndex + i)];
- BOOL isCTU = [ctu isKindOfClass: [CC3ConfigurableTextureUnit class]];
- [uniform setInteger: (isCTU ? ctu.rgbSource1 : GL_PREVIOUS) at: i];
- }
- return YES;
- case kCC3SemanticTexUnitSource2RGB:
- for (GLuint i = 0; i < uniformSize; i++) {
- CC3ConfigurableTextureUnit* ctu = (CC3ConfigurableTextureUnit*)[visitor currentTextureUnitAt: (semanticIndex + i)];
- BOOL isCTU = [ctu isKindOfClass: [CC3ConfigurableTextureUnit class]];
- [uniform setInteger: (isCTU ? ctu.rgbSource2 : GL_CONSTANT) at: i];
- }
- return YES;
- case kCC3SemanticTexUnitOperand0RGB:
- for (GLuint i = 0; i < uniformSize; i++) {
- CC3ConfigurableTextureUnit* ctu = (CC3ConfigurableTextureUnit*)[visitor currentTextureUnitAt: (semanticIndex + i)];
- BOOL isCTU = [ctu isKindOfClass: [CC3ConfigurableTextureUnit class]];
- [uniform setInteger: (isCTU ? ctu.rgbOperand0 : GL_SRC_COLOR) at: i];
- }
- return YES;
- case kCC3SemanticTexUnitOperand1RGB:
- for (GLuint i = 0; i < uniformSize; i++) {
- CC3ConfigurableTextureUnit* ctu = (CC3ConfigurableTextureUnit*)[visitor currentTextureUnitAt: (semanticIndex + i)];
- BOOL isCTU = [ctu isKindOfClass: [CC3ConfigurableTextureUnit class]];
- [uniform setInteger: (isCTU ? ctu.rgbOperand1 : GL_SRC_COLOR) at: i];
- }
- return YES;
- case kCC3SemanticTexUnitOperand2RGB:
- for (GLuint i = 0; i < uniformSize; i++) {
- CC3ConfigurableTextureUnit* ctu = (CC3ConfigurableTextureUnit*)[visitor currentTextureUnitAt: (semanticIndex + i)];
- BOOL isCTU = [ctu isKindOfClass: [CC3ConfigurableTextureUnit class]];
- [uniform setInteger: (isCTU ? ctu.rgbOperand2 : GL_SRC_ALPHA) at: i];
- }
- return YES;
- case kCC3SemanticTexUnitCombineAlphaFunction:
- for (GLuint i = 0; i < uniformSize; i++) {
- CC3ConfigurableTextureUnit* ctu = (CC3ConfigurableTextureUnit*)[visitor currentTextureUnitAt: (semanticIndex + i)];
- BOOL isCTU = [ctu isKindOfClass: [CC3ConfigurableTextureUnit class]];
- [uniform setInteger: (isCTU ? ctu.combineAlphaFunction : GL_MODULATE) at: i];
- }
- return YES;
- case kCC3SemanticTexUnitSource0Alpha:
- for (GLuint i = 0; i < uniformSize; i++) {
- CC3ConfigurableTextureUnit* ctu = (CC3ConfigurableTextureUnit*)[visitor currentTextureUnitAt: (semanticIndex + i)];
- BOOL isCTU = [ctu isKindOfClass: [CC3ConfigurableTextureUnit class]];
- [uniform setInteger: (isCTU ? ctu.alphaSource0 : GL_TEXTURE) at: i];
- }
- return YES;
- case kCC3SemanticTexUnitSource1Alpha:
- for (GLuint i = 0; i < uniformSize; i++) {
- CC3ConfigurableTextureUnit* ctu = (CC3ConfigurableTextureUnit*)[visitor currentTextureUnitAt: (semanticIndex + i)];
- BOOL isCTU = [ctu isKindOfClass: [CC3ConfigurableTextureUnit class]];
- [uniform setInteger: (isCTU ? ctu.alphaSource1 : GL_PREVIOUS) at: i];
- }
- return YES;
- case kCC3SemanticTexUnitSource2Alpha:
- for (GLuint i = 0; i < uniformSize; i++) {
- CC3ConfigurableTextureUnit* ctu = (CC3ConfigurableTextureUnit*)[visitor currentTextureUnitAt: (semanticIndex + i)];
- BOOL isCTU = [ctu isKindOfClass: [CC3ConfigurableTextureUnit class]];
- [uniform setInteger: (isCTU ? ctu.alphaSource2 : GL_CONSTANT) at: i];
- }
- return YES;
- case kCC3SemanticTexUnitOperand0Alpha:
- for (GLuint i = 0; i < uniformSize; i++) {
- CC3ConfigurableTextureUnit* ctu = (CC3ConfigurableTextureUnit*)[visitor currentTextureUnitAt: (semanticIndex + i)];
- BOOL isCTU = [ctu isKindOfClass: [CC3ConfigurableTextureUnit class]];
- [uniform setInteger: (isCTU ? ctu.alphaOperand0 : GL_SRC_ALPHA) at: i];
- }
- return YES;
- case kCC3SemanticTexUnitOperand1Alpha:
- for (GLuint i = 0; i < uniformSize; i++) {
- CC3ConfigurableTextureUnit* ctu = (CC3ConfigurableTextureUnit*)[visitor currentTextureUnitAt: (semanticIndex + i)];
- BOOL isCTU = [ctu isKindOfClass: [CC3ConfigurableTextureUnit class]];
- [uniform setInteger: (isCTU ? ctu.alphaOperand1 : GL_SRC_ALPHA) at: i];
- }
- return YES;
- case kCC3SemanticTexUnitOperand2Alpha:
- for (GLuint i = 0; i < uniformSize; i++) {
- CC3ConfigurableTextureUnit* ctu = (CC3ConfigurableTextureUnit*)[visitor currentTextureUnitAt: (semanticIndex + i)];
- BOOL isCTU = [ctu isKindOfClass: [CC3ConfigurableTextureUnit class]];
- [uniform setInteger: (isCTU ? ctu.alphaOperand2 : GL_SRC_ALPHA) at: i];
- }
- return YES;
-
- #pragma mark Setting model semantics
- // MODEL ----------------
- case kCC3SemanticCenterOfGeometry:
- [uniform setVector: visitor.currentMeshNode.mesh.centerOfGeometry];
- return YES;
- case kCC3SemanticBoundingRadius:
- [uniform setFloat: visitor.currentMeshNode.mesh.radius];
- return YES;
- case kCC3SemanticBoundingBoxMin:
- [uniform setVector: visitor.currentMeshNode.mesh.boundingBox.minimum];
- return YES;
- case kCC3SemanticBoundingBoxMax:
- [uniform setVector: visitor.currentMeshNode.mesh.boundingBox.maximum];
- return YES;
- case kCC3SemanticBoundingBoxSize:
- [uniform setVector: CC3BoxSize(visitor.currentMeshNode.mesh.boundingBox)];
- return YES;
- case kCC3SemanticAnimationFraction:
- [uniform setFloat: [visitor.currentMeshNode animationTimeOnTrack: 0]];
- return YES;
- #pragma mark Setting particle semantics
- // PARTICLES ------------
- case kCC3SemanticPointSize:
- emitter = (CC3PointParticleEmitter*)visitor.currentNode;
- isPtEmitter = [emitter isKindOfClass: [CC3PointParticleEmitter class]];
- [uniform setFloat: (isPtEmitter ? emitter.normalizedParticleSize : 0.0f)];
- return YES;
- case kCC3SemanticPointSizeAttenuation: {
- emitter = (CC3PointParticleEmitter*)visitor.currentNode;
- isPtEmitter = [emitter isKindOfClass: [CC3PointParticleEmitter class]];
- CC3AttenuationCoefficients ac = (isPtEmitter)
- ? CC3AttenuationCoefficientsLegalize(emitter.particleSizeAttenuation)
- : kCC3AttenuationNone;
- [uniform setVector: *(CC3Vector*)&ac];
- return YES;
- }
- case kCC3SemanticPointSizeMinimum:
- emitter = (CC3PointParticleEmitter*)visitor.currentNode;
- isPtEmitter = [emitter isKindOfClass: [CC3PointParticleEmitter class]];
- [uniform setFloat: (isPtEmitter ? emitter.normalizedParticleSizeMinimum : 0.0f)];
- return YES;
- case kCC3SemanticPointSizeMaximum:
- emitter = (CC3PointParticleEmitter*)visitor.currentNode;
- isPtEmitter = [emitter isKindOfClass: [CC3PointParticleEmitter class]];
- [uniform setFloat: (isPtEmitter ? emitter.normalizedParticleSizeMaximum : 0.0f)];
- return YES;
- case kCC3SemanticPointSpritesIsEnabled:
- [uniform setBoolean: visitor.currentMeshNode.isDrawingPointSprites];
- return YES;
-
- #pragma mark Setting time semantics
- // TIME ------------------
- case kCC3SemanticFrameTime:
- [uniform setFloat: visitor.deltaTime];
- return YES;
- case kCC3SemanticSceneTime:
- sceneTime = visitor.scene.elapsedTimeSinceOpened;
- [uniform setPoint: ccp(sceneTime, fmodf(sceneTime, 1.0))];
- return YES;
- case kCC3SemanticSceneTimeSine:
- sceneTime = visitor.scene.elapsedTimeSinceOpened;
- [uniform setVector4: CC3Vector4Make(sinf(sceneTime),
- sinf(sceneTime / 2.0f),
- sinf(sceneTime / 4.0f),
- sinf(sceneTime / 8.0f))];
- return YES;
- case kCC3SemanticSceneTimeCosine:
- sceneTime = visitor.scene.elapsedTimeSinceOpened;
- [uniform setVector4: CC3Vector4Make(cosf(sceneTime),
- co…
Large files files are truncated, but you can click here to view the full file