private SSMeshOBJSubsetData _loadMaterialSubset(SSAssetManager.Context ctx, WavefrontObjLoader wff, WavefrontObjLoader.MaterialInfoWithFaces objMatSubset) { // generate renderable geometry data... SSVertex_PosNormTexDiff[] vertices; UInt16[] triIndices, wireframeIndices; VertexSoup_VertexFormatBinder.generateDrawIndexBuffer( wff, out triIndices, out vertices); wireframeIndices = OpenTKHelper.generateLineIndicies(triIndices); SSMeshOBJSubsetData subsetData = new SSMeshOBJSubsetData( vertices, triIndices, wireframeIndices); // setup the material... // load and link every texture present subsetData.TextureMaterial = new SSTextureMaterial(); if (objMatSubset.mtl.diffuseTextureResourceName != null) { subsetData.TextureMaterial.diffuseTex = SSAssetManager.GetInstance <SSTexture>(ctx, objMatSubset.mtl.diffuseTextureResourceName); } if (objMatSubset.mtl.ambientTextureResourceName != null) { subsetData.TextureMaterial.ambientTex = SSAssetManager.GetInstance <SSTexture>(ctx, objMatSubset.mtl.ambientTextureResourceName); } if (objMatSubset.mtl.bumpTextureResourceName != null) { subsetData.TextureMaterial.bumpMapTex = SSAssetManager.GetInstance <SSTexture>(ctx, objMatSubset.mtl.bumpTextureResourceName); } if (objMatSubset.mtl.specularTextureResourceName != null) { subsetData.TextureMaterial.specularTex = SSAssetManager.GetInstance <SSTexture>(ctx, objMatSubset.mtl.specularTextureResourceName); } return(subsetData); }
public static SSSkeletalAnimationMD5 ReadAnimation(SSAssetManager.Context ctx, string filename) { var parser = new SSMD5AnimParser(ctx, filename); var anim = parser.readAnimation (); anim.name = filename; return anim; }
public static TypeFace loadTypeFace(string path) { var reader = SSAssetManager.OpenStreamReader(path); TypeFace newTypeFace = new TypeFace (); newTypeFace.ReadSVG(reader.ReadToEnd()); return newTypeFace; }
public static void RegisterTypes() { // Register SS types for loading by SSAssetManager SSAssetManager.RegisterLoadDelegate <SSTexture>( (ctx, filename) => { return(new SSTexture(ctx, filename)); } ); SSAssetManager.RegisterLoadDelegate <SSTextureWithAlpha>( (ctx, filename) => { return(new SSTextureWithAlpha(ctx, filename)); } ); SSAssetManager.RegisterLoadDelegate <SSMesh_wfOBJ>( (ctx, filename) => { return(new SSMesh_wfOBJ(ctx, filename)); } ); SSAssetManager.RegisterLoadDelegate <SSVertexShader>( (ctx, filename) => { return(new SSVertexShader(ctx, filename)); } ); SSAssetManager.RegisterLoadDelegate <SSFragmentShader>( (ctx, filename) => { return(new SSFragmentShader(ctx, filename)); } ); SSAssetManager.RegisterLoadDelegate <SSGeometryShader>( (ctx, filename) => { return(new SSGeometryShader(ctx, filename)); } ); SSAssetManager.RegisterLoadDelegate <SSSkeletalMeshMD5[]> ( (ctx, filename) => { return(SSMD5MeshParser.ReadMeshes(ctx, filename)); } ); SSAssetManager.RegisterLoadDelegate <SSSkeletalAnimationMD5> ( (ctx, filename) => { return(SSMD5AnimParser.ReadAnimation(ctx, filename)); } ); }
public SSTexture(string filename) : this() { Bitmap textureBitmap = new Bitmap(SSAssetManager.OpenStream(filename)); loadFromBitmap(textureBitmap, name: filename); }
public static SSTextureMaterial FromBlenderMtl(string basePath, SSWavefrontMTLInfo mtl) { SSTexture diffuse = null, specular = null, ambient = null, bumpMap = null; if (mtl.diffuseTextureResourceName != null && mtl.diffuseTextureResourceName.Length > 0) { string path = Path.Combine(basePath, mtl.diffuseTextureResourceName); diffuse = SSAssetManager.GetInstance <SSTextureWithAlpha> (path); } if (mtl.specularTextureResourceName != null && mtl.specularTextureResourceName.Length > 0) { string path = Path.Combine(basePath, mtl.specularTextureResourceName); specular = SSAssetManager.GetInstance <SSTextureWithAlpha> (path); } if (mtl.ambientTextureResourceName != null && mtl.ambientTextureResourceName.Length > 0) { string path = Path.Combine(basePath, mtl.ambientTextureResourceName); ambient = SSAssetManager.GetInstance <SSTextureWithAlpha> (path); } if (mtl.bumpTextureResourceName != null && mtl.bumpTextureResourceName.Length > 0) { string path = Path.Combine(basePath, mtl.bumpTextureResourceName); bumpMap = SSAssetManager.GetInstance <SSTextureWithAlpha> (path); } return(new SSTextureMaterial(diffuse, specular, ambient, bumpMap)); }
public SSMainShaderProgram() { // we use this method of detecting the extension because we are in a GL2.2 context if (GL.GetString(StringName.Extensions).ToLower().Contains("gl_ext_gpu_shader4")) { m_vertexShader = SSAssetManager.GetInstance <SSVertexShader>(c_ctx, "ss4_vertex.glsl"); attach(m_vertexShader); m_fragmentShader = SSAssetManager.GetInstance <SSFragmentShader>(c_ctx, "ss4_fragment.glsl"); attach(m_fragmentShader); m_geometryShader = SSAssetManager.GetInstance <SSGeometryShader>(c_ctx, "ss4_geometry.glsl"); GL.Ext.ProgramParameter(m_programID, ExtGeometryShader4.GeometryInputTypeExt, (int)All.Triangles); GL.Ext.ProgramParameter(m_programID, ExtGeometryShader4.GeometryOutputTypeExt, (int)All.TriangleStrip); GL.Ext.ProgramParameter(m_programID, ExtGeometryShader4.GeometryVerticesOutExt, 3); attach(m_geometryShader); } else { m_vertexShader = SSAssetManager.GetInstance <SSVertexShader>(c_ctx, "ss1_vertex.glsl"); attach(m_vertexShader); m_fragmentShader = SSAssetManager.GetInstance <SSFragmentShader>(c_ctx, "ss1_fragment.glsl"); attach(m_fragmentShader); } link(); // shader is initialized now... Activate(); // reused uniform locations u_diffTexEnabled = getUniLoc("diffTexEnabled"); u_specTexEnabled = getUniLoc("specTexEnabled"); u_ambiTexEnabled = getUniLoc("ambiTexEnabled"); u_bumpTexEnabled = getUniLoc("bumpTexEnabled"); u_animateSecondsOffset = getUniLoc("animateSecondsOffset"); u_winScale = getUniLoc("WIN_SCALE"); u_showWireframes = getUniLoc("showWireframes"); u_numShadowMaps = getUniLoc("numShadowMaps"); u_shadowMapTextures = getUniLoc("shadowMapTextures"); u_shadowMapVPs = getUniLoc("shadowMapVPs"); u_objectWorldTransform = getUniLoc("objWorldTransform"); u_ShowWireframes = false; u_AnimateSecondsOffset = 0.0f; // uniform locations for texture setup only int GLun_diffTex = getUniLoc("diffTex"); int GLun_specTex = getUniLoc("specTex"); int GLun_ambiTex = getUniLoc("ambiTex"); int GLun_bumpTex = getUniLoc("bumpTex"); // bind shader uniform variable handles to GL texture-unit numbers GL.Uniform1(GLun_diffTex, 0); // Texture.Texture0 GL.Uniform1(GLun_specTex, 1); // Texture.Texture1 GL.Uniform1(GLun_ambiTex, 2); // Texture.Texture2 GL.Uniform1(GLun_bumpTex, 3); // Texture.Texture3 checkErrors(); }
public SSTextureWithAlpha(string path) : base() { Bitmap textureBitmap = new Bitmap(SSAssetManager.OpenStream(path)); string name = Path.GetFileName(path); loadFromBitmap(textureBitmap, name, hasAlpha: true); }
public static SSTextureMaterial FromMaterialString(SSAssetManager.Context ctx, string materialString) { string existingFilename = null; SSAssetManager.Context existingCtx = null; if (ctx != null && SSAssetManager.ResourceExists (ctx, materialString)) { existingCtx = ctx; existingFilename = materialString; } else if (SSAssetManager.ResourceExists (SSAssetManager.Context.Root, materialString)) { existingCtx = SSAssetManager.Context.Root; existingFilename = materialString; } else { SSAssetManager.Context[] ctxs = { ctx, SSAssetManager.Context.Root }; var extensions = new List<string> (SSTexture.commonImageExtensions); extensions.Insert (0, ".mtl"); // check mtl first foreach (var context in ctxs) { // for each context (current vs root directory)... foreach (string extension in extensions) { // for each extension of interest... string filename = materialString + extension; if (SSAssetManager.ResourceExists (context, filename)) { existingCtx = context; existingFilename = filename; break; } } } } if (existingFilename != null) { // try loading a material try { SSWavefrontMTLInfo[] mtls = SSWavefrontMTLInfo.ReadMTLs(existingCtx, existingFilename); if (mtls.Length < 0) { throw new Exception("No MTLs available in a file"); } return SSTextureMaterial.FromBlenderMtl(existingCtx, mtls[0]); } catch { // try loading an image try { SSTexture diffTex = SSAssetManager.GetInstance<SSTextureWithAlpha> (existingCtx, existingFilename); return new SSTextureMaterial (diffTex); } catch { } } } string errMsg = "could not load texture material: " + materialString; System.Console.WriteLine (errMsg); throw new Exception (errMsg); }
public SSInstancedCylinderShaderProgram(string preprocessorDefs = "#define INSTANCE_DRAW") { m_programID = GL.CreateProgram(); _vertexShader = SSAssetManager.GetInstance <SSVertexShader>( basePath + "cylinder_vertex.glsl"); _vertexShader.Prepend(preprocessorDefs); _vertexShader.LoadShader(); attach(_vertexShader); _fragmentShader = SSAssetManager.GetInstance <SSFragmentShader>( basePath + "cylinder_fragment.glsl"); _fragmentShader.Prepend(preprocessorDefs); _fragmentShader.LoadShader(); attach(_fragmentShader); link(); Activate(); u_screenWidth = getUniLoc("screenWidth"); u_screenHeight = getUniLoc("screenHeight"); u_viewMatrix = getUniLoc("viewMatrix"); u_viewMatrixInverse = getUniLoc("viewMatrixInverse"); u_distanceToAlpha = getUniLoc("distanceToAlpha"); u_alphaMin = getUniLoc("alphaMin"); u_alphaMax = getUniLoc("alphaMax"); a_cylinderPos = getAttrLoc("cylinderCenter"); a_cylinderAxis = getAttrLoc("cylinderAxis"); a_prevJointAxis = getAttrLoc("prevJointAxis"); a_nextJointAxis = getAttrLoc("nextJointAxis"); a_cylinderWidth = getAttrLoc("cylinderWidth"); a_cylinderLength = getAttrLoc("cylinderLength"); a_cylinderColor = getAttrLoc("cylinderColor"); a_cylinderInnerColor = getAttrLoc("cylinderInnerColor"); a_innerColorRatio = getAttrLoc("innerColorRatio"); a_outerColorRatio = getAttrLoc("outerColorRatio"); m_isValid = checkGlValid(); this.UniDistanceToAlpha = 0.1f; this.UniAlphaMin = 0.0f; this.UniAlphaMax = 0.6f; }
public static SSTextureMaterial FromBlenderMtl(SSAssetManager.Context ctx, SSWavefrontMTLInfo mtl) { SSTexture diffuse = null, specular = null, ambient = null, bumpMap = null; if (mtl.diffuseTextureResourceName != null && mtl.diffuseTextureResourceName.Length > 0) { diffuse = SSAssetManager.GetInstance<SSTextureWithAlpha> (ctx, mtl.diffuseTextureResourceName); } if (mtl.specularTextureResourceName != null && mtl.specularTextureResourceName.Length > 0) { specular = SSAssetManager.GetInstance<SSTextureWithAlpha> (ctx, mtl.specularTextureResourceName); } if (mtl.ambientTextureResourceName != null && mtl.ambientTextureResourceName.Length > 0) { ambient = SSAssetManager.GetInstance<SSTextureWithAlpha> (ctx, mtl.ambientTextureResourceName); } if (mtl.bumpTextureResourceName != null && mtl.bumpTextureResourceName.Length > 0) { bumpMap = SSAssetManager.GetInstance<SSTextureWithAlpha> (ctx, mtl.bumpTextureResourceName); } return new SSTextureMaterial (diffuse, specular, ambient, bumpMap); }
public SSScene() { // Register SS types for loading by SSAssetManager SSAssetManager.RegisterLoadDelegate <SSTexture>( (ctx, filename) => { return(new SSTexture(ctx, filename)); } ); SSAssetManager.RegisterLoadDelegate <SSMesh_wfOBJ>( (ctx, filename) => { return(new SSMesh_wfOBJ(ctx, filename)); } ); SSAssetManager.RegisterLoadDelegate <SSVertexShader>( (ctx, filename) => { return(new SSVertexShader(ctx, filename)); } ); SSAssetManager.RegisterLoadDelegate <SSFragmentShader>( (ctx, filename) => { return(new SSFragmentShader(ctx, filename)); } ); SSAssetManager.RegisterLoadDelegate <SSGeometryShader>( (ctx, filename) => { return(new SSGeometryShader(ctx, filename)); } ); }
public STrailsRenderer(PositionFunc positonFunc, FwdFunc fwdDirFunc, UpFunc upFunc, STrailsParameters trailsParams = null) : base(new STrailsData(positonFunc, fwdDirFunc, upFunc, trailsParams ?? new STrailsParameters()), SSTexturedCube.Instance, _defaultUsageHint) { trailsParams = trailsData.trailsParams; var tex = SSAssetManager.GetInstance <SSTextureWithAlpha>(trailsParams.textureFilename); renderState.castsShadow = false; renderState.receivesShadows = false; renderState.doBillboarding = false; renderState.alphaBlendingOn = true; //renderState.alphaBlendingOn = false; renderState.depthTest = true; renderState.depthWrite = false; renderState.lighted = false; renderState.blendEquationModeRGB = BlendEquationMode.FuncAdd; renderState.blendFactorSrcRGB = BlendingFactorSrc.SrcAlpha; //renderState.blendFactorDestRGB = BlendingFactorDest.DstAlpha; renderState.blendFactorDestRGB = BlendingFactorDest.OneMinusSrc1Alpha; renderState.blendEquationModeAlpha = BlendEquationMode.FuncAdd; renderState.blendFactorSrcAlpha = BlendingFactorSrc.One; renderState.blendFactorDestAlpha = BlendingFactorDest.One; //renderState.blendFactorSrcAlpha = BlendingFactorSrc.SrcAlpha; renderState.blendFactorDestAlpha = BlendingFactorDest.OneMinusSrcAlpha; simulateOnUpdate = false; simulateOnRender = true; renderState.frustumCulling = true; colorMaterial = SSColorMaterial.pureAmbient; textureMaterial = new SSTextureMaterial(diffuse: tex); Name = "simple trails renderer"; //this.MainColor = Color4Helper.RandomDebugColor(); this.renderMode = RenderMode.GpuInstancing; }
public SSPssmShaderProgram(string preprocessorDefs = null) { string glExtStr = GL.GetString(StringName.Extensions).ToLower(); if (!glExtStr.Contains("gl_ext_gpu_shader4")) { Console.WriteLine("PSSM shader not supported"); m_isValid = false; return; } m_vertexShader = SSAssetManager.GetInstance <SSVertexShader>( Path.Combine(c_basePath, "pssm_vertex.glsl")); m_vertexShader.Prepend(preprocessorDefs); m_vertexShader.LoadShader(); attach(m_vertexShader); m_fragmentShader = SSAssetManager.GetInstance <SSFragmentShader>( Path.Combine(c_basePath, "pssm_fragment.glsl")); m_fragmentShader.Prepend(preprocessorDefs); m_fragmentShader.LoadShader(); attach(m_fragmentShader); m_geometryShader = SSAssetManager.GetInstance <SSGeometryShader>( Path.Combine(c_basePath, "pssm_geometry.glsl")); m_geometryShader.Prepend(preprocessorDefs); m_geometryShader.LoadShader(); GL.Ext.ProgramParameter(m_programID, ExtGeometryShader4.GeometryInputTypeExt, (int)All.Triangles); GL.Ext.ProgramParameter(m_programID, ExtGeometryShader4.GeometryOutputTypeExt, (int)All.TriangleStrip); GL.Ext.ProgramParameter(m_programID, ExtGeometryShader4.GeometryVerticesOutExt, 3 * SSParallelSplitShadowMap.c_numberOfSplits); attach(m_geometryShader); link(); Activate(); u_shadowMapVPs = getUniLoc("shadowMapVPs"); u_objectWorldTransform = getUniLoc("objWorldTransform"); u_numShadowMaps = getUniLoc("numShadowMaps"); GL.Uniform1(u_numShadowMaps, SSParallelSplitShadowMap.c_numberOfSplits); m_isValid = checkGlValid(); }
private SSMeshOBJSubsetData _loadMaterialSubset(SSAssetManager.Context ctx, WavefrontObjLoader wff, WavefrontObjLoader.MaterialInfoWithFaces objMatSubset) { // create new mesh subset-data SSMeshOBJSubsetData subsetData = new SSMeshOBJSubsetData(); // setup the material... // load and link every texture present subsetData.TextureMaterial = new SSTextureMaterial(); if (objMatSubset.mtl.diffuseTextureResourceName != null) { subsetData.TextureMaterial.diffuseTex = SSAssetManager.GetInstance <SSTexture>(ctx, objMatSubset.mtl.diffuseTextureResourceName); } if (objMatSubset.mtl.ambientTextureResourceName != null) { subsetData.TextureMaterial.ambientTex = SSAssetManager.GetInstance <SSTexture>(ctx, objMatSubset.mtl.ambientTextureResourceName); } if (objMatSubset.mtl.bumpTextureResourceName != null) { subsetData.TextureMaterial.bumpMapTex = SSAssetManager.GetInstance <SSTexture>(ctx, objMatSubset.mtl.bumpTextureResourceName); } if (objMatSubset.mtl.specularTextureResourceName != null) { subsetData.TextureMaterial.specularTex = SSAssetManager.GetInstance <SSTexture>(ctx, objMatSubset.mtl.specularTextureResourceName); } // generate renderable geometry data... VertexSoup_VertexFormatBinder.generateDrawIndexBuffer(wff, out subsetData.indicies, out subsetData.vertices); // TODO: setup VBO/IBO buffers // http://www.opentk.com/doc/graphics/geometry/vertex-buffer-objects subsetData.wireframe_indicies = OpenTKHelper.generateLineIndicies(subsetData.indicies); subsetData.vbo = new SSVertexBuffer <SSVertex_PosNormTexDiff>(subsetData.vertices); subsetData.ibo = new SSIndexBuffer(subsetData.indicies, subsetData.vbo); subsetData.ibo_wireframe = new SSIndexBuffer(subsetData.wireframe_indicies, subsetData.vbo); return(subsetData); }
public SSMesh_wfOBJ(SSAssetManager.Context ctx, string filename) { this.srcFilename = ctx.fullResourcePath(filename); Console.WriteLine("SSMesh_wfOBJ: loading wff {0}",filename); WavefrontObjLoader wff_data = new WavefrontObjLoader(ctx, filename); Console.WriteLine("wff vertex count = {0}",wff_data.positions.Count); Console.WriteLine("wff face count = {0}",wff_data.numFaces); _loadData(ctx, wff_data); // update radius float maxRadSq = 0f; foreach (var subset in geometrySubsets) { foreach (var vtx in subset.triangleMesh.lastAssignedVertices) { maxRadSq = Math.Max (maxRadSq, vtx.Position.LengthSquared); } } _boundingSphereRadius = (float)Math.Sqrt (maxRadSq); }
public static SSTextureMaterial FromBlenderMtl(SSAssetManager.Context ctx, SSWavefrontMTLInfo mtl) { SSTexture diffuse = null, specular = null, ambient = null, bumpMap = null; if (mtl.diffuseTextureResourceName != null && mtl.diffuseTextureResourceName.Length > 0) { diffuse = SSAssetManager.GetInstance <SSTextureWithAlpha> (ctx, mtl.diffuseTextureResourceName); } if (mtl.specularTextureResourceName != null && mtl.specularTextureResourceName.Length > 0) { specular = SSAssetManager.GetInstance <SSTextureWithAlpha> (ctx, mtl.specularTextureResourceName); } if (mtl.ambientTextureResourceName != null && mtl.ambientTextureResourceName.Length > 0) { ambient = SSAssetManager.GetInstance <SSTextureWithAlpha> (ctx, mtl.ambientTextureResourceName); } if (mtl.bumpTextureResourceName != null && mtl.bumpTextureResourceName.Length > 0) { bumpMap = SSAssetManager.GetInstance <SSTextureWithAlpha> (ctx, mtl.bumpTextureResourceName); } return(new SSTextureMaterial(diffuse, specular, ambient, bumpMap)); }
public static void RegisterTypes() { // Register SS types for loading by SSAssetManager SSAssetManager.RegisterLoadDelegate <SSTexture>( (path) => { return(new SSTexture(path)); } ); SSAssetManager.RegisterLoadDelegate <SSTextureWithAlpha>( (path) => { return(new SSTextureWithAlpha(path)); } ); SSAssetManager.RegisterLoadDelegate <SSMesh_wfOBJ>( (path) => { return(new SSMesh_wfOBJ(path)); } ); SSAssetManager.RegisterLoadDelegate <SSVertexShader>( (path) => { return(new SSVertexShader(path)); } ); SSAssetManager.RegisterLoadDelegate <SSFragmentShader>( (path) => { return(new SSFragmentShader(path)); } ); SSAssetManager.RegisterLoadDelegate <SSGeometryShader>( (path) => { return(new SSGeometryShader(path)); } ); SSAssetManager.RegisterLoadDelegate <SSSkeletalMeshMD5[]> ( (path) => { return(SSMD5MeshParser.ReadMeshes(path)); } ); SSAssetManager.RegisterLoadDelegate <SSSkeletalAnimationMD5> ( (path) => { return(SSMD5AnimParser.ReadAnimation(path)); } ); SSAssetManager.RegisterLoadDelegate <MatterHackers.Agg.Font.TypeFace>( (path) => { return(SSFontLoader.loadTypeFace(path)); } ); #if false SSAssetManager.RegisterLoadDelegate <FontFamily[]>( (ctx, path) => { return(SSFontLoader.loadFontFamilies(path)); } ); #endif }
public SSAssetManagerContext(SSAssetManager mgr, string basepath) { this.mgr = mgr; this.basepath = basepath; }
public static SSTextureMaterial FromMaterialString(string basePath, string materialString) { string existingPath = null; string combined = Path.Combine(basePath, materialString); if (SSAssetManager.ResourceExists(combined)) { existingPath = combined; } else if (SSAssetManager.ResourceExists(materialString)) { existingPath = materialString; } else { string[] basePaths = { "", basePath }; // search in root as well as supplied base path var extensions = new List <string> (SSTexture.commonImageExtensions); extensions.Insert(0, ".mtl"); // check mtl first foreach (var bp in basePaths) { // for each context (current vs root directory)... foreach (string extension in extensions) { // for each extension of interest... string fullPath = Path.Combine(bp, materialString + extension); if (SSAssetManager.ResourceExists(fullPath)) { existingPath = fullPath; break; } } } } if (existingPath != null) { // try loading a material try { SSWavefrontMTLInfo[] mtls = SSWavefrontMTLInfo.ReadMTLs(existingPath); if (mtls.Length <= 0) { throw new Exception("No MTLs available in a file"); } string baseDir = Path.GetDirectoryName(existingPath); return(SSTextureMaterial.FromBlenderMtl(baseDir, mtls[0])); } catch { // try loading an image try { SSTexture diffTex = SSAssetManager.GetInstance <SSTextureWithAlpha> (existingPath); return(new SSTextureMaterial(diffTex)); } catch { } } } string errMsg = "could not load texture material: " + materialString; System.Console.WriteLine(errMsg); throw new Exception(errMsg); }
public SSTexture(SSAssetManager.Context ctx, string filename) : this() { Bitmap textureBitmap = new Bitmap(ctx.Open(filename)); loadFromBitmap(textureBitmap, name: filename); }
public SSGeometryShader(SSAssetManager.Context context, string filename) : base(ShaderType.GeometryShader, filename, context.Open(filename).AsString()) { }
public SSTextureWithAlpha(SSAssetManager.Context ctx, string filename) : base() { Bitmap textureBitmap = new Bitmap(ctx.Open(filename)); loadFromBitmap(textureBitmap, name: filename, hasAlpha: true); }
private void _loadData(SSAssetManager.Context ctx ,WavefrontObjLoader m) { foreach (var srcmat in m.materials) { if (srcmat.faces.Count != 0) { this.geometrySubsets.Add(_loadMaterialSubset(ctx, m, srcmat)); } } }
private SSMeshOBJSubsetData _loadMaterialSubset(SSAssetManager.Context ctx, WavefrontObjLoader wff, WavefrontObjLoader.MaterialInfoWithFaces objMatSubset) { // generate renderable geometry data... SSVertex_PosNormTexDiff[] vertices; UInt16[] triIndices, wireframeIndices; VertexSoup_VertexFormatBinder.generateDrawIndexBuffer( wff, out triIndices, out vertices); wireframeIndices = OpenTKHelper.generateLineIndicies (triIndices); SSMeshOBJSubsetData subsetData = new SSMeshOBJSubsetData( vertices, triIndices, wireframeIndices); // setup the material... // load and link every texture present subsetData.TextureMaterial = new SSTextureMaterial(); if (objMatSubset.mtl.diffuseTextureResourceName != null) { subsetData.TextureMaterial.diffuseTex = SSAssetManager.GetInstance<SSTexture>(ctx, objMatSubset.mtl.diffuseTextureResourceName); } if (objMatSubset.mtl.ambientTextureResourceName != null) { subsetData.TextureMaterial.ambientTex = SSAssetManager.GetInstance<SSTexture>(ctx, objMatSubset.mtl.ambientTextureResourceName); } if (objMatSubset.mtl.bumpTextureResourceName != null) { subsetData.TextureMaterial.bumpMapTex = SSAssetManager.GetInstance<SSTexture>(ctx, objMatSubset.mtl.bumpTextureResourceName); } if (objMatSubset.mtl.specularTextureResourceName != null) { subsetData.TextureMaterial.specularTex = SSAssetManager.GetInstance<SSTexture>(ctx, objMatSubset.mtl.specularTextureResourceName); } return subsetData; }
public SSGeometryShader(string path) : base(ShaderType.GeometryShader, Path.GetFileName(path), SSAssetManager.OpenStream(path).AsString()) { }
public SSMD5Parser(SSAssetManager.Context ctx, string filename) { m_ctx = ctx; m_reader = ctx.OpenText (filename); System.Console.WriteLine ("Reading a \"doom\" file: " + ctx.fullResourcePath(filename)); }
public SSMainShaderProgram(string preprocessorDefs = null) { // we use this method of detecting the extension because we are in a GL2.2 context bool load_fallback_shader = true; // try to load SS4 shader if (GL.GetString(StringName.Extensions).ToLower().Contains("gl_ext_gpu_shader4")) { try { m_programID = GL.CreateProgram(); m_vertexShader = SSAssetManager.GetInstance <SSVertexShader>( Path.Combine(c_basePath, "ss4_vertex.glsl")); m_vertexShader.Prepend(preprocessorDefs); m_vertexShader.LoadShader(); attach(m_vertexShader); m_fragmentShader = SSAssetManager.GetInstance <SSFragmentShader>( Path.Combine(c_basePath, "ss4_fragment.glsl")); m_fragmentShader.Prepend(preprocessorDefs); m_fragmentShader.LoadShader(); attach(m_fragmentShader); m_geometryShader = SSAssetManager.GetInstance <SSGeometryShader>( Path.Combine(c_basePath, "ss4_geometry.glsl")); GL.Ext.ProgramParameter(m_programID, ExtGeometryShader4.GeometryInputTypeExt, (int)All.Triangles); GL.Ext.ProgramParameter(m_programID, ExtGeometryShader4.GeometryOutputTypeExt, (int)All.TriangleStrip); GL.Ext.ProgramParameter(m_programID, ExtGeometryShader4.GeometryVerticesOutExt, 3); m_geometryShader.Prepend(preprocessorDefs); m_geometryShader.LoadShader(); attach(m_geometryShader); load_fallback_shader = false; Console.WriteLine(" ---- SS4 shader loaded ---- "); } catch (SSShaderLoadException e) { Console.WriteLine(" ---- SS4 shader load failed... fallback to SS1 "); load_fallback_shader = true; } } // if the SS4 shader failed, load SS1 shader.... if (load_fallback_shader) { m_programID = GL.CreateProgram(); m_vertexShader = SSAssetManager.GetInstance <SSVertexShader>( Path.Combine(c_basePath, "ss1_vertex.glsl")); m_vertexShader.LoadShader(); attach(m_vertexShader); m_fragmentShader = SSAssetManager.GetInstance <SSFragmentShader>( Path.Combine(c_basePath, "ss1_fragment.glsl")); m_fragmentShader.LoadShader(); attach(m_fragmentShader); Console.WriteLine(" !!!! SS1 shader loaded "); } link(); // shader is initialized now... Activate(); // reused uniform locations u_diffTexEnabled = getUniLoc("diffTexEnabled"); u_specTexEnabled = getUniLoc("specTexEnabled"); u_ambiTexEnabled = getUniLoc("ambiTexEnabled"); u_bumpTexEnabled = getUniLoc("bumpTexEnabled"); u_animateSecondsOffset = getUniLoc("animateSecondsOffset"); u_winScale = getUniLoc("WIN_SCALE"); u_showWireframes = getUniLoc("showWireframes"); u_receivesShadow = getUniLoc("receivesShadow"); u_numShadowMaps = getUniLoc("numShadowMaps"); u_shadowMapTexture = getUniLoc("shadowMapTexture"); u_poissonSamplingEnabled = getUniLoc("poissonSamplingEnabled"); u_numPoissonSamples = getUniLoc("numPoissonSamples"); u_objectWorldTransform = getUniLoc("objWorldTransform"); u_lightingMode = getUniLoc("lightingMode"); u_directionalLightIndex = getUniLoc("directionalLightIndex"); u_lighted = getUniLoc("lighted"); u_shadowMapVPs = getUniLoc("shadowMapVPs"); u_poissonScaling = getUniLoc("poissonScale"); u_shadowMapViewSplits = getUniLoc("shadowMapViewSplits"); u_spriteOffsetAndSize = getUniLoc("spriteOffsetAndSize"); UniShowWireframes = false; UniAnimateSecondsOffset = 0.0f; UniNumShadowMaps = 0; UniLightingMode = LightingMode.ShadowMapDebug; UniPoissonSamplingEnabled = true; UniNumPoissonSamples = 8; UniDirectionalLightIndex = -1; // no directional light by default UniLighted = false; #if MAIN_SHADER_INSTANCING UniInstanceDrawEnabled = false; UniInstanceBillboardingEnabled = false; #endif // uniform locations for texture setup only int GLun_diffTex = getUniLoc("diffTex"); int GLun_specTex = getUniLoc("specTex"); int GLun_ambiTex = getUniLoc("ambiTex"); int GLun_bumpTex = getUniLoc("bumpTex"); // bind shader uniform variable handles to GL texture-unit numbers GL.Uniform1(GLun_diffTex, 0); // Texture.Texture0 GL.Uniform1(GLun_specTex, 1); // Texture.Texture1 GL.Uniform1(GLun_ambiTex, 2); // Texture.Texture2 GL.Uniform1(GLun_bumpTex, 3); // Texture.Texture3 // errors? m_isValid = checkGlValid(); }
public float vSpecularWeight; // Ns #endregion Fields #region Methods public static SSWavefrontMTLInfo[] ReadMTLs(SSAssetManager.Context ctx, string filename) { var materials = new List<SSWavefrontMTLInfo> (); SSWavefrontMTLInfo parseMaterial = null; StreamReader sr = ctx.OpenText(filename); //Read the first line of text string line = sr.ReadLine(); //Continue to read until you reach end of file while (line != null) { string[] tokens = line.Split(" ".ToArray(), 2); if (tokens.Length < 2) { goto next_line; } string firstToken = tokens[0]; string lineContent = tokens[1]; switch (firstToken) { case "#": // Nothing to read, these are comments. break; case "newmtl": // create new named material parseMaterial = new SSWavefrontMTLInfo(); materials.Add(parseMaterial); parseMaterial.name = lineContent; break; case "Ka": // ambient color parseMaterial.vAmbient = WavefrontParser.readVector4(lineContent, null); parseMaterial.hasAmbient = true; break; case "Kd": // diffuse color parseMaterial.vDiffuse = WavefrontParser.readVector4(lineContent, null); parseMaterial.hasDiffuse = true; break; case "Ks": // specular color (weighted by Ns) parseMaterial.vSpecular = WavefrontParser.readVector4(lineContent,null); parseMaterial.hasSpecular = true; break; case "Ns": // specular color weight parseMaterial.vSpecularWeight = WavefrontParser.parseFloat(lineContent); break; case "d": case "Tr": // transparency / dissolve (i.e. alpha) parseMaterial.fTransparency = WavefrontParser.parseFloat(lineContent); parseMaterial.hasTransparency = true; break; case "illum": // illumination mode parseMaterial.hasIlluminationMode = true; parseMaterial.illuminationMode = (SSWavefrontIlluminationMode) int.Parse(lineContent); break; case "map_Kd": // diffuse color map parseMaterial.diffuseTextureResourceName = lineContent; break; case "map_Ka": // ambient color map parseMaterial.ambientTextureResourceName = lineContent; break; case "map_Ks": // specular color map parseMaterial.specularTextureResourceName = lineContent; break; case "bump": case "map_Bump": case "map_bump": // bump map // bump <filename> [-bm <float intensity>] // bump -bm <float intensity> <filename> string[] parts = lineContent.Split(' '); if (parts.Length == 1) { parseMaterial.bumpTextureResourceName = parts[0]; } else { if (parts.Length == 3) { if (parts[1].Equals("-bm")) { parseMaterial.bumpTextureResourceName = parts[0]; parseMaterial.bumpIntensity = WavefrontParser.parseFloat(parts[2]); } else if (parts[0].Equals("-bm")) { parseMaterial.bumpTextureResourceName = parts[3]; parseMaterial.bumpIntensity = WavefrontParser.parseFloat(parts[1]); } } } break; } next_line: //Read the next line line = sr.ReadLine(); } //close the file sr.Close(); return materials.ToArray(); }
public static SSWavefrontMTLInfo[] ReadMTLs(string path) { var materials = new List <SSWavefrontMTLInfo> (); SSWavefrontMTLInfo parseMaterial = null; StreamReader sr = SSAssetManager.OpenStreamReader(path); //Read the first line of text string line = sr.ReadLine(); //Continue to read until you reach end of file while (line != null) { string[] tokens = line.Split(" ".ToArray(), 2); if (tokens.Length < 2) { goto next_line; } string firstToken = tokens[0]; string lineContent = tokens[1]; switch (firstToken) { case "#": // Nothing to read, these are comments. break; case "newmtl": // create new named material parseMaterial = new SSWavefrontMTLInfo(); materials.Add(parseMaterial); parseMaterial.name = lineContent; break; case "Ka": // ambient color parseMaterial.vAmbient = WavefrontParser.readVector4(lineContent, null); parseMaterial.hasAmbient = true; break; case "Kd": // diffuse color parseMaterial.vDiffuse = WavefrontParser.readVector4(lineContent, null); parseMaterial.hasDiffuse = true; break; case "Ks": // specular color (weighted by Ns) parseMaterial.vSpecular = WavefrontParser.readVector4(lineContent, null); parseMaterial.hasSpecular = true; break; case "Ns": // specular color weight parseMaterial.vSpecularWeight = WavefrontParser.parseFloat(lineContent); break; case "d": case "Tr": // transparency / dissolve (i.e. alpha) parseMaterial.fTransparency = WavefrontParser.parseFloat(lineContent); parseMaterial.hasTransparency = true; break; case "illum": // illumination mode parseMaterial.hasIlluminationMode = true; parseMaterial.illuminationMode = (SSWavefrontIlluminationMode)int.Parse(lineContent); break; case "map_Kd": // diffuse color map parseMaterial.diffuseTextureResourceName = lineContent; break; case "map_Ka": // ambient color map parseMaterial.ambientTextureResourceName = lineContent; break; case "map_Ks": // specular color map parseMaterial.specularTextureResourceName = lineContent; break; case "bump": case "map_Bump": case "map_bump": // bump map // bump <filename> [-bm <float intensity>] // bump -bm <float intensity> <filename> string[] parts = lineContent.Split(' '); if (parts.Length == 1) { parseMaterial.bumpTextureResourceName = parts[0]; } else { if (parts.Length == 3) { if (parts[1].Equals("-bm")) { parseMaterial.bumpTextureResourceName = parts[0]; parseMaterial.bumpIntensity = WavefrontParser.parseFloat(parts[2]); } else if (parts[0].Equals("-bm")) { parseMaterial.bumpTextureResourceName = parts[3]; parseMaterial.bumpIntensity = WavefrontParser.parseFloat(parts[1]); } } } break; } next_line: //Read the next line line = sr.ReadLine(); } //close the file sr.Close(); return(materials.ToArray()); }
public SSFragmentShader(SSAssetManager.Context context, string filename) : base(ShaderType.FragmentShader, filename, context.Open(filename).AsString()) { }
public SSMD5Parser(string path) { m_reader = SSAssetManager.OpenStreamReader(path); System.Console.WriteLine("Reading a \"doom\" file: " + path); }
private SSMD5AnimParser(SSAssetManager.Context ctx, string filename) : base(ctx, filename) { }
public static SSTextureMaterial FromMaterialString(SSAssetManager.Context ctx, string materialString) { string existingFilename = null; SSAssetManager.Context existingCtx = null; if (ctx != null && SSAssetManager.ResourceExists(ctx, materialString)) { existingCtx = ctx; existingFilename = materialString; } else if (SSAssetManager.ResourceExists(SSAssetManager.Context.Root, materialString)) { existingCtx = SSAssetManager.Context.Root; existingFilename = materialString; } else { SSAssetManager.Context[] ctxs = { ctx, SSAssetManager.Context.Root }; var extensions = new List <string> (SSTexture.commonImageExtensions); extensions.Insert(0, ".mtl"); // check mtl first foreach (var context in ctxs) { // for each context (current vs root directory)... foreach (string extension in extensions) { // for each extension of interest... string filename = materialString + extension; if (SSAssetManager.ResourceExists(context, filename)) { existingCtx = context; existingFilename = filename; break; } } } } if (existingFilename != null) { // try loading a material try { SSWavefrontMTLInfo[] mtls = SSWavefrontMTLInfo.ReadMTLs(existingCtx, existingFilename); if (mtls.Length < 0) { throw new Exception("No MTLs available in a file"); } return(SSTextureMaterial.FromBlenderMtl(existingCtx, mtls[0])); } catch { // try loading an image try { SSTexture diffTex = SSAssetManager.GetInstance <SSTextureWithAlpha> (existingCtx, existingFilename); return(new SSTextureMaterial(diffTex)); } catch { } } } string errMsg = "could not load texture material: " + materialString; System.Console.WriteLine(errMsg); throw new Exception(errMsg); }
public SSMainShaderProgram(string preprocessorDefs = null) { // we use this method of detecting the extension because we are in a GL2.2 context if (GL.GetString(StringName.Extensions).ToLower().Contains("gl_ext_gpu_shader4")) { m_vertexShader = SSAssetManager.GetInstance <SSVertexShader>(c_ctx, "ss4_vertex.glsl"); m_vertexShader.Prepend(preprocessorDefs); m_vertexShader.LoadShader(); attach(m_vertexShader); m_fragmentShader = SSAssetManager.GetInstance <SSFragmentShader>(c_ctx, "ss4_fragment.glsl"); m_fragmentShader.Prepend(preprocessorDefs); m_fragmentShader.LoadShader(); attach(m_fragmentShader); m_geometryShader = SSAssetManager.GetInstance <SSGeometryShader>(c_ctx, "ss4_geometry.glsl"); GL.Ext.ProgramParameter(m_programID, ExtGeometryShader4.GeometryInputTypeExt, (int)All.Triangles); GL.Ext.ProgramParameter(m_programID, ExtGeometryShader4.GeometryOutputTypeExt, (int)All.TriangleStrip); GL.Ext.ProgramParameter(m_programID, ExtGeometryShader4.GeometryVerticesOutExt, 3); m_geometryShader.Prepend(preprocessorDefs); m_geometryShader.LoadShader(); attach(m_geometryShader); } else { m_vertexShader = SSAssetManager.GetInstance <SSVertexShader>(c_ctx, "ss1_vertex.glsl"); m_vertexShader.LoadShader(); attach(m_vertexShader); m_fragmentShader = SSAssetManager.GetInstance <SSFragmentShader>(c_ctx, "ss1_fragment.glsl"); m_fragmentShader.LoadShader(); attach(m_fragmentShader); } link(); // shader is initialized now... Activate(); // reused uniform locations u_diffTexEnabled = getUniLoc("diffTexEnabled"); u_specTexEnabled = getUniLoc("specTexEnabled"); u_ambiTexEnabled = getUniLoc("ambiTexEnabled"); u_bumpTexEnabled = getUniLoc("bumpTexEnabled"); u_animateSecondsOffset = getUniLoc("animateSecondsOffset"); u_winScale = getUniLoc("WIN_SCALE"); u_showWireframes = getUniLoc("showWireframes"); u_numShadowMaps = getUniLoc("numShadowMaps"); u_shadowMapTexture = getUniLoc("shadowMapTexture"); u_poissonSamplingEnabled = getUniLoc("poissonSamplingEnabled"); u_numPoissonSamples = getUniLoc("numPoissonSamples"); u_objectWorldTransform = getUniLoc("objWorldTransform"); u_lightingMode = getUniLoc("lightingMode"); u_shadowMapVPs = getUniLoc("shadowMapVPs"); u_poissonScaling = getUniLoc("poissonScale"); u_shadowMapViewSplits = getUniLoc("shadowMapViewSplits"); UniShowWireframes = false; UniAnimateSecondsOffset = 0.0f; UniNumShadowMaps = 0; UniLightingMode = LightingMode.ShadowMapDebug; UniPoissonSamplingEnabled = true; UniNumPoissonSamples = 8; #if MAIN_SHADER_INSTANCING UniInstanceDrawEnabled = false; UniInstanceBillboardingEnabled = false; #endif // uniform locations for texture setup only int GLun_diffTex = getUniLoc("diffTex"); int GLun_specTex = getUniLoc("specTex"); int GLun_ambiTex = getUniLoc("ambiTex"); int GLun_bumpTex = getUniLoc("bumpTex"); // bind shader uniform variable handles to GL texture-unit numbers GL.Uniform1(GLun_diffTex, 0); // Texture.Texture0 GL.Uniform1(GLun_specTex, 1); // Texture.Texture1 GL.Uniform1(GLun_ambiTex, 2); // Texture.Texture2 GL.Uniform1(GLun_bumpTex, 3); // Texture.Texture3 // errors? m_isValid = checkGlValid(); }
public static SSSkeletalMeshMD5[] ReadMeshes(SSAssetManager.Context ctx, string filename) { var parser = new SSMD5MeshParser (ctx, filename); return parser.readMeshes (); }