Open luohuiiqng opened 10 months ago
The first image is generator from the problem code..
My idea is that even with advanced opengl, the material of the model can still be obtained from the OSG file normally, and the model can be rendered in the shader through built-in OSG variables. Is this idea feasible?
The result seems to be correct. The shader code you provided uses diffuse lighting as the fragment color. And the image shows the same thing.
The result seems to be correct. The shader code you provided uses diffuse lighting as the fragment color. And the image shows the same thing.
How can I reference the model colors set in the OSG file in the shader? I tried using osg_ Color is still invalid in the shader. Thank you!
If want want to use advanced graphics functionality then OpenGL/OpenSceneGraph isn't the best tool. You will likely find it easier to using modern APIs like Vulkan/VulkanSceneGraph.
If want want to use advanced graphics functionality then OpenGL/OpenSceneGraph isn't the best tool. You will likely find it easier to using modern APIs like Vulkan/VulkanSceneGraph.
Yes, but I currently want to quickly implement something similar to Google Earth. After searching for some information, I learned that OSG and OSgEarth can quickly help me achieve it, so I am currently trying to understand OSG
I think my current problem is that after reading the OSG file, I cannot easily extract the colors specified in the file and use them in the shader.
The VulkanSceneGraph README.md provides links to a number of related projects including vsgQt:
https://github.com/vsg-dev/VulkanSceneGraph
vsgQt itself:
The result seems to be correct. The shader code you provided uses diffuse lighting as the fragment color. And the image shows the same thing.
How can I reference the model colors set in the OSG file in the shader? I tried using osg_ Color is still invalid in the shader. Thank you!
osg_Color should work as an alternative of gl_Color. Make sure it's vec4
The result seems to be correct. The shader code you provided uses diffuse lighting as the fragment color. And the image shows the same thing.
How can I reference the model colors set in the OSG file in the shader? I tried using osg_ Color is still invalid in the shader. Thank you!
osg_Color should work as an alternative of gl_Color. Make sure it's vec4
Thank you! This plan is feasible. Where can I find any built-in opengl variables for OSG?
The result seems to be correct. The shader code you provided uses diffuse lighting as the fragment color. And the image shows the same thing.
How can I reference the model colors set in the OSG file in the shader? I tried using osg_ Color is still invalid in the shader. Thank you!
osg_Color should work as an alternative of gl_Color. Make sure it's vec4
Thank you! This plan is feasible. Where can I find any built-in opengl variables for OSG?
For example, textures
osg_Color should work as an alternative of gl_Color. Make sure it's vec4
Thank you! This plan is feasible. Where can I find any built-in opengl variables for OSG?
OSG replaces gl_* attributes for convience under core profile. Have a look at State::resetVertexAttributeAlias(): osg_Vertex, osg_Normal, osg_Color, osg_SecondaryColor, osg_FogCoord, osg_MultiTexCoord0, osg_MultiTexCoord1, ...
And some necessary uniforms, at State::convertVertexShaderSourceToOsgBuiltIns(): osg_ModelViewMatrix, osg_ModelViewProjectionMatrix, osg_ProjectionMatrix, osg_NormalMatrix
FYI, don't forget those uniforms that work under both core and compatible profiles. See them at SceneView::updateUniforms(): osg_FrameNumber, osg_FrameTime, osg_SimulationTime, osg_ViewMatrix, osg_ViewMatrixInverse
osg_Color should work as an alternative of gl_Color. Make sure it's vec4
Thank you! This plan is feasible. Where can I find any built-in opengl variables for OSG?
OSG replaces gl_* attributes for convience under core profile. Have a look at State::resetVertexAttributeAlias(): osg_Vertex, osg_Normal, osg_Color, osg_SecondaryColor, osg_FogCoord, osg_MultiTexCoord0, osg_MultiTexCoord1, ...
And some necessary uniforms, at State::convertVertexShaderSourceToOsgBuiltIns(): osg_ModelViewMatrix, osg_ModelViewProjectionMatrix, osg_ProjectionMatrix, osg_NormalMatrix
FYI, don't forget those uniforms that work under both core and compatible profiles. See them at SceneView::updateUniforms(): osg_FrameNumber, osg_FrameTime, osg_SimulationTime, osg_ViewMatrix, osg_ViewMatrixInverse
Thank you! I found it.
The VulkanSceneGraph README.md provides links to a number of related projects including vsgQt:
https://github.com/vsg-dev/VulkanSceneGraph
vsgQt itself:
Thank you!
Now I want to use advanced opengl in 3.7.0, but there are some issues. After running the example, the model did not display correctly. Is there a problem with my code? I enable advanced opengl attributes when compiling the source code.
include <osgViewer/Viewer>
include <osgDB/ReadFile>
include <osg/GraphicsContext>
include <osg/Camera>
include <osg/Viewport>
include <osg/StateSet>
include <osg/Program>
include <osg/Shader>
include <osgUtil/Optimizer>
include <osgGA/StateSetManipulator>
include <osgGA/TrackballManipulator>
include <osgGA/FlightManipulator>
include <osgGA/KeySwitchMatrixManipulator>
include <osgGA/AnimationPathManipulator>
include <osgGA/TerrainManipulator>
include <osgGA/DriveManipulator>
include <osgViewer/ViewerEventHandlers>
void configureShaders(osg::StateSet stateSet) { const std::string vertexSource = "#version 130 \n" " \n" "uniform mat4 osg_ModelViewProjectionMatrix; \n" "uniform mat3 osg_NormalMatrix; \n" "uniform vec3 ecLightDir; \n" " \n" "in vec4 osg_Vertex; \n" "in vec3 osg_Normal; \n" "out vec4 color; \n" " \n" "void main() \n" "{ \n" " vec3 ecNormal = normalize( osg_NormalMatrix osg_Normal ); \n" " float diffuse = max( dot( ecLightDir, ecNormal ), 0. ); \n" " color = vec4( vec3( diffuse ), 1. ); \n" " \n" " gl_Position = osg_ModelViewProjectionMatrix osg_Vertex; \n" "} \n"; osg::Shader vShader = new osg::Shader(osg::Shader::VERTEX, vertexSource);
}
int main(int argc, char** argv) { fileList;
fileList.push_back("glider.osg");
// 创建节点.
osg::ref_ptr root = osgDB::readRefNodeFiles(fileList);
if (root == NULL)
{
osg::notify(osg::FATAL) << "Unable to load model from command line." << std::endl;
return(1);
}
std::vector
}