I am trying to change a model color, adding effects to it using fragment shader how do I get/change the model fragment shader in order to get needed wanted effect of my implementation
Hello, @catCoder Thank you for your contact. This is Live2D Support.
Please check CubismRenderer_OpenGLES2.cpp in CubismSdkForNative Framework. It defines a fragment shader around which the FragShaderSrc variable is defined. Please follow that description and add a shader with color and effect processing.
After adding the shaders, load them with the CubismShader_OpenGLES2::GenerateShaders function. Please replace the items that set the shaders for each application in the CubismShader_OpenGLES2::SetupShaderProgram function.
I read the code and from what I understood adding a new shader to CubismRenderer_OpenGLES2 will change all the models in the application with that shader. How do I add a new shader only for specific model/s in the app? (please excuse me I am new to the subject of Opengl es).
As a prerequisite, the shaders are designed to be the same for all models.
If you want to set a different shader for a specific model, you need to get the CubismModel using the CubismShader_OpenGLES2::SetupShaderProgram function. Please use the model information to identify your model and switch the shader to be set.
I was able to pass the model name and filter for the shader I want for a specific model. I now face a different problem I try to add phong light to the shader but I don't understand how to calculate the normals for the model vertex positions can you explain the line in the SetupShaderProgram() method:
glVertexAttribPointer() is a method provided by OpenGL, so please refer to the official OpenGL documentation.
The arguments are as follows. shaderSet->AttributePositionLocation is the index of the shader vertexArray is the model's vertex array obtained using csmGetDrawableVertexPositions().
Comments
Thank you for your contact.
This is Live2D Support.
Please check CubismRenderer_OpenGLES2.cpp in CubismSdkForNative Framework.
It defines a fragment shader around which the FragShaderSrc variable is defined.
Please follow that description and add a shader with color and effect processing.
After adding the shaders, load them with the CubismShader_OpenGLES2::GenerateShaders function.
Please replace the items that set the shaders for each application in the CubismShader_OpenGLES2::SetupShaderProgram function.
hope that helps!
How do I add a new shader only for specific model/s in the app?
(please excuse me I am new to the subject of Opengl es).
As a prerequisite, the shaders are designed to be the same for all models.
If you want to set a different shader for a specific model, you need to get the CubismModel using the CubismShader_OpenGLES2::SetupShaderProgram function.
Please use the model information to identify your model and switch the shader to be set.
hope that helps!
I now face a different problem I try to add phong light to the shader but I don't understand how to calculate the normals for the model vertex positions
can you explain the line in the SetupShaderProgram() method:
glVertexAttribPointer(shaderSet->AttributePositionLocation, 2, GL_FLOAT, GL_FALSE, sizeof(csmFloat32) * 2, vertexArray);
from what I think the vertexArray hold vec2 positions with stride Length of 2.
if so what is stored in the other positions of the vertexArray?
glVertexAttribPointer() is a method provided by OpenGL, so please refer to the official OpenGL documentation.
The arguments are as follows.
shaderSet->AttributePositionLocation is the index of the shader
vertexArray is the model's vertex array obtained using csmGetDrawableVertexPositions().
hope that helps!